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