Friday, April 17, 2009

Python distutils installer and user_options

I found the standard doco for distutils to be pretty appalling. It is really only useful for simple cases. The API Reference is slightly more useful, but still not great. I couldn't find a good explanation of how user_options worked to pass extra stuff into the setup script.

Here a few things I found out after a lot of mucking around:

  • Tuples that go into the user_options array should look like:
    ('mysql-root-passwd=', "p", 'MySQL root password for local server [default: None]')
    The '=' on the first element tells distutils this options should have a value (i.e. it is not a boolean option)
  • Options get stored as object variables in your class so the one above turns up as self.mysql_root_passwd - note the substitution for '-'.
  • To subclass the install command inherit from
    from distutils.command.install import install
    and set
    'cmdclass': {'install': WhitetrashInstallData}
    in your call to setup.
  • If the doco sucks, take a look at the code:
    /usr/lib/python2.5/distutils/command/install_data.py
    helped me.

1 comment:

Steve said...

/distutils/cmd.py is good to read too.