views:

33

answers:

2

Here's my stripped-down setup.py script with non-code stuff removed:

#!/usr/bin/env python

from distutils.core import setup
from whyteboard.misc import meta


setup(
    name = 'Whyteboard',
    version = meta.version,

    packages = ['whyteboard', 'whyteboard.gui', 'whyteboard.lib', 'whyteboard.lib.pubsub',
                'whyteboard.lib.pubsub.core', 'whyteboard.lib.pubsub.utils', 'whyteboard.misc'],

    py_modules = ['whyteboard'],
    scripts = ['whyteboard.py'],
)

MANIFEST.in:

include *.txt
include whyteboard-help/*.*
recursive-include locale *.mo
recursive-include images *.png

When I run "python setup.py install sdist" I get a nice .tar.gz with a "whyteboard-0.41" root folder, with my locale/ images/ and whyteboard-help/ folders inside. This also has my whyteboard.py script that launches my program from inside the whyteboard source package.

So:

whyteboard/
 |
 | locale/
 | images
 | whyteboard-help/
 | whyteboard/
    | 
    | __init__.py
    | other packages etc
 |
 | whyteboard.py
 | README
 | setup.py
 | CHANGELOG

This mirrors the source of my program, is how everything should be, and is correct.

However when I run "python setup.py install" none of my data files are written - only the "whyteboard" source package, and the whyteboard.py is placed in /usr/local/lib/python2.6/dist-packages/.

Ideally, I'd like the same directory structure as what's been generated in the .tar.gz file to be created in dist-packages, as this is how my program expects to look for its resources.

How can I get "install" to create this directory structure? It seems to be ignoring my manifest file, as far as I can tell.

+1  A: 

MANIFEST.in tells Distutils what files to include in the source distribution but it does not directly affect what files are installed. For that you need to include the appropriate files in the setup.py file, generally either as package data or as additional files.

Ned Deily
I tried adding a list of package data but none of the files I specified were used. I wasn't sure whether the locations of the files were installed relative to the overall installation of the package. Anyhow, it still wasn't writing my files in the correct directory structure I expected.
Steven Sproat
The documentation linked in this answer gives you all the information you need about where data_files and package_data are installed. If these options aren't working for you, please update your question with the exact syntax you tried, the results, and what you expected.
Carl Meyer
+1  A: 

Some notes in addition to Ned's answer (which hits on the core problem):

Distutils does not install Python packages and modules inside a per-project subdirectory within dist-packages: they are installed directly into dist-packages, as you've seen. So the containing "whyteboard-xx" directory in your sdist will not exist in the final installed form.

One implication of this is that you should be careful to name your data_files in a way that clarifies what project they belong to, because those files/directories are installed directly into the global dist-packages (or site-packages) directory, not inside any containing "whyteboard" directory.

Or you could instead make your data package_data of the whyteboard package (which means it needs to live inside that package, i.e. next to init.py), and then this isn't a problem.

Lastly, it doesn't make much sense to have both a whyteboard.py module in py_modules and a whyteboard/init.py package in packages. The two are mutually exclusive, and if you have both, the whyteboard.py module will be ignored by imports in favor of the package of the same name.

If whyteboard.py is just a script, and is not intended to be imported, then you should use the scripts option for it, and remove it from py_modules.

Carl Meyer
That's unfortunate. I don't like the idea of having package data - to me, it makes more sense for those resources to live outside of the source directory. Nor do I like having to have directory names prefixed with the program name (even though I already do that for the help files). Hmm..
Steven Sproat