[Distutils] Honoring localedir

Raúl Núñez de Arenas Coronado raul at dervishd.net
Mon Nov 17 11:59:58 CET 2008

Hi all :)

I would like to support options like "--localedir" in my setup.py, and
that means:

- Support the option in setup.py. Easy, just subclassing and appending
  the option to the proper "user_options". Worst part is that I would
  have to subclass both "build_scripts" and "install_data" for this to
  work. More on that below.

- Changing the hardcoded path into the main script, so the proper path
  is given to "bindtextdomain()". I suppose I have to subclass
  "build_scripts" for this, run sed or whatever to modify the script
  code with the specified paths, etc.

- Install the files to the user-specified location. This means I have to
  subclass "install_data" for this, to put the translation files where
  the end-user wants me to do.

At first I was ready to do the above, but then I thought of a big
problem (I'm used to autoconf's './configure', and this problem doesn't
happens with it): the end-user may run, by mistake, "setup.py build
--localedir=mylocaledir" first and "setup.py install" after that, and
that means that the script will look for the translations into
"mylocaledir", but translations will be installed in
"/usr/share/locale", probably.

Then I thought: no problem. I won't touch any "build" subclass and will
do the modifications at installation time, subclassing only
"install_scripts" and "install_data". Then again, both commands are
independent and if the user forgets to pass "--localedir" to any of
them, the installed script won't work properly.

The same problem happens with any data that the script have to access
and whose path can be only determined at installation time (icons, for

Right now I only have these choices, if using distutils:

- Forget "--localedir" and use the default options (--install-data, for
  example). This doesn't solve my problem, because as soon as the user
  installs the program using separate "install_scripts" and
  "install_data" commands, it's impossible to put the proper directory
  into the script because the destination directory for data files won't
  be known when installing the scripts.

- Use hardcoded, FHS compliants directories for translations and icons,
  and hope that new data types I may need in the future have such FHS
  compliant directories. This means that my script will try to find the
  data in /usr/whatever and /usr/local/whatever (and maybe under
  /opt/package/whatever), so any installation outside those directories
  won't work. This looks like the more frequent solution, from what I've

- Use a self made "setup.py" that doesn't use distutils at all.
  Tempting, but right now I'm not like reinventing wheels. Moreover,
  I've already read half of the code of distutils to know what to
  subclass and how, and I would like to use distutils if possible.

So, my question is: is there any "official" way of doing what I want?
That is, treating the script as a template and put the proper paths
there, no matter what combination of "build_*" and "install_*" commands
are used. I could live by using hardcoded paths, but that's not the way
I've done things in the past (when using autoconf, CMake, MOBS, etc.)
and I don't feel comfortable with it.

I've googled with no result, and I'm afraid that people use hardcoded
paths or their own search functions to find the data once it is

Thanks a lot in advance :)

Raúl "DervishD" Núñez de Arenas Coronado
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!
We are waiting for 13 Feb 2009 23:31:30 +0000 ...

More information about the Distutils-SIG mailing list