A solution to distutils' habit of installing data_files inconsistantly

L

Lonnie Princehouse

I've just spent an hour or so being frustrated at the way distutils
installs data files, and a quick search of c.l.py shows that I'm not
the first. For posterity, here's an easy (albeit limited) solution.


The Problem:
Distutils installs data files by default in sys.prefix or
sys.exec_prefix, and the installation location is not always
consistant between Win32 and Unix. This means that you have to
duplicate distutils' logic in order to find out where your package's
data files got installed :(
What you really want is to have your data files in the same place
as your Python code, so that you can find them easily.

The Solution:
More complicated packages like PyXML and OpenGLContext address this
by subclassing distutils.command.install_data and/or
distutils.command.install, and then using the cmdclass argument to
setup() to override distutils' built in command handlers. This is
overkill if you only have a few data files and you just want them to
go into the same directories as your Python code. Here's an easier
way. Do this before you call setup():

from distutils.command.install import INSTALL_SCHEMES

for scheme in INSTALL_SCHEMES.values():
scheme['data'] = scheme['purelib']

Alternately, that should read 'platlib' instead of 'purelib' if your
data files are platform specific.

This sets the default data directory to the default pure python
directory, lib/site-packages in most cases.



-ljp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top