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.
Ideally, users would run setup.py install
or setup.py install --magic-doer=/path/to/executable
. If they used the second option, I’d set a variable somewhere in the code, and go from there.
Is this possible with Python's setuptools
? If so, how do I do it?
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"]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With