views:

44

answers:

1

I'm packaging up a python module, and I would like users to be able to build the module with some custom options. Specifically, the package will do some extra magic if you provide it with certain executables that it can use.

So ideally, users would be able to run "setup.py install" or "setup.py install --magic-doer=/path/to/executable", and if they used the second option, I would set a variable somewhere accessible in the python code and go from there.

Is this possible with python's setuptools, and if so, how do I do it?

Thanks!

+2  A: 

It seems you can... read this.

Extract from article:

Commands are simple class that derives from setuptools.Command, and define some minimum elements, which are:

description: describe the command
user_options: a list of options
initialize_options(): called at startup
finalize_options(): called at the end
run(): called to run the command

The setuptools doc is still empty about subclassing Command, but a minimal class will look like this:

 class MyCommand(Command):
     """setuptools Command"""
     description = "run my command"
     user_options = tuple()
     def initialize_options(self):
         """init options"""
         pass

     def finalize_options(self):
         """finalize options"""
         pass

     def run(self):
         """runner"""
         XXX DO THE JOB HERE

The class can then be hook as a command, using an entry point in its setup.py file:

 setup(
     # ...
     entry_points = {
     "distutils.commands": [
     "my_command = mypackage.some_module:MyCommand"]}
jldupont