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

P.J. Eby pje at telecommunity.com
Thu Mar 25 21:34:14 CET 2010


At 03:54 PM 3/25/2010 -0400, John Posner wrote:
>On 3/25/2010 7:21 AM, Tarek Ziadé wrote:
>
>I'm a packaging newbie, but a long-time Python hobbyist programmer 
>and a longer-time tech writer. I'm planning to help with the cleanup 
>of the Hitchhiker's Guide.
>
>>
>>>>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
>>>>
>>>>
>
>All of the above works for me, and now I'm proceeding to include PNG 
>image files in my project. Here's the project's directory structure:
>
>   setup.py
>
>   hibye
>   hibye\__init__.py
>   hibye\goodbye.py
>   hibye\hello.py
>   hibye\png
>   hibye\png\left_arrow.png
>   hibye\png\right_arrow.png
>
>   hibye\french
>   hibye\french\__init__.py
>   hibye\french\aurevoir.py
>   hibye\french\bonjour.py
>   hibye\french\french.jpg
>
>
>And here's my setup.py:
>
>   from setuptools import setup
>   ###from distutils.core import setup
>   ###import distribute_setup; distribute_setup.use_setuptools()
>
>   setup(name = "hibye",
>         version = "6.7",
>         packages = ["hibye", "hibye.french"],
>         package_data = {
>             "hibye": ['png/left_arrow.png', 'png/right_arrow.png'],
>             "hibye.french": ['french.jpg'],
>         },
>   )
>
>With this setup, it seems that "python setup.py bdist_egg" includes 
>the PNG files in the distribution, but "python setup.py sdist" does 
>not. I need to include a MANIFEST file to have the PNG files 
>included in a source distribution.

Or, you can place the files under revision control.  CVS and SVN are 
supported natively by setuptools, other systems are supported via 
plugins.  (Note: the recipient of your source distribution will not 
require these tools; setuptools bundles a SOURCES manifest in the 
distribution so the revision control information isn't needed by the 
recipient.)

If your files are under revision control, you also have the option of 
replacing your package_data list with an include_package_data = True flag.


>  Is that the correct functionality? If so, why the difference?

The difference is that in the original design of distutils, including 
arbitrary files in your source distribution is kind of an 
afterthought, whereas in setuptools, the assumption is that your 
source distribution should contain everything you have under revision 
control (or your MANIFEST if you don't have revision control).  Then, 
you can simply tell setuptools to include_package_data, and get your 
data list as a side effect.

Historically, package_data was introduce in setuptools first, then 
adopted by distutils, but this took place before the revision control 
support was added.  Once it was added, it made more sense to treat 
the source distribution as primary...  and hopefully this approach 
will be carried over to distutils2, as well, because there's no need 
to duplicate that info.

Essentially, if you want a DRY (repetition-free) setup, use either 
MANIFEST.in or the revision control system to specify your package 
data files, and then just use include_package_data=True in the 
setup().  (From at least setuptools' POV, package_data is a "legacy" 
feature, rather than a recommended one.)



More information about the Distutils-SIG mailing list