distutils, data files, and data sources

Lee Harr missive at frontiernet.net
Fri Dec 13 13:56:16 EST 2002


I've been googling around about this for a few days and still do not
see what I would call an authoritative answer:

Where should data files that are being distributed with a module or
package be stored?

I figured out how to distribute documentation and files using
MANIFEST.in, but that would just leave them there in the unpacked
tarball, not accessible to programs running in arbitrary directories.

When I used the default data_files variable, as shown in the python
distutils docs, the files ended up in /usr/local/ which I cannot
believe is cross-platform... and I am not sure how I would go about
finding them at runtime.

I looked at a couple of other projects (PyOpenGL, and Pygame) and
they both implemented similar hacks to store their data files inside
of their package directories in site-packages.

That is what I ended up doing too... I "borrowed" the simpler
Pygame method and store the couple of images I need in a folder
with the library files. At least that way, I can find them easily
when I import the library.

But then I also needed to create a utility method which checks
the current directory and the directory in which the script lives.
It almost seems like I am duplicating the import functionality
except for data sources.

It seems like this must be a fairly common activity, though I suppose
on reflection it seems like most times when I run a Python program
I end up writing a shell script which first changes directory in to
the unpacked source, and then runs the program. It works, but it is
not practical for something which is intended as a library.

I looked at the current code in cvs, but it is not clear to me that
this has been addressed. The one example using data_files is about
two years old and seems to be installing in to /etc which I also
don't think is cross-platform.

Anyone have a better idea?




More information about the Python-list mailing list