Customizing Python setuptools

I am building a Python module, and I would like users to be able to create a module with some custom parameters. In particular, the package will do extra magic if you provide it with certain executable files that it can use.

Ideally, users will run setup.py install or setup.py install --magic-doer=/path/to/executable . If they used the second option, Id sets the variable somewhere in the code and from there.

Is this possible with Python setuptools ? If so, how to do it?

+6
python setup.py
source share
1 answer

It seems you can ... read this .

Extract from the article:

Commands are a simple class that comes from setuptools.Command and defines some minimal elements that:

 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 document is still empty relative to the subclass command, but the minimal class would 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 

Then the class can be attached as a command using the entry point in the setup.py file:

  setup( # ... entry_points = { "distutils.commands": [ "my_command = mypackage.some_module:MyCommand"]} 
+6
source share

All Articles