Issue #9 invalid

Add check for `packages` and `package_dir` at `setup()`

Hugo Lopes Tavares
created an issue

I took a look over pyroma's code, and something I missed was a check on packages and package_dir. It is not an easy check, by the way.

setuptools has "editable" installations, and they area just symlinks. The problem is that if you call setup() with a different package name, let's say you use packages=['src'], you can't import your package through its name if you install as editable.

pip install -e use editable installations.

Example:

(env)/tmp/mypackage $ tree
.
├── setup.py
└── src
    └── __init__.py

1 directory, 2 files
(env)/tmp/mypackage $ cat src/__init__.py
A = "FOO"
(env)/tmp/mypackage $ cat setup.py
from setuptools import setup
setup(name='mypackage', packages=['src'])


(env)/tmp/mypackage$ pip install -e .
Obtaining file:///private/tmp/mypackage
  Running setup.py egg_info for package from file:///private/tmp/mypackage

Installing collected packages: mypackage
  Running setup.py develop for mypackage

    Creating /private/tmp/env/lib/python2.7/site-packages/mypackage.egg-link (link to .)
    Adding mypackage 0.0.0 to easy-install.pth file

    Installed /private/tmp/mypackage
Successfully installed mypackage
Cleaning up...

(env)/tmp/mypackage $ cd /tmp
(env)/tmp $ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mypackage
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named mypackage
>>> import src
>>> src.A
'FOO'

Comments (3)

  1. Lennart Regebro repo owner

    I didn't check package_dir because without it the package won't work at all, so it seemed pointless. But adding a check to make sure these sort of features work makes sense.

  2. Lennart Regebro repo owner

    I looked at this, and there is no difference between an editable install and a normal install. In both cases here, installing "mypackage" will install a module called "src". This is per the design of setuptools. It is a misconfiguration, but not really something that is possible to check for. And a far as I can tell, you will never be able to import this module as any other name than "src", so this should be noticeable quickly in the development process.

    Pyromas intenton is not to tell you that your software isn't working, but to check how well you packaged it. :-)

    The way to solve it is to add package_dir = {'': 'src'} in the setup.py.

  3. Log in to comment