This section outlines the steps to create a new Distutils command.
A new command lives in a module in the distutils.command
package. There is a sample template in that directory called
command_template. Copy this file to a new module with the
same name as the new command you're implementing. This module should
implement a class with the same name as the module (and the command).
So, for instance, to create the command peel_banana
(so that users
can run "setup.py peel_banana"), you'd copy command_template
to distutils/command/peel_banana.py, then edit it so that it's
implementing the class peel_banana, a subclass of
distutils.cmd.Command.
Subclasses of Command must define the following methods.
S) |
) |
) |
sub_commands formalizes the notion of a ``family'' of commands,
eg. install
as the parent with sub-commands install_lib
,
install_headers
, etc. The parent of a family of commands
defines sub_commands as a class attribute; it's a list of
2-tuples "(command_name, predicate)", with command_name a string
and predicate an unbound method, a string or None.
predicate is a method of the parent command that
determines whether the corresponding command is applicable in the
current situation. (Eg. we install_headers
is only applicable if
we have any C header files to install.) If predicate is None,
that command is always applicable.
sub_commands is usually defined at the *end* of a class, because
predicates can be unbound methods, so they must already have been
defined. The canonical example is the install
command.
See About this document... for information on suggesting changes.