Differences between revisions 4 and 5
Revision 4 as of 2009-04-19 11:43:35
Size: 2017
Editor: tarek
Comment:
Revision 5 as of 2009-04-19 11:44:59
Size: 2009
Editor: tarek
Comment:
Deletions are marked like this. Additions are marked like this.
Line 45: Line 45:
The Command will load these plugins using setuptools entry point called: "distutils.MyCmd.manifest_makers". The Command will load these plugins using setuptools entry point called: "distutils.!MyCmd.manifest_makers".
Line 48: Line 48:
Then, a new API called "run_extension" allows MyCmd to run these plugins. Then, a new API called "run_extension" allows !MyCmd to run these plugins.
Line 51: Line 51:
to work over the command, the distribution and so forth. to work over the command and its distribution.

Example

This is a generalization of the technique used in setuptools so people can write plugins to add files registered in special index files from various version control systems.

You have a command where you create a list of files to build 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.

Implementation

Distutils/PluginSystem (last edited 2009-04-22 09:16:36 by tarek)

Unable to edit the page? See the FrontPage for instructions.