[Distutils] Help to create a setup.py (subdirectories aren't working)

P.J. Eby pje at telecommunity.com
Thu Mar 25 03:37:18 CET 2010


At 11:04 PM 3/24/2010 -0300, Hugo Doria wrote:
>Hi guys,
>
>I am new to distutils and trying to create a setup.py for a project,
>but i am having a problem.
>
>My project has this directory layout:
>
>/
>/AUTHORS
>/README
>/myproject (binary)
>/MyProject
>/MyProject/modules/
>/MyProject/modules/first.py
>/MyProject/modules/__init__.py
>/MyProject/output/
>/MyProject/output/second.py
>/MyProject/output/__init__.py
>/doc/manpage.1
>
>Here's the setup.py that i did:
>
>from distutils.core import setup
>
>DATAFILES = [('/usr/share/man/man1', ['doc/manpage.1']),
> 
>('/usr/share/doc/myproject',['AUTHORS','COPYING','README','TODO'])]
>
>setup(name='MyProject',
>       version='0.1',
>       license='GPL2',
>       description='Trying distutils,
>       author=['Hugo Doria'],
>       package_dir={'modules':MyProject/modules', 
> 'output':'MyProject/output'},
>       packages=['modules', 'output'],
>       scripts=['myproject'],
>       data_files=DATAFILES)
>
>When i run setup.py install it does works. But i get this on my system:
>
>/usr//lib/python2.6/site-packages/modules
>/usr//lib/python2.6/site-packages/output
>/usr//lib/python2.6/site-packages/MyProject
>
>It's a bit strange, is not?

It's exactly what you asked for.  Your setup.py says you have two 
top-level packages called 'modules' and 'output', so that's what you got.


>Shouldn't it be something like:
>
>/usr//lib/python2.6/site-packages/MyProject
>/usr//lib/python2.6/site-packages/MyProject/output/
>/usr//lib/python2.6/site-packages/MyProject/modules/
>
>What am i doing wrong?

You're using a package_dir with more than one entry in it, which is a 
sign that your project's layout is broken.  If you wanted a layout 
like the one you describe here, you need to:

1. Omit the package_dir option altogether
2. set packages = ['MyProject', 'MyProject.output', 'MyProject.modules']
3. Add an __init__.py in the MyProject directory, to make it the parent package




More information about the Distutils-SIG mailing list