Let's say you have a project called proj and in this project you have the following structure:
proj/
dists/
doc/
src/
__init__.py
xyz.py
abc.py
test/
setup.py
As you can see all the content of your project is in the src subfolder. How to go about making a distutils distribution package out of the src folder?
My naive idea, following the tutorial, would've been to write the setup.py like this:
#omitting basics
setup(
name='proj',
packages=['src'],
package_dir={'proj':'src'}
)
But after installing the resulting package to my system, I still have to import src.xyz and not proj.xyz, which would've been the goal and the expected result.
You could fix it by putting Python package files into proj/ directory:
proj/
src/
proj/
__init__.py
xyz.py
abc.py
setup.py
And changing setup.py to:
# ...
setup(
name='proj',
packages=['proj'],
package_dir={'':'src'}
)
It is not required by distutils but other tools might expect the parent directory name of __init__.py file to be the same as Python package name i.e., proj in this case.
This is due to a bug in setuptools reported here: https://github.com/pypa/setuptools/issues/250
Basically, it does work but not in dev mode. Now on you have 3 solutions:
src package as proj (and ignore it when comitting), it will works out of the box but is dirtysrc to proj
proj in src and use the following options:
packages=['proj'],
package_dir={'proj': 'src/proj'},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With