[Distutils] [setuptools] When .py files are "data", strange things happen
Phillip J. Eby
pje at telecommunity.com
Thu Jan 5 18:07:39 CET 2006
At 10:54 PM 1/4/2006 -0500, David Handy wrote:
>I want setuptools to install a bunch of sample scripts in a package-relative
>directory. Each end user will later run a script that copies these to a
>directory relative to his or her home directory.
>
>However, strange things happen to data files that have a .py extension.
>
>1) Saying "include_package_data = True" was not enough to get them included
> in the egg. The .txt files were included, but the .py files were
> magically excluded.
>
>2) I overcame the above problem with the following setup parameter:
>
> package_data = {
> # Include all .py files in the data directories, they
> # are excluded by default.
> 'cpif.data': ['lander/*.py', 'samples/*.py'],
> }
>
> But now I get a bogus .pyc file generated for each of these sample
> scripts. These bogus .pyc files get included in the egg.
If I understand your use case correctly, I don't see how that hurts anything.
The simplest way to solve your problem, however, is to put the samples in a
subdirectory of your project's .egg-info directory, and then use the
metadata APIs to access them. .py files under .egg-info do not get compiled.
Meanwhile, it's not really practical to have .py files inside a package be
included, but not compiled. So your three choices are:
* Give the files a different extension (e.g. .py.orig or .py.in or .cfg or
whatever), which will then trivially work with include_package_data=True
* Include them explicitly as .py files, as shown above (and then ignore the
irrelevant .pyc files)
* Put them in a subdirectory of the project's .egg-info, and then use the
pkg_resources metadata APIs at runtime to get access.
More information about the Distutils-SIG
mailing list