distutils: tweaking my ini to use relevant data_files path

Anastasios Hatzis ah at hatzis.de
Wed Mar 7 05:04:29 EST 2007


I would like to let my setup script know if the user has provided a 
custom path for the data_files of my distribution, e.g. by using the 
--install-data option, so the setup can automagically change a config 
information in my package to the local path applied, instead of using 
some default path I hard-coded into the config information. I could not 
find an appropriate pattern for this, but I'm rather confident that this 
is not too exotic and some of you already use such a pattern. Would be 
great to learn. Thank you in advance.

Following some details. My development version is Python 2.4.4 on 
Windows XP. My project contains a sdk.ini configuration file which is in 
the root package of my tool (by default in site-packages of course). 
This INI has a OSPDIR option for a path to some example *.osp files 
(data_files) coming with the distribution. These *.osp files are some 
work files that should be typically stored in an user's home directory 
or somewhere else, but not in the Python directory.

So, the setup() in my setup.py has (among many other arguments, which I 
don't consier to be important for my task here):

data_files=[('projects', ['projects/foo.osp', 'projects/bar.osp']),

By default this "projects" directory is going into the Python directory, 
right? At least I could see that in my Python 2.4.4 installation on 
Windows XP:

C:\Python24\projects\

My default config could be:
OSPDIR = os.path.join(sys.prefix, 'projects')

so, my tool should usually know where this directory is on a local machine.

But, as mentioned earlier, it makes much sense to have "projects" (and 
its contained data files) installed instead to another location, e.g. 
user home or D:\ etc. - of course this should work on any platform with 
Python and distutils.

I already learned, that user's can alter where setup distributes 
specific parts, such as the data_files with the --install-data option, 
see alternate installation 
http://www.python.org/doc/2.4.4/inst/alt-install-windows.html
or custom installation http://www.python.org/doc/2.4.4/inst/search-path.html

I think, this is reasonable for any user. But what do I need to do, to 
provide OSPDIR with this particular --install-data path applied by the 
user? Can I use OptionParser module (as I already do for my tools) in 
the setup.py which checks, if this option is given, and eventually which 
value it has, and somehow putting it dynamically into the OSPDIR variable?

a) Is --install-data the only way for users to customize path to data_files?
b) Am I right to parse --install-data in setup.py and change OSPDIR 
variable on the fly?
c) If yes, how do I add this to my setup.py? It currently has only a 
setup() call with plenty of arguments (no weired stuff, though). Do I 
need to put this verifcation before or after setup() or is there any 
callback or hook to use?

Many thanks for your support,
Anastasios



More information about the Python-list mailing list