@@ -147,11 +147,11 @@ setup script). Indirectly provides the :class:`distutils.dist.Distribution` and
147147In addition, the :mod: `distutils.core ` module exposed a number of classes that
148148live elsewhere.
149149
150- * :class: `Extension ` from :mod: `distutils.extension `
150+ * :class: `~distutils.extension. Extension ` from :mod: `distutils.extension `
151151
152- * :class: `Command ` from :mod: `distutils.cmd `
152+ * :class: `~distutils.cmd. Command ` from :mod: `distutils.cmd `
153153
154- * :class: `Distribution ` from :mod: `distutils.dist `
154+ * :class: `~distutils.dist. Distribution ` from :mod: `distutils.dist `
155155
156156A short description of each of these follows, but see the relevant module for
157157the full reference.
@@ -1679,8 +1679,8 @@ lines, and joining lines with backslashes.
16791679===================================================================
16801680
16811681.. module :: distutils.cmd
1682- :synopsis: This module provides the abstract base class Command. This class is subclassed
1683- by the modules in the distutils.command subpackage.
1682+ :synopsis: This module provides the abstract base class Command. This class
1683+ is subclassed by the modules in the distutils.command subpackage.
16841684
16851685
16861686This module supplies the abstract base class :class: `Command `.
@@ -1690,20 +1690,84 @@ This module supplies the abstract base class :class:`Command`.
16901690
16911691 Abstract base class for defining command classes, the "worker bees" of the
16921692 Distutils. A useful analogy for command classes is to think of them as
1693- subroutines with local variables called *options *. The options are declared in
1694- :meth: `initialize_options ` and defined (given their final values) in
1695- :meth: `finalize_options `, both of which must be defined by every command class.
1696- The distinction between the two is necessary because option values might come
1697- from the outside world (command line, config file, ...), and any options
1698- dependent on other options must be computed after these outside influences have
1699- been processed --- hence :meth: `finalize_options `. The body of the subroutine,
1700- where it does all its work based on the values of its options, is the
1701- :meth: `run ` method, which must also be implemented by every command class.
1702-
1703- The class constructor takes a single argument *dist *, a :class: `Distribution `
1693+ subroutines with local variables called *options *. The options are declared
1694+ in :meth: `initialize_options ` and defined (given their final values) in
1695+ :meth: `finalize_options `, both of which must be defined by every command
1696+ class. The distinction between the two is necessary because option values
1697+ might come from the outside world (command line, config file, ...), and any
1698+ options dependent on other options must be computed after these outside
1699+ influences have been processed --- hence :meth: `finalize_options `. The body
1700+ of the subroutine, where it does all its work based on the values of its
1701+ options, is the :meth: `run ` method, which must also be implemented by every
1702+ command class.
1703+
1704+ The class constructor takes a single argument *dist *, a :class: `Distribution `
17041705 instance.
17051706
17061707
1708+ Creating a new Distutils command
1709+ ================================
1710+
1711+ This section outlines the steps to create a new Distutils command.
1712+
1713+ A new command lives in a module in the :mod: `distutils.command ` package. There
1714+ is a sample template in that directory called :file: `command_template `. Copy
1715+ this file to a new module with the same name as the new command you're
1716+ implementing. This module should implement a class with the same name as the
1717+ module (and the command). So, for instance, to create the command
1718+ ``peel_banana `` (so that users can run ``setup.py peel_banana ``), you'd copy
1719+ :file: `command_template ` to :file: `distutils/command/peel_banana.py `, then edit
1720+ it so that it's implementing the class :class: `peel_banana `, a subclass of
1721+ :class: `distutils.cmd.Command `.
1722+
1723+ Subclasses of :class: `Command ` must define the following methods.
1724+
1725+ .. method :: Command.initialize_options()
1726+
1727+ Set default values for all the options that this command supports. Note that
1728+ these defaults may be overridden by other commands, by the setup script, by
1729+ config files, or by the command-line. Thus, this is not the place to code
1730+ dependencies between options; generally, :meth: `initialize_options `
1731+ implementations are just a bunch of ``self.foo = None `` assignments.
1732+
1733+
1734+ .. method :: Command.finalize_options()
1735+
1736+ Set final values for all the options that this command supports. This is
1737+ always called as late as possible, ie. after any option assignments from the
1738+ command-line or from other commands have been done. Thus, this is the place
1739+ to to code option dependencies: if *foo * depends on *bar *, then it is safe to
1740+ set *foo * from *bar * as long as *foo * still has the same value it was
1741+ assigned in :meth: `initialize_options `.
1742+
1743+
1744+ .. method :: Command.run()
1745+
1746+ A command's raison d'etre: carry out the action it exists to perform, controlled
1747+ by the options initialized in :meth: `initialize_options `, customized by other
1748+ commands, the setup script, the command-line, and config files, and finalized in
1749+ :meth: `finalize_options `. All terminal output and filesystem interaction should
1750+ be done by :meth: `run `.
1751+
1752+
1753+ .. attribute :: Command.sub_commands
1754+
1755+ *sub_commands * formalizes the notion of a "family" of commands,
1756+ e.g. ``install `` as the parent with sub-commands ``install_lib ``,
1757+ ``install_headers ``, etc. The parent of a family of commands defines
1758+ *sub_commands * as a class attribute; it's a list of 2-tuples ``(command_name,
1759+ predicate) ``, with *command_name * a string and *predicate * a function, a
1760+ string or ``None ``. *predicate * is a method of the parent command that
1761+ determines whether the corresponding command is applicable in the current
1762+ situation. (E.g. we ``install_headers `` is only applicable if we have any C
1763+ header files to install.) If *predicate * is ``None ``, that command is always
1764+ applicable.
1765+
1766+ *sub_commands * is usually defined at the *end * of a class, because
1767+ predicates can be methods of the class, so they must already have been
1768+ defined. The canonical example is the :command: `install ` command.
1769+
1770+
17071771:mod: `distutils.command ` --- Individual Distutils commands
17081772==========================================================
17091773
@@ -1942,76 +2006,3 @@ The ``register`` command registers the package with the Python Package Index.
19422006This is described in more detail in :pep: `301 `.
19432007
19442008.. % todo
1945-
1946- :mod: `distutils.command.check ` --- Check the meta-data of a package
1947- ===================================================================
1948-
1949- .. module :: distutils.command.check
1950- :synopsis: Check the metadata of a package
1951-
1952-
1953- The ``check `` command performs some tests on the meta-data of a package.
1954- For example, it verifies that all required meta-data are provided as
1955- the arguments passed to the :func: `setup ` function.
1956-
1957- .. % todo
1958-
1959-
1960- Creating a new Distutils command
1961- ================================
1962-
1963- This section outlines the steps to create a new Distutils command.
1964-
1965- A new command lives in a module in the :mod: `distutils.command ` package. There
1966- is a sample template in that directory called :file: `command_template `. Copy
1967- this file to a new module with the same name as the new command you're
1968- implementing. This module should implement a class with the same name as the
1969- module (and the command). So, for instance, to create the command
1970- ``peel_banana `` (so that users can run ``setup.py peel_banana ``), you'd copy
1971- :file: `command_template ` to :file: `distutils/command/peel_banana.py `, then edit
1972- it so that it's implementing the class :class: `peel_banana `, a subclass of
1973- :class: `distutils.cmd.Command `.
1974-
1975- Subclasses of :class: `Command ` must define the following methods.
1976-
1977-
1978- .. method :: Command.initialize_options()
1979-
1980- Set default values for all the options that this command supports. Note that
1981- these defaults may be overridden by other commands, by the setup script, by
1982- config files, or by the command-line. Thus, this is not the place to code
1983- dependencies between options; generally, :meth: `initialize_options `
1984- implementations are just a bunch of ``self.foo = None `` assignments.
1985-
1986-
1987- .. method :: Command.finalize_options()
1988-
1989- Set final values for all the options that this command supports. This is
1990- always called as late as possible, ie. after any option assignments from the
1991- command-line or from other commands have been done. Thus, this is the place
1992- to to code option dependencies: if *foo * depends on *bar *, then it is safe to
1993- set *foo * from *bar * as long as *foo * still has the same value it was
1994- assigned in :meth: `initialize_options `.
1995-
1996-
1997- .. method :: Command.run()
1998-
1999- A command's raison d'etre: carry out the action it exists to perform, controlled
2000- by the options initialized in :meth: `initialize_options `, customized by other
2001- commands, the setup script, the command-line, and config files, and finalized in
2002- :meth: `finalize_options `. All terminal output and filesystem interaction should
2003- be done by :meth: `run `.
2004-
2005- *sub_commands * formalizes the notion of a "family" of commands, eg. ``install ``
2006- as the parent with sub-commands ``install_lib ``, ``install_headers ``, etc. The
2007- parent of a family of commands defines *sub_commands * as a class attribute; it's
2008- a list of 2-tuples ``(command_name, predicate) ``, with *command_name * a string
2009- and *predicate * a function, a string or None. *predicate * is a method of
2010- the parent command that determines whether the corresponding command is
2011- applicable in the current situation. (Eg. we ``install_headers `` is only
2012- applicable if we have any C header files to install.) If *predicate * is None,
2013- that command is always applicable.
2014-
2015- *sub_commands * is usually defined at the \* end\* of a class, because predicates
2016- can be methods of the class, so they must already have been defined. The
2017- canonical example is the :command: `install ` command.
0 commit comments