distutils: tweaking my ini to use relevant data_files path

  • Thread starter Anastasios Hatzis
  • Start date
A

Anastasios Hatzis

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
 

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

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top