Example
This is a generalization of the technique used in setuptools so people can write plugins for commands.
Let's take an example: you have a command where you create a list of files to build a file list (a manifest).
You provide a default system to build this list but you know some people will probably provide other strategies to build that list.
So let's declare a user option, called "manifest-makers", where an ordered list of plugins name can be declared.
We also declare a new attribute called extensible_options, to declare the list of options that are used to extend the command.
class MyCmd(Command): user_options = [('manifest-makers', None, 'Plugins to build the manifest file')] extensible_options = ['manifest_makers'] def initialize_options(self): # this is a regular user option self.manifest_makers = ['svn', 'template', 'hg'] self.files = [] def finalize_options(self): pass def run(self): # this will build the filelist by running the plugins self.run_extension('manifest_makers')
What happened ? In the initialize options, we declared default values for the manifest_makers attribute : three plugins called 'svn', 'template' and 'hg'.
The Command will load these plugins using setuptools entry point called: "distutils.MyCmd.manifest_makers". It will load them at the end of the option finalization.
Then, a new API called "run_extension" allows MyCmd to run these plugins.
Each plugin received the command and the name of the option in argument and is free to work over the command and its distribution.