@@ -78,7 +78,13 @@ \subsection{A simple example}
7878\label {simple-example }
7979
8080The setup script is usually quite simple, although since it's written in
81- Python, there are no arbitrary limits to what you can do with it. If
81+ Python, there are no arbitrary limits to what you can do with
82+ it.\footnote {But be careful about putting arbitrarily expensive
83+ operations in your setup script; unlike, say, Autoconf-style configure
84+ scripts, the setup script may be run multiple times in the course of
85+ building and installing your module distribution. If you need to
86+ insert potentially expensive processing steps into the Distutils
87+ chain, see section~\ref {extending } on extending the Distutils.} If
8288all you want to do is distribute a module called \module {foo}, contained
8389in a file \file {foo.py}, then your setup script can be as little as
8490this:
@@ -100,6 +106,7 @@ \subsection{A simple example}
100106 hold true for packages and extensions)
101107\item it's recommended that you supply a little more meta-data, in
102108 particular your name, email address and a URL for the project
109+ (see section~\ref {setup-script } for an example)
103110\end {itemize }
104111
105112To create a source distribution for this module, you would create a
@@ -153,7 +160,7 @@ \subsection{A simple example}
153160Wise installed on your system for the \command {bdist\_ wise} command to
154161work; it's available from \url {http://foo/bar/baz}.)
155162
156- Currently (Distutils 0.9.1 ), the are only other useful built
163+ Currently (Distutils 0.9.2 ), the are only other useful built
157164distribution format is RPM, implemented by the \command {bdist\_ rpm}
158165command. For example, the following command will create an RPM file
159166called \file {Foo-1.0.noarch.rpm}:
@@ -552,24 +559,125 @@ \section{Writing the Setup Configuration File}
552559\label {setup-config }
553560
554561Often, it's not possible to write down everything needed to build a
555- distribution \emph {a priori }. You need to get some information from the
556- user, or from the user's system, in order to proceed. For example, you
557- might include an optional extension module that provides an interface to
558- a particular C library. If that library is installed on the user's
559- system, then you can build your optional extension---but you need to
560- know where to find the header and library file. If it's not installed,
561- you need to know this so you can omit your optional extension.
562-
563- The preferred way to do this, of course, would be for you to tell the
564- Distutils which optional features (C libraries, system calls, external
565- utilities, etc.) you're looking for, and it would inspect the user's
566- system and try to find them. This functionality may appear in a future
567- version of the Distutils, but it isn't there now. So, for the time
568- being, we rely on the user building and installing your software to
569- provide the necessary information. The vehicle for doing so is the
570- setup configuration file, \file {setup.cfg}.
571-
572- \XXX {need more here!}
562+ distribution \emph {a priori }: you may need to get some information from
563+ the user, or from the user's system, in order to proceed. As long as
564+ that information is fairly simple---a list of directories to search for
565+ C header files or libraries, for example---then providing a
566+ configuration file, \file {setup.cfg}, for users to edit is a cheap and
567+ easy way to solicit it. Configuration files also let you provide
568+ default values for any command option, which the installer can then
569+ override either on the command-line or by editing the config file.
570+
571+ (If you have more advanced needs, such as determining which extensions
572+ to build based on what capabilities are present on the target system,
573+ then you need the Distutils `` auto-configuration'' facility. This
574+ started to appear in Distutils 0.9 but, as of this writing, isn't mature
575+ or stable enough yet for real-world use.)
576+
577+ \XXX {should reference description of distutils config files in
578+ `` Installing'' manual here}
579+
580+ The setup configuration file is a useful middle-ground between the setup
581+ script---which, ideally, would be opaque to installers\footnote {This
582+ ideal probably won't be achieved until auto-configuration is fully
583+ supported by the Distutils.}---and the command-line to the setup
584+ script, which is outside of your control and entirely up to the
585+ installer. In fact, \file {setup.cfg} (and any other Distutils
586+ configuration files present on the target system) are processed after
587+ the contents of the setup script, but before the command-line. This has
588+ several useful consequences:
589+ \begin {itemize }
590+ \item installers can override some of what you put in \file {setup.py} by
591+ editing \file {setup.cfg}
592+ \item you can provide non-standard defaults for options that are not
593+ easily set in \file {setup.py}
594+ \item installers can override anything in \file {setup.cfg} using the
595+ command-line options to \file {setup.py}
596+ \end {itemize }
597+
598+ The basic syntax of the configuration file is simple:
599+ \begin {verbatim }
600+ [command]
601+ option=value
602+ ...
603+ \end {verbatim }
604+ where \var {command} is one of the Distutils commands (e.g.
605+ \command {build\_ py}, \command {install}), and \var {option} is one of the
606+ options that command supports. Any number of options can be supplied
607+ for each command, and any number of command sections can be included in
608+ the file. Blank lines are ignored, as are comments (from a \verb +# +
609+ character to end-of-line). Long option values can be split across
610+ multiple lines simply by indenting the continuation lines.
611+
612+ You can find out the list of options supported by a particular command
613+ with the universal \longprogramopt {help} option, e.g.
614+ \begin {verbatim }
615+ > python setup.py --help build_ext
616+ [...]
617+ Options for 'build_ext' command:
618+ --build-lib (-b) directory for compiled extension modules
619+ --build-temp (-t) directory for temporary files (build by-products)
620+ --inplace (-i) ignore build-lib and put compiled extensions into the
621+ source directory alongside your pure Python modules
622+ --include-dirs (-I) list of directories to search for header files
623+ --define (-D) C preprocessor macros to define
624+ --undef (-U) C preprocessor macros to undefine
625+ [...]
626+ \end {verbatim }
627+ Or consult section \ref {reference } of this document (the command
628+ reference).
629+
630+ Note that an option spelled \longprogramopt {foo-bar} on the command-line
631+ is spelled \option {foo\_ bar} in configuration files.
632+
633+ For example, say you want your extensions to be built
634+ `` in-place'' ---that is, you have an extension \module {pkg.ext}, and you
635+ want the compiled extension file (\file {ext.so} on Unix, say) to be put
636+ in the same source directory as your pure Python modules
637+ \module {pkg.mod1} and \module {pkg.mod2}. You can always use the
638+ \longprogramopt {inplace} option on the command-line to ensure this:
639+ \begin {verbatim }
640+ python setup.py build_ext --inplace
641+ \end {verbatim }
642+ But this requires that you always specify the \command {build\_ ext}
643+ command explicitly, and remember to provide \longprogramopt {inplace}.
644+ An easier way is to `` set and forget'' this option, by encoding it in
645+ \file {setup.cfg}, the configuration file for this distribution:
646+ \begin {verbatim }
647+ [build_ext]
648+ inplace=1
649+ \end {verbatim }
650+ This will affect all builds of this module distribution, whether or not
651+ you explcitly specify \command {build\_ ext}. If you include
652+ \file {setup.cfg} in your source distribution, it will also affect
653+ end-user builds---which is probably a bad idea for this option, since
654+ always building extensions in-place would break installation of the
655+ module distribution. In certain peculiar cases, though, modules are
656+ built right in their installation directory, so this is conceivably a
657+ useful ability. (Distributing extensions that expect to be built in
658+ their installation directory is almost always a bad idea, though.)
659+
660+ Another example: certain commands take a lot of options that don't
661+ change from run-to-run; for example, \command {bdist\_ rpm} needs to know
662+ everything required to generate a `` spec'' file for creating an RPM
663+ distribution. Some of this information comes from the setup script, and
664+ some is automatically generated by the Distutils (such as the list of
665+ files installed). But some of it has to be supplied as options to
666+ \command {bdist\_ rpm}, which would be very tedious to do on the
667+ command-line for every run. Hence, here is a snippet from the
668+ Distutils' own \file {setup.cfg}:
669+ \begin {verbatim }
670+ [bdist_rpm]
671+ release = 1
672+ packager = Greg Ward <[email protected] > 673+ doc_files = CHANGES.txt
674+ README.txt
675+ USAGE.txt
676+ doc/
677+ examples/
678+ \end {verbatim }
679+ Note that the \option {doc\_ files} option is simply a
680+ whitespace-separated string split across multiple lines for readability.
573681
574682
575683\section {Creating a Source Distribution }
@@ -597,16 +705,21 @@ \section{Creating a Source Distribution}
597705to create a gzipped tarball and a zip file. The available formats are:
598706\begin {tableiii }{l|l|c}{code}%
599707 {Format}{Description}{Notes}
600- \lineiii {zip}{zip file (\file {.zip})}{(1)}
601- \lineiii {gztar}{gzipped tar file (\file {.tar.gz})}{(2)}
602- \lineiii {ztar}{compressed tar file (\file {.tar.Z})}{}
708+ \lineiii {zip}{zip file (\file {.zip})}{(1),(2)}
709+ \lineiii {gztar}{gzip'ed tar file (\file {.tar.gz})}{(3),(4)}
710+ \lineiii {bztar}{bzip2'ed tar file (\file {.tar.gz})}{(4)}
711+ \lineiii {ztar}{compressed tar file (\file {.tar.Z})}{(4)}
603712 \lineiii {tar}{tar file (\file {.tar})}{}
604713\end {tableiii }
605714
606715\noindent Notes:
607716\begin {description }
608717\item [(1)] default on Windows
609- \item [(2)] default on Unix
718+ \item [(2)] under both Unix and Windows, requires either external
719+ Info-ZIP utility \emph {or } the \module {zipfile} module
720+ \item [(3)] default on Unix
721+ \item [(4)] requires external utilities: \program {tar} and possibly one
722+ of \program {gzip}, \program {bzip2}, or \program {compress}
610723\end {description }
611724
612725
@@ -659,7 +772,7 @@ \subsection{The manifest and manifest template}
659772reference, and then used to build the source distribution archive(s).
660773
661774Following the Distutils' own manifest template, let's trace how the
662- \command {sdist} command will build the list of files to include in the
775+ \command {sdist} command builds the list of files to include in the
663776Distutils source distribution:
664777\begin {enumerate }
665778\item include all Python source files in the \file {distutils} and
@@ -869,7 +982,7 @@ \subsection{Writing new commands}
869982
870983
871984\section {Reference }
872- \label {ref }
985+ \label {reference }
873986
874987
875988\subsection {Building modules: the \protect\command {build} command family }
0 commit comments