automatically setting platform-dependent location for Distutils "install-scripts"?

jomorcsi at jomorcsi at
Mon Aug 6 20:30:02 CEST 2007

Hello all,

I am developing a Python-based tool that will be deployed both in a
Windows and in a Linux
environment, and I have a question concerning the use of the Distutils
module to manage the
installation of the tool in a transparent manner.

A bit of background info:
1. (I am using Python version 2.5)
2. Let's assume that the tool is named "xyz"
3. It is internally partitioned into two parts: -- the front-end script that the users actually
invoke, and
    xyzPackage -- a package containing the "guts" of the tool
4. Users do not really care where the "xyzPackage" part is installed
    and thus by default it will be installed into Python's standard
"site-packages" directory.
5. However, users *do* care where the "" part is installed

Now, I have created a Distutils-based "" script that looks
like this:
from distutils.core import setup

> setup(name='xyz',
>       version="1.0",
>       # provide other metadata, such as 'description', 'author', 'author_email', 'url', ... etc.
>       packages=['xyzPackage'],
>       scripts=[''])

... that takes care of the above concerns, and also accepts a
"setup.cfg" configuration file that
allows the user to control into which directory to install the
"" part, as follows:

> [install]
> install-scripts=C:\xyzScriptDirectory

And thus, here is my problem:

[1] At any given moment, the directory name specified in the above
"setup.cfg" file
    can be either a "Windows-style" directory (as is shown above)
    or a "Linux-style" directory (say "/opt/xyzScriptDirectory"), but
not both!

[2] I would like to have a *single* "setup.cfg" file that can
nevertheless be used for *both*
    Windows and Linux, *without* having to be edited by the user.

For example, it would be really nice if I can have a customized
"setup.cfg" file that looks like:

> [install]
> install-scripts-Windows=C:\xyzScriptDirectory
> install-scripts-Linux=/opt/xyzScriptDirectory

... and then some part of Distutils can query "" and set the
"real" 'install-scripts' option
to the appropriate one of these two choices.

I assume this can be done by "overriding" and customizing part of
Indeed, I have already done something similar by overriding
to use a customized "copy_scripts()" method.

However, it is not clear to me in what manner I can/should
override "distutils.command.install_scripts" to achieve the effect
that I desire.

Is this at all the way to go, or might there be a totally obvious way
to do this
that I am currently overlooking?

If anyone has similar experience in tweaking Distutils, I would be
most appreciative of any
advice that you can offer.

Thanks in advance!

More information about the Python-list mailing list