Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1 | \documentclass{manual} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 2 | \usepackage{distutils} |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 3 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 4 | % $Id$ |
| 5 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 6 | % TODO |
| 7 | % Document extension.read_setup_file |
| 8 | % Document build_clib command |
| 9 | % |
| 10 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 11 | \title{Distributing Python Modules} |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 12 | |
Fred Drake | 20d4738 | 2004-01-23 15:23:49 +0000 | [diff] [blame] | 13 | \input{boilerplate} |
| 14 | |
Fred Drake | 6fca7cc | 2004-03-23 18:43:03 +0000 | [diff] [blame^] | 15 | \author{Greg Ward\\ |
| 16 | Anthony Baxter} |
Fred Drake | b914ef0 | 2004-01-02 06:57:50 +0000 | [diff] [blame] | 17 | \authoraddress{ |
| 18 | \strong{Python Software Foundation}\\ |
| 19 | Email: \email{distutils-sig@python.org} |
| 20 | } |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 21 | |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 22 | \makeindex |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 23 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 24 | \begin{document} |
| 25 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 26 | \maketitle |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 27 | \begin{abstract} |
| 28 | \noindent |
| 29 | This document describes the Python Distribution Utilities |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 30 | (``Distutils'') from the module developer's point of view, describing |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 31 | how to use the Distutils to make Python modules and extensions easily |
| 32 | available to a wider audience with very little overhead for |
| 33 | build/release/install mechanics. |
| 34 | \end{abstract} |
| 35 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 36 | % The ugly "%begin{latexonly}" pseudo-environment supresses the table |
| 37 | % of contents for HTML generation. |
| 38 | % |
| 39 | %begin{latexonly} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 40 | \tableofcontents |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 41 | %end{latexonly} |
| 42 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 43 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 44 | \chapter{An Introduction to Distutils} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 45 | \label{intro} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 46 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 47 | This document covers using the Distutils to distribute your Python |
| 48 | modules, concentrating on the role of developer/distributor: if |
Fred Drake | 01df453 | 2000-06-30 03:36:41 +0000 | [diff] [blame] | 49 | you're looking for information on installing Python modules, you |
| 50 | should refer to the \citetitle[../inst/inst.html]{Installing Python |
| 51 | Modules} manual. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 52 | |
| 53 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 54 | \section{Concepts \& Terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 55 | \label{concepts} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 56 | |
| 57 | Using the Distutils is quite simple, both for module developers and for |
| 58 | users/administrators installing third-party modules. As a developer, |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 59 | your responsibilities (apart from writing solid, well-documented and |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 60 | well-tested code, of course!) are: |
| 61 | \begin{itemize} |
| 62 | \item write a setup script (\file{setup.py} by convention) |
| 63 | \item (optional) write a setup configuration file |
| 64 | \item create a source distribution |
| 65 | \item (optional) create one or more built (binary) distributions |
| 66 | \end{itemize} |
| 67 | Each of these tasks is covered in this document. |
| 68 | |
| 69 | Not all module developers have access to a multitude of platforms, so |
| 70 | it's not always feasible to expect them to create a multitude of built |
| 71 | distributions. It is hoped that a class of intermediaries, called |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 72 | \emph{packagers}, will arise to address this need. Packagers will take |
| 73 | source distributions released by module developers, build them on one or |
| 74 | more platforms, and release the resulting built distributions. Thus, |
| 75 | users on the most popular platforms will be able to install most popular |
| 76 | Python module distributions in the most natural way for their platform, |
| 77 | without having to run a single setup script or compile a line of code. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 78 | |
| 79 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 80 | \section{A Simple Example} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 81 | \label{simple-example} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 82 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 83 | The setup script is usually quite simple, although since it's written |
| 84 | in Python, there are no arbitrary limits to what you can do with it, |
| 85 | though you should be careful about putting arbitrarily expensive |
| 86 | operations in your setup script. Unlike, say, Autoconf-style configure |
| 87 | scripts, the setup script may be run multiple times in the course of |
Andrew M. Kuchling | e9a54a3 | 2003-05-13 15:02:06 +0000 | [diff] [blame] | 88 | building and installing your module distribution. |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 89 | |
| 90 | If all you want to do is distribute a module called \module{foo}, |
| 91 | contained in a file \file{foo.py}, then your setup script can be as |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 92 | simple as this: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 93 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 94 | \begin{verbatim} |
| 95 | from distutils.core import setup |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 96 | setup(name="foo", |
| 97 | version="1.0", |
| 98 | py_modules=["foo"]) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 99 | \end{verbatim} |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 100 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 101 | Some observations: |
| 102 | \begin{itemize} |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 103 | \item most information that you supply to the Distutils is supplied as |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 104 | keyword arguments to the \function{setup()} function |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 105 | \item those keyword arguments fall into two categories: package |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 106 | metadata (name, version number) and information about what's in the |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 107 | package (a list of pure Python modules, in this case) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 108 | \item modules are specified by module name, not filename (the same will |
| 109 | hold true for packages and extensions) |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 110 | \item it's recommended that you supply a little more metadata, in |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 111 | particular your name, email address and a URL for the project |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 112 | (see section~\ref{setup-script} for an example) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 113 | \end{itemize} |
| 114 | |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 115 | To create a source distribution for this module, you would create a |
| 116 | setup script, \file{setup.py}, containing the above code, and run: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 117 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 118 | \begin{verbatim} |
| 119 | python setup.py sdist |
| 120 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 121 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 122 | which will create an archive file (e.g., tarball on \UNIX, ZIP file on |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 123 | Windows) containing your setup script \file{setup.py}, and your module |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 124 | \file{foo.py}. The archive file will be named \file{foo-1.0.tar.gz} (or |
| 125 | \file{.zip}), and will unpack into a directory \file{foo-1.0}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 126 | |
| 127 | If an end-user wishes to install your \module{foo} module, all she has |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 128 | to do is download \file{foo-1.0.tar.gz} (or \file{.zip}), unpack it, |
| 129 | and---from the \file{foo-1.0} directory---run |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 130 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 131 | \begin{verbatim} |
| 132 | python setup.py install |
| 133 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 134 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 135 | which will ultimately copy \file{foo.py} to the appropriate directory |
| 136 | for third-party modules in their Python installation. |
| 137 | |
| 138 | This simple example demonstrates some fundamental concepts of the |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 139 | Distutils. First, both developers and installers have the same basic |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 140 | user interface, i.e. the setup script. The difference is which |
| 141 | Distutils \emph{commands} they use: the \command{sdist} command is |
| 142 | almost exclusively for module developers, while \command{install} is |
| 143 | more often for installers (although most developers will want to install |
| 144 | their own code occasionally). |
| 145 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 146 | If you want to make things really easy for your users, you can create |
| 147 | one or more built distributions for them. For instance, if you are |
| 148 | running on a Windows machine, and want to make things easy for other |
| 149 | Windows users, you can create an executable installer (the most |
| 150 | appropriate type of built distribution for this platform) with the |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 151 | \command{bdist\_wininst} command. For example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 152 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 153 | \begin{verbatim} |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 154 | python setup.py bdist_wininst |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 155 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 156 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 157 | will create an executable installer, \file{foo-1.0.win32.exe}, in the |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 158 | current directory. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 159 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 160 | Other useful built distribution formats are RPM, implemented by the |
| 161 | \command{bdist\_rpm} command, Solaris \program{pkgtool} |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 162 | (\command{bdist\_pkgtool}), and HP-UX \program{swinstall} |
| 163 | (\command{bdist_sdux}). For example, the following command will |
| 164 | create an RPM file called \file{foo-1.0.noarch.rpm}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 165 | |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 166 | \begin{verbatim} |
| 167 | python setup.py bdist_rpm |
| 168 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 169 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 170 | (The \command{bdist\_rpm} command uses the \command{rpm} executable, |
| 171 | therefore this has to be run on an RPM-based system such as Red Hat |
| 172 | Linux, SuSE Linux, or Mandrake Linux.) |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 173 | |
| 174 | You can find out what distribution formats are available at any time by |
| 175 | running |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 176 | |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 177 | \begin{verbatim} |
| 178 | python setup.py bdist --help-formats |
| 179 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 180 | |
| 181 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 182 | \section{General Python terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 183 | \label{python-terms} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 184 | |
| 185 | If you're reading this document, you probably have a good idea of what |
| 186 | modules, extensions, and so forth are. Nevertheless, just to be sure |
| 187 | that everyone is operating from a common starting point, we offer the |
| 188 | following glossary of common Python terms: |
| 189 | \begin{description} |
| 190 | \item[module] the basic unit of code reusability in Python: a block of |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 191 | code imported by some other code. Three types of modules concern us |
| 192 | here: pure Python modules, extension modules, and packages. |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 193 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 194 | \item[pure Python module] a module written in Python and contained in a |
| 195 | single \file{.py} file (and possibly associated \file{.pyc} and/or |
| 196 | \file{.pyo} files). Sometimes referred to as a ``pure module.'' |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 197 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 198 | \item[extension module] a module written in the low-level language of |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 199 | the Python implementation: C/\Cpp{} for Python, Java for Jython. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 200 | Typically contained in a single dynamically loadable pre-compiled |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 201 | file, e.g. a shared object (\file{.so}) file for Python extensions on |
| 202 | \UNIX, a DLL (given the \file{.pyd} extension) for Python extensions |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 203 | on Windows, or a Java class file for Jython extensions. (Note that |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 204 | currently, the Distutils only handles C/\Cpp{} extensions for Python.) |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 205 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 206 | \item[package] a module that contains other modules; typically contained |
| 207 | in a directory in the filesystem and distinguished from other |
| 208 | directories by the presence of a file \file{\_\_init\_\_.py}. |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 209 | |
Greg Ward | 6153fa1 | 2000-05-26 02:24:28 +0000 | [diff] [blame] | 210 | \item[root package] the root of the hierarchy of packages. (This isn't |
| 211 | really a package, since it doesn't have an \file{\_\_init\_\_.py} |
| 212 | file. But we have to call it something.) The vast majority of the |
| 213 | standard library is in the root package, as are many small, standalone |
| 214 | third-party modules that don't belong to a larger module collection. |
| 215 | Unlike regular packages, modules in the root package can be found in |
| 216 | many directories: in fact, every directory listed in \code{sys.path} |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 217 | contributes modules to the root package. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 218 | \end{description} |
| 219 | |
| 220 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 221 | \section{Distutils-specific terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 222 | \label{distutils-term} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 223 | |
| 224 | The following terms apply more specifically to the domain of |
| 225 | distributing Python modules using the Distutils: |
| 226 | \begin{description} |
| 227 | \item[module distribution] a collection of Python modules distributed |
| 228 | together as a single downloadable resource and meant to be installed |
| 229 | \emph{en masse}. Examples of some well-known module distributions are |
| 230 | Numeric Python, PyXML, PIL (the Python Imaging Library), or |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 231 | mxBase. (This would be called a \emph{package}, except that term |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 232 | is already taken in the Python context: a single module distribution |
| 233 | may contain zero, one, or many Python packages.) |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 234 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 235 | \item[pure module distribution] a module distribution that contains only |
| 236 | pure Python modules and packages. Sometimes referred to as a ``pure |
| 237 | distribution.'' |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 238 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 239 | \item[non-pure module distribution] a module distribution that contains |
| 240 | at least one extension module. Sometimes referred to as a ``non-pure |
| 241 | distribution.'' |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 242 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 243 | \item[distribution root] the top-level directory of your source tree (or |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 244 | source distribution); the directory where \file{setup.py} exists. Generally |
| 245 | \file{setup.py} will be run from this directory. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 246 | \end{description} |
| 247 | |
| 248 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 249 | \chapter{Writing the Setup Script} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 250 | \label{setup-script} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 251 | |
| 252 | The setup script is the centre of all activity in building, |
| 253 | distributing, and installing modules using the Distutils. The main |
| 254 | purpose of the setup script is to describe your module distribution to |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 255 | the Distutils, so that the various commands that operate on your modules |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 256 | do the right thing. As we saw in section~\ref{simple-example} above, |
| 257 | the setup script consists mainly of a call to \function{setup()}, and |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 258 | most information supplied to the Distutils by the module developer is |
| 259 | supplied as keyword arguments to \function{setup()}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 260 | |
| 261 | Here's a slightly more involved example, which we'll follow for the next |
| 262 | couple of sections: the Distutils' own setup script. (Keep in mind that |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 263 | although the Distutils are included with Python 1.6 and later, they also |
| 264 | have an independent existence so that Python 1.5.2 users can use them to |
| 265 | install other module distributions. The Distutils' own setup script, |
| 266 | shown here, is used to install the package into Python 1.5.2.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 267 | |
| 268 | \begin{verbatim} |
| 269 | #!/usr/bin/env python |
| 270 | |
| 271 | from distutils.core import setup |
| 272 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 273 | setup(name="Distutils", |
| 274 | version="1.0", |
| 275 | description="Python Distribution Utilities", |
| 276 | author="Greg Ward", |
| 277 | author_email="gward@python.net", |
| 278 | url="http://www.python.org/sigs/distutils-sig/", |
| 279 | packages=['distutils', 'distutils.command'], |
| 280 | ) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 281 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 282 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 283 | There are only two differences between this and the trivial one-file |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 284 | distribution presented in section~\ref{simple-example}: more |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 285 | metadata, and the specification of pure Python modules by package, |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 286 | rather than by module. This is important since the Distutils consist of |
| 287 | a couple of dozen modules split into (so far) two packages; an explicit |
| 288 | list of every module would be tedious to generate and difficult to |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 289 | maintain. For more information on the additional meta-data, see |
| 290 | section~\ref{meta-data}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 291 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 292 | Note that any pathnames (files or directories) supplied in the setup |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 293 | script should be written using the \UNIX{} convention, i.e. |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 294 | slash-separated. The Distutils will take care of converting this |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 295 | platform-neutral representation into whatever is appropriate on your |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 296 | current platform before actually using the pathname. This makes your |
| 297 | setup script portable across operating systems, which of course is one |
| 298 | of the major goals of the Distutils. In this spirit, all pathnames in |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 299 | this document are slash-separated. (Mac OS programmers should keep in |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 300 | mind that the \emph{absence} of a leading slash indicates a relative |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 301 | path, the opposite of the Mac OS convention with colons.) |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 302 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 303 | This, of course, only applies to pathnames given to Distutils |
Fred Drake | 2a04623 | 2003-03-31 16:23:09 +0000 | [diff] [blame] | 304 | functions. If you, for example, use standard Python functions such as |
| 305 | \function{glob.glob()} or \function{os.listdir()} to specify files, you |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 306 | should be careful to write portable code instead of hardcoding path |
| 307 | separators: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 308 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 309 | \begin{verbatim} |
| 310 | glob.glob(os.path.join('mydir', 'subdir', '*.html')) |
| 311 | os.listdir(os.path.join('mydir', 'subdir')) |
| 312 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 313 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 314 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 315 | \subsection{Listing whole packages} |
| 316 | \label{listing-packages} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 317 | |
| 318 | The \option{packages} option tells the Distutils to process (build, |
| 319 | distribute, install, etc.) all pure Python modules found in each package |
| 320 | mentioned in the \option{packages} list. In order to do this, of |
| 321 | course, there has to be a correspondence between package names and |
| 322 | directories in the filesystem. The default correspondence is the most |
Greg Ward | 1ecc251 | 2000-04-19 22:36:24 +0000 | [diff] [blame] | 323 | obvious one, i.e. package \module{distutils} is found in the directory |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 324 | \file{distutils} relative to the distribution root. Thus, when you say |
| 325 | \code{packages = ['foo']} in your setup script, you are promising that |
| 326 | the Distutils will find a file \file{foo/\_\_init\_\_.py} (which might |
| 327 | be spelled differently on your system, but you get the idea) relative to |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 328 | the directory where your setup script lives. If you break this |
| 329 | promise, the Distutils will issue a warning but still process the broken |
| 330 | package anyways. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 331 | |
| 332 | If you use a different convention to lay out your source directory, |
| 333 | that's no problem: you just have to supply the \option{package\_dir} |
| 334 | option to tell the Distutils about your convention. For example, say |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 335 | you keep all Python source under \file{lib}, so that modules in the |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 336 | ``root package'' (i.e., not in any package at all) are in |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 337 | \file{lib}, modules in the \module{foo} package are in \file{lib/foo}, |
| 338 | and so forth. Then you would put |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 339 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 340 | \begin{verbatim} |
| 341 | package_dir = {'': 'lib'} |
| 342 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 343 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 344 | in your setup script. The keys to this dictionary are package names, |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 345 | and an empty package name stands for the root package. The values are |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 346 | directory names relative to your distribution root. In this case, when |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 347 | you say \code{packages = ['foo']}, you are promising that the file |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 348 | \file{lib/foo/\_\_init\_\_.py} exists. |
| 349 | |
Greg Ward | 1ecc251 | 2000-04-19 22:36:24 +0000 | [diff] [blame] | 350 | Another possible convention is to put the \module{foo} package right in |
| 351 | \file{lib}, the \module{foo.bar} package in \file{lib/bar}, etc. This |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 352 | would be written in the setup script as |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 353 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 354 | \begin{verbatim} |
| 355 | package_dir = {'foo': 'lib'} |
| 356 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 357 | |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 358 | A \code{\var{package}: \var{dir}} entry in the \option{package\_dir} |
| 359 | dictionary implicitly applies to all packages below \var{package}, so |
| 360 | the \module{foo.bar} case is automatically handled here. In this |
| 361 | example, having \code{packages = ['foo', 'foo.bar']} tells the Distutils |
| 362 | to look for \file{lib/\_\_init\_\_.py} and |
| 363 | \file{lib/bar/\_\_init\_\_.py}. (Keep in mind that although |
| 364 | \option{package\_dir} applies recursively, you must explicitly list all |
| 365 | packages in \option{packages}: the Distutils will \emph{not} recursively |
| 366 | scan your source tree looking for any directory with an |
| 367 | \file{\_\_init\_\_.py} file.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 368 | |
| 369 | |
| 370 | \subsection{Listing individual modules} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 371 | \label{listing-modules} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 372 | |
| 373 | For a small module distribution, you might prefer to list all modules |
| 374 | rather than listing packages---especially the case of a single module |
| 375 | that goes in the ``root package'' (i.e., no package at all). This |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 376 | simplest case was shown in section~\ref{simple-example}; here is a |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 377 | slightly more involved example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 378 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 379 | \begin{verbatim} |
| 380 | py_modules = ['mod1', 'pkg.mod2'] |
| 381 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 382 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 383 | This describes two modules, one of them in the ``root'' package, the |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 384 | other in the \module{pkg} package. Again, the default package/directory |
| 385 | layout implies that these two modules can be found in \file{mod1.py} and |
| 386 | \file{pkg/mod2.py}, and that \file{pkg/\_\_init\_\_.py} exists as well. |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 387 | And again, you can override the package/directory correspondence using |
| 388 | the \option{package\_dir} option. |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 389 | |
| 390 | |
| 391 | \subsection{Describing extension modules} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 392 | \label{describing-extensions} |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 393 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 394 | % XXX read over this section |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 395 | Just as writing Python extension modules is a bit more complicated than |
| 396 | writing pure Python modules, describing them to the Distutils is a bit |
| 397 | more complicated. Unlike pure modules, it's not enough just to list |
| 398 | modules or packages and expect the Distutils to go out and find the |
| 399 | right files; you have to specify the extension name, source file(s), and |
| 400 | any compile/link requirements (include directories, libraries to link |
| 401 | with, etc.). |
| 402 | |
| 403 | All of this is done through another keyword argument to |
| 404 | \function{setup()}, the \option{extensions} option. \option{extensions} |
| 405 | is just a list of \class{Extension} instances, each of which describes a |
| 406 | single extension module. Suppose your distribution includes a single |
| 407 | extension, called \module{foo} and implemented by \file{foo.c}. If no |
| 408 | additional instructions to the compiler/linker are needed, describing |
| 409 | this extension is quite simple: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 410 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 411 | \begin{verbatim} |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 412 | uExtension("foo", ["foo.c"]) |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 413 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 414 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 415 | The \class{Extension} class can be imported from |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 416 | \module{distutils.core} along with \function{setup()}. Thus, the setup |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 417 | script for a module distribution that contains only this one extension |
| 418 | and nothing else might be: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 419 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 420 | \begin{verbatim} |
| 421 | from distutils.core import setup, Extension |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 422 | setup(name="foo", version="1.0", |
| 423 | ext_modules=[Extension("foo", ["foo.c"])]) |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 424 | \end{verbatim} |
| 425 | |
| 426 | The \class{Extension} class (actually, the underlying extension-building |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 427 | machinery implemented by the \command{build\_ext} command) supports a |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 428 | great deal of flexibility in describing Python extensions, which is |
| 429 | explained in the following sections. |
| 430 | |
| 431 | |
| 432 | \subsubsection{Extension names and packages} |
| 433 | |
| 434 | The first argument to the \class{Extension} constructor is always the |
| 435 | name of the extension, including any package names. For example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 436 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 437 | \begin{verbatim} |
| 438 | Extension("foo", ["src/foo1.c", "src/foo2.c"]) |
| 439 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 440 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 441 | describes an extension that lives in the root package, while |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 442 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 443 | \begin{verbatim} |
| 444 | Extension("pkg.foo", ["src/foo1.c", "src/foo2.c"]) |
| 445 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 446 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 447 | describes the same extension in the \module{pkg} package. The source |
| 448 | files and resulting object code are identical in both cases; the only |
| 449 | difference is where in the filesystem (and therefore where in Python's |
| 450 | namespace hierarchy) the resulting extension lives. |
| 451 | |
| 452 | If you have a number of extensions all in the same package (or all under |
| 453 | the same base package), use the \option{ext\_package} keyword argument |
| 454 | to \function{setup()}. For example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 455 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 456 | \begin{verbatim} |
| 457 | setup(... |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 458 | ext_package="pkg", |
| 459 | ext_modules=[Extension("foo", ["foo.c"]), |
| 460 | Extension("subpkg.bar", ["bar.c"])] |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 461 | ) |
| 462 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 463 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 464 | will compile \file{foo.c} to the extension \module{pkg.foo}, and |
| 465 | \file{bar.c} to \module{pkg.subpkg.bar}. |
| 466 | |
| 467 | |
| 468 | \subsubsection{Extension source files} |
| 469 | |
| 470 | The second argument to the \class{Extension} constructor is a list of |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 471 | source files. Since the Distutils currently only support C, \Cpp, and |
| 472 | Objective-C extensions, these are normally C/\Cpp/Objective-C source |
| 473 | files. (Be sure to use appropriate extensions to distinguish \Cpp\ |
| 474 | source files: \file{.cc} and \file{.cpp} seem to be recognized by both |
| 475 | \UNIX{} and Windows compilers.) |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 476 | |
| 477 | However, you can also include SWIG interface (\file{.i}) files in the |
| 478 | list; the \command{build\_ext} command knows how to deal with SWIG |
| 479 | extensions: it will run SWIG on the interface file and compile the |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 480 | resulting C/\Cpp{} file into your extension. |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 481 | |
| 482 | \XXX{SWIG support is rough around the edges and largely untested; |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 483 | especially SWIG support for \Cpp{} extensions! Explain in more detail |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 484 | here when the interface firms up.} |
| 485 | |
| 486 | On some platforms, you can include non-source files that are processed |
| 487 | by the compiler and included in your extension. Currently, this just |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 488 | means Windows message text (\file{.mc}) files and resource definition |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 489 | (\file{.rc}) files for Visual \Cpp. These will be compiled to binary resource |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 490 | (\file{.res}) files and linked into the executable. |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 491 | |
| 492 | |
| 493 | \subsubsection{Preprocessor options} |
| 494 | |
| 495 | Three optional arguments to \class{Extension} will help if you need to |
| 496 | specify include directories to search or preprocessor macros to |
| 497 | define/undefine: \code{include\_dirs}, \code{define\_macros}, and |
| 498 | \code{undef\_macros}. |
| 499 | |
| 500 | For example, if your extension requires header files in the |
| 501 | \file{include} directory under your distribution root, use the |
| 502 | \code{include\_dirs} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 503 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 504 | \begin{verbatim} |
| 505 | Extension("foo", ["foo.c"], include_dirs=["include"]) |
| 506 | \end{verbatim} |
| 507 | |
| 508 | You can specify absolute directories there; if you know that your |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 509 | extension will only be built on \UNIX{} systems with X11R6 installed to |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 510 | \file{/usr}, you can get away with |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 511 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 512 | \begin{verbatim} |
| 513 | Extension("foo", ["foo.c"], include_dirs=["/usr/include/X11"]) |
| 514 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 515 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 516 | You should avoid this sort of non-portable usage if you plan to |
Greg Ward | 58437f2 | 2002-05-10 14:40:22 +0000 | [diff] [blame] | 517 | distribute your code: it's probably better to write C code like |
| 518 | \begin{verbatim} |
| 519 | #include <X11/Xlib.h> |
| 520 | \end{verbatim} |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 521 | |
| 522 | If you need to include header files from some other Python extension, |
Greg Ward | 58437f2 | 2002-05-10 14:40:22 +0000 | [diff] [blame] | 523 | you can take advantage of the fact that header files are installed in a |
| 524 | consistent way by the Distutils \command{install\_header} command. For |
| 525 | example, the Numerical Python header files are installed (on a standard |
| 526 | Unix installation) to \file{/usr/local/include/python1.5/Numerical}. |
| 527 | (The exact location will differ according to your platform and Python |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 528 | installation.) Since the Python include |
Greg Ward | 58437f2 | 2002-05-10 14:40:22 +0000 | [diff] [blame] | 529 | directory---\file{/usr/local/include/python1.5} in this case---is always |
| 530 | included in the search path when building Python extensions, the best |
| 531 | approach is to write C code like |
| 532 | \begin{verbatim} |
| 533 | #include <Numerical/arrayobject.h> |
| 534 | \end{verbatim} |
| 535 | If you must put the \file{Numerical} include directory right into your |
| 536 | header search path, though, you can find that directory using the |
| 537 | Distutils \module{sysconfig} module: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 538 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 539 | \begin{verbatim} |
| 540 | from distutils.sysconfig import get_python_inc |
| 541 | incdir = os.path.join(get_python_inc(plat_specific=1), "Numerical") |
| 542 | setup(..., |
| 543 | Extension(..., include_dirs=[incdir])) |
| 544 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 545 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 546 | Even though this is quite portable---it will work on any Python |
| 547 | installation, regardless of platform---it's probably easier to just |
| 548 | write your C code in the sensible way. |
| 549 | |
| 550 | You can define and undefine pre-processor macros with the |
| 551 | \code{define\_macros} and \code{undef\_macros} options. |
| 552 | \code{define\_macros} takes a list of \code{(name, value)} tuples, where |
| 553 | \code{name} is the name of the macro to define (a string) and |
| 554 | \code{value} is its value: either a string or \code{None}. (Defining a |
| 555 | macro \code{FOO} to \code{None} is the equivalent of a bare |
| 556 | \code{\#define FOO} in your C source: with most compilers, this sets |
| 557 | \code{FOO} to the string \code{1}.) \code{undef\_macros} is just |
| 558 | a list of macros to undefine. |
| 559 | |
| 560 | For example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 561 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 562 | \begin{verbatim} |
| 563 | Extension(..., |
Thomas Heller | 95a97d5 | 2003-10-08 12:01:33 +0000 | [diff] [blame] | 564 | define_macros=[('NDEBUG', '1'), |
| 565 | ('HAVE_STRFTIME', None)], |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 566 | undef_macros=['HAVE_FOO', 'HAVE_BAR']) |
| 567 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 568 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 569 | is the equivalent of having this at the top of every C source file: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 570 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 571 | \begin{verbatim} |
| 572 | #define NDEBUG 1 |
| 573 | #define HAVE_STRFTIME |
| 574 | #undef HAVE_FOO |
| 575 | #undef HAVE_BAR |
| 576 | \end{verbatim} |
| 577 | |
| 578 | |
| 579 | \subsubsection{Library options} |
| 580 | |
| 581 | You can also specify the libraries to link against when building your |
| 582 | extension, and the directories to search for those libraries. The |
| 583 | \code{libraries} option is a list of libraries to link against, |
| 584 | \code{library\_dirs} is a list of directories to search for libraries at |
| 585 | link-time, and \code{runtime\_library\_dirs} is a list of directories to |
| 586 | search for shared (dynamically loaded) libraries at run-time. |
| 587 | |
| 588 | For example, if you need to link against libraries known to be in the |
| 589 | standard library search path on target systems |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 590 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 591 | \begin{verbatim} |
| 592 | Extension(..., |
| 593 | libraries=["gdbm", "readline"]) |
| 594 | \end{verbatim} |
| 595 | |
| 596 | If you need to link with libraries in a non-standard location, you'll |
| 597 | have to include the location in \code{library\_dirs}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 598 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 599 | \begin{verbatim} |
| 600 | Extension(..., |
| 601 | library_dirs=["/usr/X11R6/lib"], |
| 602 | libraries=["X11", "Xt"]) |
| 603 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 604 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 605 | (Again, this sort of non-portable construct should be avoided if you |
| 606 | intend to distribute your code.) |
| 607 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 608 | \XXX{Should mention clib libraries here or somewhere else!} |
| 609 | |
| 610 | \subsubsection{Other options} |
| 611 | |
| 612 | There are still some other options which can be used to handle special |
| 613 | cases. |
| 614 | |
| 615 | The \option{extra\_objects} option is a list of object files to be passed |
| 616 | to the linker. These files must not have extensions, as the default |
| 617 | extension for the compiler is used. |
| 618 | |
| 619 | \option{extra\_compile\_args} and \option{extra\_link\_args} can be used |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 620 | to specify additional command line options for the respective compiler and |
| 621 | linker command lines. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 622 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 623 | \option{export\_symbols} is only useful on Windows. It can contain a list |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 624 | of symbols (functions or variables) to be exported. This option |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 625 | is not needed when building compiled extensions: Distutils |
| 626 | will automatically add \code{initmodule} |
| 627 | to the list of exported symbols. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 628 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 629 | \subsection{Installing Scripts} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 630 | So far we have been dealing with pure and non-pure Python modules, |
| 631 | which are usually not run by themselves but imported by scripts. |
| 632 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 633 | Scripts are files containing Python source code, intended to be |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 634 | started from the command line. Scripts don't require Distutils to do |
| 635 | anything very complicated. The only clever feature is that if the |
| 636 | first line of the script starts with \code{\#!} and contains the word |
| 637 | ``python'', the Distutils will adjust the first line to refer to the |
| 638 | current interpreter location. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 639 | |
| 640 | The \option{scripts} option simply is a list of files to be handled |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 641 | in this way. From the PyXML setup script: |
| 642 | |
| 643 | \begin{verbatim} |
| 644 | setup (... |
| 645 | scripts = ['scripts/xmlproc_parse', 'scripts/xmlproc_val'] |
| 646 | ) |
| 647 | \end{verbatim} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 648 | |
| 649 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 650 | \subsection{Installing Additional Files} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 651 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 652 | The \option{data\_files} option can be used to specify additional |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 653 | files needed by the module distribution: configuration files, message |
| 654 | catalogs, data files, anything which doesn't fit in the previous |
| 655 | categories. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 656 | |
Fred Drake | 632bda3 | 2002-03-08 22:02:06 +0000 | [diff] [blame] | 657 | \option{data\_files} specifies a sequence of (\var{directory}, |
| 658 | \var{files}) pairs in the following way: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 659 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 660 | \begin{verbatim} |
| 661 | setup(... |
| 662 | data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']), |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 663 | ('config', ['cfg/data.cfg']), |
| 664 | ('/etc/init.d', ['init-script'])] |
| 665 | ) |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 666 | \end{verbatim} |
| 667 | |
| 668 | Note that you can specify the directory names where the data files |
| 669 | will be installed, but you cannot rename the data files themselves. |
| 670 | |
Fred Drake | 632bda3 | 2002-03-08 22:02:06 +0000 | [diff] [blame] | 671 | Each (\var{directory}, \var{files}) pair in the sequence specifies the |
| 672 | installation directory and the files to install there. If |
| 673 | \var{directory} is a relative path, it is interpreted relative to the |
| 674 | installation prefix (Python's \code{sys.prefix} for pure-Python |
| 675 | packages, \code{sys.exec_prefix} for packages that contain extension |
| 676 | modules). Each file name in \var{files} is interpreted relative to |
| 677 | the \file{setup.py} script at the top of the package source |
| 678 | distribution. No directory information from \var{files} is used to |
| 679 | determine the final location of the installed file; only the name of |
| 680 | the file is used. |
| 681 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 682 | You can specify the \option{data\_files} options as a simple sequence |
| 683 | of files without specifying a target directory, but this is not recommended, |
| 684 | and the \command{install} command will print a warning in this case. |
| 685 | To install data files directly in the target directory, an empty |
| 686 | string should be given as the directory. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 687 | |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 688 | \subsection{Additional meta-data} |
| 689 | \label{meta-data} |
| 690 | |
| 691 | The setup script may include additional meta-data beyond the name and |
| 692 | version. This information includes: |
| 693 | |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 694 | \begin{tableiv}{l|l|l|c}{code}% |
| 695 | {Meta-Data}{Description}{Value}{Notes} |
| 696 | \lineiv{name}{name of the package} |
| 697 | {short string}{(1)} |
| 698 | \lineiv{version}{version of this release} |
| 699 | {short string}{(1)(2)} |
| 700 | \lineiv{author}{package author's name} |
| 701 | {short string}{(3)} |
| 702 | \lineiv{author_email}{email address of the package author} |
| 703 | {email address}{(3)} |
| 704 | \lineiv{maintainer}{package maintainer's name} |
| 705 | {short string}{(3)} |
| 706 | \lineiv{maintainer_email}{email address of the package maintainer} |
| 707 | {email address}{(3)} |
| 708 | \lineiv{url}{home page for the package} |
| 709 | {URL}{(1)} |
| 710 | \lineiv{description}{short, summary description of the package} |
| 711 | {short string}{} |
| 712 | \lineiv{long_description}{longer description of the package} |
| 713 | {long string}{} |
| 714 | \lineiv{download_url}{location where the package may be downloaded} |
| 715 | {URL}{(4)} |
| 716 | \lineiv{classifiers}{a list of Trove classifiers} |
| 717 | {list of strings}{(4)} |
| 718 | \end{tableiv} |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 719 | |
| 720 | \noindent Notes: |
| 721 | \begin{description} |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 722 | \item[(1)] These fields are required. |
| 723 | \item[(2)] It is recommended that versions take the form |
| 724 | \emph{major.minor\optional{.patch\optional{.sub}}}. |
| 725 | \item[(3)] Either the author or the maintainer must be identified. |
| 726 | \item[(4)] These fields should not be used if your package is to be |
| 727 | compatible with Python versions prior to 2.2.3 or 2.3. The list is |
| 728 | available from the \ulink{PyPI website}{http://www.python.org/pypi}. |
| 729 | |
| 730 | \item["short string"] A single line of text, not more than 200 characters. |
| 731 | \item["long string"] Multiple lines of plain text in ReStructuredText |
| 732 | format (see \url{http://docutils.sf.net/}). |
| 733 | \item["list of strings"] See below. |
| 734 | \end{description} |
| 735 | |
| 736 | None of the string values may be Unicode. |
| 737 | |
| 738 | Encoding the version information is an art in itself. Python packages |
| 739 | generally adhere to the version format |
| 740 | \emph{major.minor\optional{.patch}\optional{sub}}. The major number is |
| 741 | 0 for |
| 742 | initial, experimental releases of software. It is incremented for |
| 743 | releases that represent major milestones in a package. The minor |
| 744 | number is incremented when important new features are added to the |
| 745 | package. The patch number increments when bug-fix releases are |
| 746 | made. Additional trailing version information is sometimes used to |
| 747 | indicate sub-releases. These are "a1,a2,...,aN" (for alpha releases, |
| 748 | where functionality and API may change), "b1,b2,...,bN" (for beta |
| 749 | releases, which only fix bugs) and "pr1,pr2,...,prN" (for final |
| 750 | pre-release release testing). Some examples: |
| 751 | |
| 752 | \begin{description} |
| 753 | \item[0.1.0] the first, experimental release of a package |
| 754 | \item[1.0.1a2] the second alpha release of the first patch version of 1.0 |
| 755 | \end{description} |
| 756 | |
| 757 | \option{classifiers} are specified in a python list: |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 758 | |
| 759 | \begin{verbatim} |
| 760 | setup(... |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 761 | classifiers = [ |
Fred Drake | 2a04623 | 2003-03-31 16:23:09 +0000 | [diff] [blame] | 762 | 'Development Status :: 4 - Beta', |
| 763 | 'Environment :: Console', |
| 764 | 'Environment :: Web Environment', |
| 765 | 'Intended Audience :: End Users/Desktop', |
| 766 | 'Intended Audience :: Developers', |
| 767 | 'Intended Audience :: System Administrators', |
| 768 | 'License :: OSI Approved :: Python Software Foundation License', |
| 769 | 'Operating System :: MacOS :: MacOS X', |
| 770 | 'Operating System :: Microsoft :: Windows', |
| 771 | 'Operating System :: POSIX', |
| 772 | 'Programming Language :: Python', |
| 773 | 'Topic :: Communications :: Email', |
| 774 | 'Topic :: Office/Business', |
| 775 | 'Topic :: Software Development :: Bug Tracking', |
| 776 | ], |
Fred Drake | 2a04623 | 2003-03-31 16:23:09 +0000 | [diff] [blame] | 777 | ) |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 778 | \end{verbatim} |
| 779 | |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 780 | If you wish to include classifiers in your \file{setup.py} file and also |
| 781 | wish to remain backwards-compatible with Python releases prior to 2.2.3, |
| 782 | then you can include the following code fragment in your \file{setup.py} |
| 783 | before the \code{setup()} call. |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 784 | |
| 785 | \begin{verbatim} |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 786 | # patch distutils if it can't cope with the "classifiers" or |
| 787 | # "download_url" keywords |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 788 | if sys.version < '2.2.3': |
| 789 | from distutils.dist import DistributionMetadata |
| 790 | DistributionMetadata.classifiers = None |
Fred Drake | 2a04623 | 2003-03-31 16:23:09 +0000 | [diff] [blame] | 791 | DistributionMetadata.download_url = None |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 792 | \end{verbatim} |
| 793 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 794 | |
Thomas Heller | 675580f | 2003-06-30 19:33:29 +0000 | [diff] [blame] | 795 | \subsection{Debugging the setup script} |
| 796 | \label{meta-data} |
| 797 | |
| 798 | Sometimes things go wrong, and the setup script doesn't do what the |
| 799 | developer wants. |
| 800 | |
| 801 | Distutils catches any exceptions when running the setup script, and |
| 802 | print a simple error message before the script is terminated. The |
| 803 | motivation for this behaviour is to not confuse administrators who |
| 804 | don't know much about Python and are trying to install a package. If |
| 805 | they get a big long traceback from deep inside the guts of Distutils, |
| 806 | they may think the package or the Python installation is broken |
| 807 | because they don't read all the way down to the bottom and see that |
| 808 | it's a permission problem. |
| 809 | |
| 810 | On the other hand, this doesn't help the developer to find the cause |
| 811 | of the failure. For this purpose, the DISTUTILS_DEBUG environment |
| 812 | variable can be set to anything except an empty string, and distutils |
| 813 | will now print detailed information what it is doing, and prints the |
Martin v. Löwis | 95cf84a | 2003-10-19 07:32:24 +0000 | [diff] [blame] | 814 | full traceback in case an exception occurs. |
Thomas Heller | 675580f | 2003-06-30 19:33:29 +0000 | [diff] [blame] | 815 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 816 | \chapter{Writing the Setup Configuration File} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 817 | \label{setup-config} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 818 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 819 | Often, it's not possible to write down everything needed to build a |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 820 | distribution \emph{a priori}: you may need to get some information from |
| 821 | the user, or from the user's system, in order to proceed. As long as |
| 822 | that information is fairly simple---a list of directories to search for |
| 823 | C header files or libraries, for example---then providing a |
| 824 | configuration file, \file{setup.cfg}, for users to edit is a cheap and |
| 825 | easy way to solicit it. Configuration files also let you provide |
| 826 | default values for any command option, which the installer can then |
| 827 | override either on the command-line or by editing the config file. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 828 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 829 | % (If you have more advanced needs, such as determining which extensions |
| 830 | % to build based on what capabilities are present on the target system, |
| 831 | % then you need the Distutils ``auto-configuration'' facility. This |
| 832 | % started to appear in Distutils 0.9 but, as of this writing, isn't mature |
| 833 | % or stable enough yet for real-world use.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 834 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 835 | The setup configuration file is a useful middle-ground between the setup |
| 836 | script---which, ideally, would be opaque to installers\footnote{This |
| 837 | ideal probably won't be achieved until auto-configuration is fully |
| 838 | supported by the Distutils.}---and the command-line to the setup |
| 839 | script, which is outside of your control and entirely up to the |
| 840 | installer. In fact, \file{setup.cfg} (and any other Distutils |
| 841 | configuration files present on the target system) are processed after |
| 842 | the contents of the setup script, but before the command-line. This has |
| 843 | several useful consequences: |
| 844 | \begin{itemize} |
| 845 | \item installers can override some of what you put in \file{setup.py} by |
| 846 | editing \file{setup.cfg} |
| 847 | \item you can provide non-standard defaults for options that are not |
| 848 | easily set in \file{setup.py} |
| 849 | \item installers can override anything in \file{setup.cfg} using the |
| 850 | command-line options to \file{setup.py} |
| 851 | \end{itemize} |
| 852 | |
| 853 | The basic syntax of the configuration file is simple: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 854 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 855 | \begin{verbatim} |
| 856 | [command] |
| 857 | option=value |
| 858 | ... |
| 859 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 860 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 861 | where \var{command} is one of the Distutils commands (e.g. |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 862 | \command{build\_py}, \command{install}), and \var{option} is one of |
| 863 | the options that command supports. Any number of options can be |
| 864 | supplied for each command, and any number of command sections can be |
| 865 | included in the file. Blank lines are ignored, as are comments, which |
| 866 | run from a \character{\#} character until the end of the line. Long |
| 867 | option values can be split across multiple lines simply by indenting |
| 868 | the continuation lines. |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 869 | |
| 870 | You can find out the list of options supported by a particular command |
| 871 | with the universal \longprogramopt{help} option, e.g. |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 872 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 873 | \begin{verbatim} |
| 874 | > python setup.py --help build_ext |
| 875 | [...] |
| 876 | Options for 'build_ext' command: |
| 877 | --build-lib (-b) directory for compiled extension modules |
| 878 | --build-temp (-t) directory for temporary files (build by-products) |
| 879 | --inplace (-i) ignore build-lib and put compiled extensions into the |
| 880 | source directory alongside your pure Python modules |
| 881 | --include-dirs (-I) list of directories to search for header files |
| 882 | --define (-D) C preprocessor macros to define |
| 883 | --undef (-U) C preprocessor macros to undefine |
| 884 | [...] |
| 885 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 886 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 887 | Note that an option spelled \longprogramopt{foo-bar} on the command-line |
| 888 | is spelled \option{foo\_bar} in configuration files. |
| 889 | |
| 890 | For example, say you want your extensions to be built |
| 891 | ``in-place''---that is, you have an extension \module{pkg.ext}, and you |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 892 | want the compiled extension file (\file{ext.so} on \UNIX, say) to be put |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 893 | in the same source directory as your pure Python modules |
| 894 | \module{pkg.mod1} and \module{pkg.mod2}. You can always use the |
| 895 | \longprogramopt{inplace} option on the command-line to ensure this: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 896 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 897 | \begin{verbatim} |
| 898 | python setup.py build_ext --inplace |
| 899 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 900 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 901 | But this requires that you always specify the \command{build\_ext} |
| 902 | command explicitly, and remember to provide \longprogramopt{inplace}. |
| 903 | An easier way is to ``set and forget'' this option, by encoding it in |
| 904 | \file{setup.cfg}, the configuration file for this distribution: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 905 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 906 | \begin{verbatim} |
| 907 | [build_ext] |
| 908 | inplace=1 |
| 909 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 910 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 911 | This will affect all builds of this module distribution, whether or not |
| 912 | you explcitly specify \command{build\_ext}. If you include |
| 913 | \file{setup.cfg} in your source distribution, it will also affect |
| 914 | end-user builds---which is probably a bad idea for this option, since |
| 915 | always building extensions in-place would break installation of the |
| 916 | module distribution. In certain peculiar cases, though, modules are |
| 917 | built right in their installation directory, so this is conceivably a |
| 918 | useful ability. (Distributing extensions that expect to be built in |
| 919 | their installation directory is almost always a bad idea, though.) |
| 920 | |
| 921 | Another example: certain commands take a lot of options that don't |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 922 | change from run to run; for example, \command{bdist\_rpm} needs to know |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 923 | everything required to generate a ``spec'' file for creating an RPM |
| 924 | distribution. Some of this information comes from the setup script, and |
| 925 | some is automatically generated by the Distutils (such as the list of |
| 926 | files installed). But some of it has to be supplied as options to |
| 927 | \command{bdist\_rpm}, which would be very tedious to do on the |
| 928 | command-line for every run. Hence, here is a snippet from the |
| 929 | Distutils' own \file{setup.cfg}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 930 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 931 | \begin{verbatim} |
| 932 | [bdist_rpm] |
| 933 | release = 1 |
| 934 | packager = Greg Ward <gward@python.net> |
| 935 | doc_files = CHANGES.txt |
| 936 | README.txt |
| 937 | USAGE.txt |
| 938 | doc/ |
| 939 | examples/ |
| 940 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 941 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 942 | Note that the \option{doc\_files} option is simply a |
| 943 | whitespace-separated string split across multiple lines for readability. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 944 | |
| 945 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 946 | \begin{seealso} |
| 947 | \seetitle[../inst/config-syntax.html]{Installing Python |
| 948 | Modules}{More information on the configuration files is |
| 949 | available in the manual for system administrators.} |
| 950 | \end{seealso} |
| 951 | |
| 952 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 953 | \chapter{Creating a Source Distribution} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 954 | \label{source-dist} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 955 | |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 956 | As shown in section~\ref{simple-example}, you use the |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 957 | \command{sdist} command to create a source distribution. In the |
| 958 | simplest case, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 959 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 960 | \begin{verbatim} |
| 961 | python setup.py sdist |
| 962 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 963 | |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 964 | (assuming you haven't specified any \command{sdist} options in the setup |
| 965 | script or config file), \command{sdist} creates the archive of the |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 966 | default format for the current platform. The default format is a gzip'ed |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 967 | tar file (\file{.tar.gz}) on \UNIX, and ZIP file on Windows. |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 968 | \XXX{no Mac OS support here} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 969 | |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 970 | You can specify as many formats as you like using the |
| 971 | \longprogramopt{formats} option, for example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 972 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 973 | \begin{verbatim} |
| 974 | python setup.py sdist --formats=gztar,zip |
| 975 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 976 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 977 | to create a gzipped tarball and a zip file. The available formats are: |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 978 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 979 | \begin{tableiii}{l|l|c}{code}% |
| 980 | {Format}{Description}{Notes} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 981 | \lineiii{zip}{zip file (\file{.zip})}{(1),(3)} |
| 982 | \lineiii{gztar}{gzip'ed tar file (\file{.tar.gz})}{(2),(4)} |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 983 | \lineiii{bztar}{bzip2'ed tar file (\file{.tar.bz2})}{(4)} |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 984 | \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(4)} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 985 | \lineiii{tar}{tar file (\file{.tar})}{(4)} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 986 | \end{tableiii} |
| 987 | |
| 988 | \noindent Notes: |
| 989 | \begin{description} |
| 990 | \item[(1)] default on Windows |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 991 | \item[(2)] default on \UNIX |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 992 | \item[(3)] requires either external \program{zip} utility or |
Greg Ward | 954ce8b | 2002-05-10 14:42:10 +0000 | [diff] [blame] | 993 | \module{zipfile} module (part of the standard Python library since |
| 994 | Python~1.6) |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 995 | \item[(4)] requires external utilities: \program{tar} and possibly one |
| 996 | of \program{gzip}, \program{bzip2}, or \program{compress} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 997 | \end{description} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 998 | |
| 999 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1000 | |
| 1001 | \subsection{Specifying the files to distribute} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1002 | \label{manifest} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1003 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1004 | If you don't supply an explicit list of files (or instructions on how to |
| 1005 | generate one), the \command{sdist} command puts a minimal default set |
| 1006 | into the source distribution: |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1007 | \begin{itemize} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1008 | \item all Python source files implied by the \option{py\_modules} and |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1009 | \option{packages} options |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1010 | \item all C source files mentioned in the \option{ext\_modules} or |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1011 | \option{libraries} options (\XXX{getting C library sources currently |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1012 | broken---no \method{get_source_files()} method in \file{build_clib.py}!}) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1013 | \item anything that looks like a test script: \file{test/test*.py} |
| 1014 | (currently, the Distutils don't do anything with test scripts except |
| 1015 | include them in source distributions, but in the future there will be |
| 1016 | a standard for testing Python module distributions) |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1017 | \item \file{README.txt} (or \file{README}), \file{setup.py} (or whatever |
| 1018 | you called your setup script), and \file{setup.cfg} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1019 | \end{itemize} |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1020 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1021 | Sometimes this is enough, but usually you will want to specify |
| 1022 | additional files to distribute. The typical way to do this is to write |
| 1023 | a \emph{manifest template}, called \file{MANIFEST.in} by default. The |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1024 | manifest template is just a list of instructions for how to generate |
| 1025 | your manifest file, \file{MANIFEST}, which is the exact list of files to |
| 1026 | include in your source distribution. The \command{sdist} command |
| 1027 | processes this template and generates a manifest based on its |
| 1028 | instructions and what it finds in the filesystem. |
| 1029 | |
| 1030 | If you prefer to roll your own manifest file, the format is simple: one |
| 1031 | filename per line, regular files (or symlinks to them) only. If you do |
| 1032 | supply your own \file{MANIFEST}, you must specify everything: the |
| 1033 | default set of files described above does not apply in this case. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1034 | |
| 1035 | The manifest template has one command per line, where each command |
| 1036 | specifies a set of files to include or exclude from the source |
| 1037 | distribution. For an example, again we turn to the Distutils' own |
| 1038 | manifest template: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1039 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1040 | \begin{verbatim} |
| 1041 | include *.txt |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1042 | recursive-include examples *.txt *.py |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1043 | prune examples/sample?/build |
| 1044 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1045 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1046 | The meanings should be fairly clear: include all files in the |
| 1047 | distribution root matching \code{*.txt}, all files anywhere under the |
| 1048 | \file{examples} directory matching \code{*.txt} or \code{*.py}, and |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1049 | exclude all directories matching \code{examples/sample?/build}. All of |
| 1050 | this is done \emph{after} the standard include set, so you can exclude |
| 1051 | files from the standard set with explicit instructions in the manifest |
| 1052 | template. (Or, you can use the \longprogramopt{no-defaults} option to |
| 1053 | disable the standard set entirely.) There are several other commands |
| 1054 | available in the manifest template mini-language; see |
| 1055 | section~\ref{sdist-cmd}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1056 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1057 | The order of commands in the manifest template matters: initially, we |
| 1058 | have the list of default files as described above, and each command in |
| 1059 | the template adds to or removes from that list of files. Once we have |
| 1060 | fully processed the manifest template, we remove files that should not |
| 1061 | be included in the source distribution: |
| 1062 | \begin{itemize} |
| 1063 | \item all files in the Distutils ``build'' tree (default \file{build/}) |
| 1064 | \item all files in directories named \file{RCS} or \file{CVS} |
| 1065 | \end{itemize} |
| 1066 | Now we have our complete list of files, which is written to the manifest |
| 1067 | for future reference, and then used to build the source distribution |
| 1068 | archive(s). |
| 1069 | |
| 1070 | You can disable the default set of included files with the |
| 1071 | \longprogramopt{no-defaults} option, and you can disable the standard |
| 1072 | exclude set with \longprogramopt{no-prune}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1073 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1074 | Following the Distutils' own manifest template, let's trace how the |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 1075 | \command{sdist} command builds the list of files to include in the |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1076 | Distutils source distribution: |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1077 | \begin{enumerate} |
| 1078 | \item include all Python source files in the \file{distutils} and |
| 1079 | \file{distutils/command} subdirectories (because packages |
| 1080 | corresponding to those two directories were mentioned in the |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1081 | \option{packages} option in the setup script---see |
| 1082 | section~\ref{setup-script}) |
| 1083 | \item include \file{README.txt}, \file{setup.py}, and \file{setup.cfg} |
| 1084 | (standard files) |
| 1085 | \item include \file{test/test*.py} (standard files) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1086 | \item include \file{*.txt} in the distribution root (this will find |
| 1087 | \file{README.txt} a second time, but such redundancies are weeded out |
| 1088 | later) |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1089 | \item include anything matching \file{*.txt} or \file{*.py} in the |
| 1090 | sub-tree under \file{examples}, |
| 1091 | \item exclude all files in the sub-trees starting at directories |
| 1092 | matching \file{examples/sample?/build}---this may exclude files |
| 1093 | included by the previous two steps, so it's important that the |
| 1094 | \code{prune} command in the manifest template comes after the |
| 1095 | \code{recursive-include} command |
| 1096 | \item exclude the entire \file{build} tree, and any \file{RCS} or |
| 1097 | \file{CVS} directories |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1098 | \end{enumerate} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1099 | Just like in the setup script, file and directory names in the manifest |
| 1100 | template should always be slash-separated; the Distutils will take care |
| 1101 | of converting them to the standard representation on your platform. |
| 1102 | That way, the manifest template is portable across operating systems. |
| 1103 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1104 | |
| 1105 | \subsection{Manifest-related options} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1106 | \label{manifest-options} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1107 | |
| 1108 | The normal course of operations for the \command{sdist} command is as |
| 1109 | follows: |
| 1110 | \begin{itemize} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1111 | \item if the manifest file, \file{MANIFEST} doesn't exist, read |
| 1112 | \file{MANIFEST.in} and create the manifest |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1113 | \item if neither \file{MANIFEST} nor \file{MANIFEST.in} exist, create a |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1114 | manifest with just the default file set |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1115 | \item if either \file{MANIFEST.in} or the setup script (\file{setup.py}) |
| 1116 | are more recent than \file{MANIFEST}, recreate \file{MANIFEST} by |
| 1117 | reading \file{MANIFEST.in} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1118 | \item use the list of files now in \file{MANIFEST} (either just |
| 1119 | generated or read in) to create the source distribution archive(s) |
| 1120 | \end{itemize} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1121 | There are a couple of options that modify this behaviour. First, use |
| 1122 | the \longprogramopt{no-defaults} and \longprogramopt{no-prune} to |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1123 | disable the standard ``include'' and ``exclude'' sets. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1124 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1125 | Second, you might want to force the manifest to be regenerated---for |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1126 | example, if you have added or removed files or directories that match an |
| 1127 | existing pattern in the manifest template, you should regenerate the |
| 1128 | manifest: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1129 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1130 | \begin{verbatim} |
| 1131 | python setup.py sdist --force-manifest |
| 1132 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1133 | |
| 1134 | Or, you might just want to (re)generate the manifest, but not create a |
| 1135 | source distribution: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1136 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1137 | \begin{verbatim} |
| 1138 | python setup.py sdist --manifest-only |
| 1139 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1140 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1141 | \longprogramopt{manifest-only} implies \longprogramopt{force-manifest}. |
| 1142 | \programopt{-o} is a shortcut for \longprogramopt{manifest-only}, and |
| 1143 | \programopt{-f} for \longprogramopt{force-manifest}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1144 | |
| 1145 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1146 | \chapter{Creating Built Distributions} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1147 | \label{built-dist} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1148 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1149 | A ``built distribution'' is what you're probably used to thinking of |
| 1150 | either as a ``binary package'' or an ``installer'' (depending on your |
| 1151 | background). It's not necessarily binary, though, because it might |
| 1152 | contain only Python source code and/or byte-code; and we don't call it a |
| 1153 | package, because that word is already spoken for in Python. (And |
Fred Drake | 2a1bc50 | 2004-02-19 23:03:29 +0000 | [diff] [blame] | 1154 | ``installer'' is a term specific to the world of mainstream desktop |
| 1155 | systems.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1156 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1157 | A built distribution is how you make life as easy as possible for |
| 1158 | installers of your module distribution: for users of RPM-based Linux |
| 1159 | systems, it's a binary RPM; for Windows users, it's an executable |
| 1160 | installer; for Debian-based Linux users, it's a Debian package; and so |
| 1161 | forth. Obviously, no one person will be able to create built |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1162 | distributions for every platform under the sun, so the Distutils are |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1163 | designed to enable module developers to concentrate on their |
| 1164 | specialty---writing code and creating source distributions---while an |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1165 | intermediary species called \emph{packagers} springs up to turn source |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 1166 | distributions into built distributions for as many platforms as there |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1167 | are packagers. |
| 1168 | |
| 1169 | Of course, the module developer could be his own packager; or the |
| 1170 | packager could be a volunteer ``out there'' somewhere who has access to |
| 1171 | a platform which the original developer does not; or it could be |
| 1172 | software periodically grabbing new source distributions and turning them |
| 1173 | into built distributions for as many platforms as the software has |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1174 | access to. Regardless of who they are, a packager uses the |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1175 | setup script and the \command{bdist} command family to generate built |
| 1176 | distributions. |
| 1177 | |
| 1178 | As a simple example, if I run the following command in the Distutils |
| 1179 | source tree: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1180 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1181 | \begin{verbatim} |
| 1182 | python setup.py bdist |
| 1183 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1184 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1185 | then the Distutils builds my module distribution (the Distutils itself |
| 1186 | in this case), does a ``fake'' installation (also in the \file{build} |
| 1187 | directory), and creates the default type of built distribution for my |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1188 | platform. The default format for built distributions is a ``dumb'' tar |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1189 | file on \UNIX, and a simple executable installer on Windows. (That tar |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1190 | file is considered ``dumb'' because it has to be unpacked in a specific |
| 1191 | location to work.) |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1192 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1193 | Thus, the above command on a \UNIX{} system creates |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1194 | \file{Distutils-1.0.\filevar{plat}.tar.gz}; unpacking this tarball |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1195 | from the right place installs the Distutils just as though you had |
| 1196 | downloaded the source distribution and run \code{python setup.py |
| 1197 | install}. (The ``right place'' is either the root of the filesystem or |
| 1198 | Python's \filevar{prefix} directory, depending on the options given to |
| 1199 | the \command{bdist\_dumb} command; the default is to make dumb |
| 1200 | distributions relative to \filevar{prefix}.) |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1201 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1202 | Obviously, for pure Python distributions, this isn't any simpler than |
| 1203 | just running \code{python setup.py install}---but for non-pure |
| 1204 | distributions, which include extensions that would need to be |
| 1205 | compiled, it can mean the difference between someone being able to use |
| 1206 | your extensions or not. And creating ``smart'' built distributions, |
| 1207 | such as an RPM package or an executable installer for Windows, is far |
| 1208 | more convenient for users even if your distribution doesn't include |
| 1209 | any extensions. |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1210 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1211 | The \command{bdist} command has a \longprogramopt{formats} option, |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1212 | similar to the \command{sdist} command, which you can use to select the |
| 1213 | types of built distribution to generate: for example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1214 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1215 | \begin{verbatim} |
| 1216 | python setup.py bdist --format=zip |
| 1217 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1218 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1219 | would, when run on a \UNIX{} system, create |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1220 | \file{Distutils-1.0.\filevar{plat}.zip}---again, this archive would be |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1221 | unpacked from the root directory to install the Distutils. |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1222 | |
| 1223 | The available formats for built distributions are: |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1224 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1225 | \begin{tableiii}{l|l|c}{code}% |
| 1226 | {Format}{Description}{Notes} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1227 | \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1),(3)} |
| 1228 | \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(3)} |
| 1229 | \lineiii{tar}{tar file (\file{.tar})}{(3)} |
| 1230 | \lineiii{zip}{zip file (\file{.zip})}{(4)} |
| 1231 | \lineiii{rpm}{RPM}{(5)} |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1232 | \lineiii{pkgtool}{Solaris \program{pkgtool}}{} |
| 1233 | \lineiii{sdux}{HP-UX \program{swinstall}}{} |
| 1234 | \lineiii{rpm}{RPM}{(5)} |
| 1235 | % \lineiii{srpm}{source RPM}{(5) \XXX{to do!}} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1236 | \lineiii{wininst}{self-extracting ZIP file for Windows}{(2),(4)} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1237 | \end{tableiii} |
| 1238 | |
| 1239 | \noindent Notes: |
| 1240 | \begin{description} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1241 | \item[(1)] default on \UNIX |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1242 | \item[(2)] default on Windows \XXX{to-do!} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1243 | \item[(3)] requires external utilities: \program{tar} and possibly one |
| 1244 | of \program{gzip}, \program{bzip2}, or \program{compress} |
| 1245 | \item[(4)] requires either external \program{zip} utility or |
Greg Ward | 954ce8b | 2002-05-10 14:42:10 +0000 | [diff] [blame] | 1246 | \module{zipfile} module (part of the standard Python library since |
| 1247 | Python~1.6) |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1248 | \item[(5)] requires external \program{rpm} utility, version 3.0.4 or |
| 1249 | better (use \code{rpm --version} to find out which version you have) |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1250 | \end{description} |
| 1251 | |
| 1252 | You don't have to use the \command{bdist} command with the |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 1253 | \longprogramopt{formats} option; you can also use the command that |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1254 | directly implements the format you're interested in. Some of these |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1255 | \command{bdist} ``sub-commands'' actually generate several similar |
| 1256 | formats; for instance, the \command{bdist\_dumb} command generates all |
| 1257 | the ``dumb'' archive formats (\code{tar}, \code{ztar}, \code{gztar}, and |
| 1258 | \code{zip}), and \command{bdist\_rpm} generates both binary and source |
| 1259 | RPMs. The \command{bdist} sub-commands, and the formats generated by |
| 1260 | each, are: |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1261 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1262 | \begin{tableii}{l|l}{command}% |
| 1263 | {Command}{Formats} |
| 1264 | \lineii{bdist\_dumb}{tar, ztar, gztar, zip} |
| 1265 | \lineii{bdist\_rpm}{rpm, srpm} |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1266 | \lineii{bdist\_wininst}{wininst} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1267 | \end{tableii} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1268 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1269 | The following sections give details on the individual \command{bdist\_*} |
| 1270 | commands. |
| 1271 | |
| 1272 | |
| 1273 | \subsection{Creating dumb built distributions} |
| 1274 | \label{creating-dumb} |
| 1275 | |
| 1276 | \XXX{Need to document absolute vs. prefix-relative packages here, but |
| 1277 | first I have to implement it!} |
| 1278 | |
| 1279 | |
| 1280 | \subsection{Creating RPM packages} |
| 1281 | \label{creating-rpms} |
| 1282 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1283 | The RPM format is used by many popular Linux distributions, including |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1284 | Red Hat, SuSE, and Mandrake. If one of these (or any of the other |
| 1285 | RPM-based Linux distributions) is your usual environment, creating RPM |
| 1286 | packages for other users of that same distribution is trivial. |
| 1287 | Depending on the complexity of your module distribution and differences |
| 1288 | between Linux distributions, you may also be able to create RPMs that |
| 1289 | work on different RPM-based distributions. |
| 1290 | |
| 1291 | The usual way to create an RPM of your module distribution is to run the |
| 1292 | \command{bdist\_rpm} command: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1293 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1294 | \begin{verbatim} |
| 1295 | python setup.py bdist_rpm |
| 1296 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1297 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1298 | or the \command{bdist} command with the \longprogramopt{format} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1299 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1300 | \begin{verbatim} |
| 1301 | python setup.py bdist --formats=rpm |
| 1302 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1303 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1304 | The former allows you to specify RPM-specific options; the latter allows |
| 1305 | you to easily specify multiple formats in one run. If you need to do |
| 1306 | both, you can explicitly specify multiple \command{bdist\_*} commands |
| 1307 | and their options: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1308 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1309 | \begin{verbatim} |
| 1310 | python setup.py bdist_rpm --packager="John Doe <jdoe@python.net>" \ |
| 1311 | bdist_wininst --target_version="2.0" |
| 1312 | \end{verbatim} |
| 1313 | |
| 1314 | Creating RPM packages is driven by a \file{.spec} file, much as using |
| 1315 | the Distutils is driven by the setup script. To make your life easier, |
| 1316 | the \command{bdist\_rpm} command normally creates a \file{.spec} file |
| 1317 | based on the information you supply in the setup script, on the command |
| 1318 | line, and in any Distutils configuration files. Various options and |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 1319 | sections in the \file{.spec} file are derived from options in the setup |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1320 | script as follows: |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1321 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1322 | \begin{tableii}{l|l}{textrm}% |
| 1323 | {RPM \file{.spec} file option or section}{Distutils setup script option} |
| 1324 | \lineii{Name}{\option{name}} |
| 1325 | \lineii{Summary (in preamble)}{\option{description}} |
| 1326 | \lineii{Version}{\option{version}} |
| 1327 | \lineii{Vendor}{\option{author} and \option{author\_email}, or \\& |
| 1328 | \option{maintainer} and \option{maintainer\_email}} |
| 1329 | \lineii{Copyright}{\option{licence}} |
| 1330 | \lineii{Url}{\option{url}} |
| 1331 | \lineii{\%description (section)}{\option{long\_description}} |
| 1332 | \end{tableii} |
| 1333 | |
| 1334 | Additionally, there many options in \file{.spec} files that don't have |
| 1335 | corresponding options in the setup script. Most of these are handled |
| 1336 | through options to the \command{bdist\_rpm} command as follows: |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1337 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1338 | \begin{tableiii}{l|l|l}{textrm}% |
| 1339 | {RPM \file{.spec} file option or section}% |
| 1340 | {\command{bdist\_rpm} option}% |
| 1341 | {default value} |
| 1342 | \lineiii{Release}{\option{release}}{``1''} |
| 1343 | \lineiii{Group}{\option{group}}{``Development/Libraries''} |
| 1344 | \lineiii{Vendor}{\option{vendor}}{(see above)} |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 1345 | \lineiii{Packager}{\option{packager}}{(none)} |
| 1346 | \lineiii{Provides}{\option{provides}}{(none)} |
| 1347 | \lineiii{Requires}{\option{requires}}{(none)} |
| 1348 | \lineiii{Conflicts}{\option{conflicts}}{(none)} |
| 1349 | \lineiii{Obsoletes}{\option{obsoletes}}{(none)} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1350 | \lineiii{Distribution}{\option{distribution\_name}}{(none)} |
| 1351 | \lineiii{BuildRequires}{\option{build\_requires}}{(none)} |
| 1352 | \lineiii{Icon}{\option{icon}}{(none)} |
| 1353 | \end{tableiii} |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1354 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1355 | Obviously, supplying even a few of these options on the command-line |
| 1356 | would be tedious and error-prone, so it's usually best to put them in |
| 1357 | the setup configuration file, \file{setup.cfg}---see |
| 1358 | section~\ref{setup-config}. If you distribute or package many Python |
| 1359 | module distributions, you might want to put options that apply to all of |
| 1360 | them in your personal Distutils configuration file |
| 1361 | (\file{\textasciitilde/.pydistutils.cfg}). |
| 1362 | |
| 1363 | There are three steps to building a binary RPM package, all of which are |
| 1364 | handled automatically by the Distutils: |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1365 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1366 | \begin{enumerate} |
| 1367 | \item create a \file{.spec} file, which describes the package (analogous |
| 1368 | to the Distutils setup script; in fact, much of the information in the |
| 1369 | setup script winds up in the \file{.spec} file) |
| 1370 | \item create the source RPM |
| 1371 | \item create the ``binary'' RPM (which may or may not contain binary |
| 1372 | code, depending on whether your module distribution contains Python |
| 1373 | extensions) |
| 1374 | \end{enumerate} |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1375 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1376 | Normally, RPM bundles the last two steps together; when you use the |
| 1377 | Distutils, all three steps are typically bundled together. |
| 1378 | |
| 1379 | If you wish, you can separate these three steps. You can use the |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1380 | \longprogramopt{spec-only} option to make \command{bdist_rpm} just |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1381 | create the \file{.spec} file and exit; in this case, the \file{.spec} |
| 1382 | file will be written to the ``distribution directory''---normally |
| 1383 | \file{dist/}, but customizable with the \longprogramopt{dist-dir} |
| 1384 | option. (Normally, the \file{.spec} file winds up deep in the ``build |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1385 | tree,'' in a temporary directory created by \command{bdist_rpm}.) |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1386 | |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1387 | % \XXX{this isn't implemented yet---is it needed?!} |
| 1388 | % You can also specify a custom \file{.spec} file with the |
| 1389 | % \longprogramopt{spec-file} option; used in conjunction with |
| 1390 | % \longprogramopt{spec-only}, this gives you an opportunity to customize |
| 1391 | % the \file{.spec} file manually: |
| 1392 | % |
| 1393 | % \begin{verbatim} |
| 1394 | % > python setup.py bdist_rpm --spec-only |
| 1395 | % # ...edit dist/FooBar-1.0.spec |
| 1396 | % > python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec |
| 1397 | % \end{verbatim} |
| 1398 | % |
| 1399 | % (Although a better way to do this is probably to override the standard |
| 1400 | % \command{bdist\_rpm} command with one that writes whatever else you want |
| 1401 | % to the \file{.spec} file.) |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1402 | |
| 1403 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1404 | \subsection{Creating Windows Installers} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1405 | \label{creating-wininst} |
| 1406 | |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1407 | Executable installers are the natural format for binary distributions |
| 1408 | on Windows. They display a nice graphical user interface, display |
| 1409 | some information about the module distribution to be installed taken |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 1410 | from the metadata in the setup script, let the user select a few |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1411 | options, and start or cancel the installation. |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1412 | |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1413 | Since the metadata is taken from the setup script, creating Windows |
| 1414 | installers is usually as easy as running: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1415 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1416 | \begin{verbatim} |
| 1417 | python setup.py bdist_wininst |
| 1418 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1419 | |
Thomas Heller | 36343f6 | 2002-11-15 19:20:56 +0000 | [diff] [blame] | 1420 | or the \command{bdist} command with the \longprogramopt{formats} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1421 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1422 | \begin{verbatim} |
| 1423 | python setup.py bdist --formats=wininst |
| 1424 | \end{verbatim} |
| 1425 | |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1426 | If you have a pure module distribution (only containing pure Python |
| 1427 | modules and packages), the resulting installer will be version |
| 1428 | independent and have a name like \file{foo-1.0.win32.exe}. These |
Fred Drake | c54d925 | 2004-02-19 22:16:05 +0000 | [diff] [blame] | 1429 | installers can even be created on \UNIX{} or Mac OS platforms. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1430 | |
| 1431 | If you have a non-pure distribution, the extensions can only be |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1432 | created on a Windows platform, and will be Python version dependent. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1433 | The installer filename will reflect this and now has the form |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1434 | \file{foo-1.0.win32-py2.0.exe}. You have to create a separate installer |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1435 | for every Python version you want to support. |
| 1436 | |
| 1437 | The installer will try to compile pure modules into bytecode after |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1438 | installation on the target system in normal and optimizing mode. If |
| 1439 | you don't want this to happen for some reason, you can run the |
Fred Drake | 0e9bfa3 | 2002-11-15 20:34:52 +0000 | [diff] [blame] | 1440 | \command{bdist_wininst} command with the |
| 1441 | \longprogramopt{no-target-compile} and/or the |
| 1442 | \longprogramopt{no-target-optimize} option. |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1443 | |
Fred Drake | 0e9bfa3 | 2002-11-15 20:34:52 +0000 | [diff] [blame] | 1444 | By default the installer will display the cool ``Python Powered'' logo |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1445 | when it is run, but you can also supply your own bitmap which must be |
Fred Drake | 0e9bfa3 | 2002-11-15 20:34:52 +0000 | [diff] [blame] | 1446 | a Windows \file{.bmp} file with the \longprogramopt{bitmap} option. |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1447 | |
| 1448 | The installer will also display a large title on the desktop |
| 1449 | background window when it is run, which is constructed from the name |
| 1450 | of your distribution and the version number. This can be changed to |
| 1451 | another text by using the \longprogramopt{title} option. |
| 1452 | |
| 1453 | The installer file will be written to the ``distribution directory'' |
| 1454 | --- normally \file{dist/}, but customizable with the |
| 1455 | \longprogramopt{dist-dir} option. |
| 1456 | |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1457 | \subsubsection{The Postinstallation script} |
| 1458 | \label{postinstallation-script} |
| 1459 | |
| 1460 | Starting with Python 2.3, a postinstallation script can be specified |
| 1461 | which the \longprogramopt{install-script} option. The basename of the |
| 1462 | script must be specified, and the script filename must also be listed |
| 1463 | in the scripts argument to the setup function. |
| 1464 | |
| 1465 | This script will be run at installation time on the target system |
Fred Drake | c54d925 | 2004-02-19 22:16:05 +0000 | [diff] [blame] | 1466 | after all the files have been copied, with \code{argv[1]} set to |
| 1467 | \programopt{-install}, and again at uninstallation time before the |
| 1468 | files are removed with \code{argv[1]} set to \programopt{-remove}. |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1469 | |
| 1470 | The installation script runs embedded in the windows installer, every |
Fred Drake | c54d925 | 2004-02-19 22:16:05 +0000 | [diff] [blame] | 1471 | output (\code{sys.stdout}, \code{sys.stderr}) is redirected into a |
| 1472 | buffer and will be displayed in the GUI after the script has finished. |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1473 | |
Fred Drake | a9ee0da | 2004-02-19 22:28:15 +0000 | [diff] [blame] | 1474 | Some functions especially useful in this context are available as |
| 1475 | additional built-in functions in the installation script. |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1476 | |
Fred Drake | a9ee0da | 2004-02-19 22:28:15 +0000 | [diff] [blame] | 1477 | \begin{funcdesc}{directory_created}{path} |
| 1478 | \funcline{file_created}{path} |
| 1479 | These functions should be called when a directory or file is created |
| 1480 | by the postinstall script at installation time. It will register |
| 1481 | \var{path} with the uninstaller, so that it will be removed when the |
| 1482 | distribution is uninstalled. To be safe, directories are only removed |
| 1483 | if they are empty. |
| 1484 | \end{funcdesc} |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1485 | |
Fred Drake | a9ee0da | 2004-02-19 22:28:15 +0000 | [diff] [blame] | 1486 | \begin{funcdesc}{get_special_folder_path}{csidl_string} |
| 1487 | This function can be used to retrieve special folder locations on |
| 1488 | Windows like the Start Menu or the Desktop. It returns the full |
| 1489 | path to the folder. \var{csidl_string} must be one of the following |
| 1490 | strings: |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1491 | |
| 1492 | \begin{verbatim} |
| 1493 | "CSIDL_APPDATA" |
| 1494 | |
| 1495 | "CSIDL_COMMON_STARTMENU" |
| 1496 | "CSIDL_STARTMENU" |
| 1497 | |
| 1498 | "CSIDL_COMMON_DESKTOPDIRECTORY" |
| 1499 | "CSIDL_DESKTOPDIRECTORY" |
| 1500 | |
| 1501 | "CSIDL_COMMON_STARTUP" |
| 1502 | "CSIDL_STARTUP" |
| 1503 | |
| 1504 | "CSIDL_COMMON_PROGRAMS" |
| 1505 | "CSIDL_PROGRAMS" |
| 1506 | |
| 1507 | "CSIDL_FONTS" |
| 1508 | \end{verbatim} |
| 1509 | |
Fred Drake | a9ee0da | 2004-02-19 22:28:15 +0000 | [diff] [blame] | 1510 | If the folder cannot be retrieved, \exception{OSError} is raised. |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1511 | |
Fred Drake | a9ee0da | 2004-02-19 22:28:15 +0000 | [diff] [blame] | 1512 | Which folders are available depends on the exact Windows version, |
| 1513 | and probably also the configuration. For details refer to |
| 1514 | Microsoft's documentation of the |
| 1515 | \cfunction{SHGetSpecialFolderPath()} function. |
| 1516 | \end{funcdesc} |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1517 | |
Fred Drake | a9ee0da | 2004-02-19 22:28:15 +0000 | [diff] [blame] | 1518 | \begin{funcdesc}{create_shortcut}{target, description, |
| 1519 | filename\optional{, |
| 1520 | arguments\optional{, |
| 1521 | workdir\optional{, |
| 1522 | iconpath\optional{, iconindex}}}}} |
| 1523 | This function creates a shortcut. |
| 1524 | \var{target} is the path to the program to be started by the shortcut. |
| 1525 | \var{description} is the description of the sortcut. |
| 1526 | \var{filename} is the title of the shortcut that the user will see. |
| 1527 | \var{arguments} specifies the command line arguments, if any. |
| 1528 | \var{workdir} is the working directory for the program. |
| 1529 | \var{iconpath} is the file containing the icon for the shortcut, |
| 1530 | and \var{iconindex} is the index of the icon in the file |
| 1531 | \var{iconpath}. Again, for details consult the Microsoft |
| 1532 | documentation for the \class{IShellLink} interface. |
| 1533 | \end{funcdesc} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1534 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1535 | \chapter{Registering with the Package Index} |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 1536 | \label{package-index} |
| 1537 | |
| 1538 | The Python Package Index (PyPI) holds meta-data describing distributions |
| 1539 | packaged with distutils. The distutils command \command{register} is |
| 1540 | used to submit your distribution's meta-data to the index. It is invoked |
| 1541 | as follows: |
| 1542 | |
| 1543 | \begin{verbatim} |
| 1544 | python setup.py register |
| 1545 | \end{verbatim} |
| 1546 | |
| 1547 | Distutils will respond with the following prompt: |
| 1548 | |
| 1549 | \begin{verbatim} |
| 1550 | running register |
| 1551 | We need to know who you are, so please choose either: |
| 1552 | 1. use your existing login, |
| 1553 | 2. register as a new user, |
| 1554 | 3. have the server generate a new password for you (and email it to you), or |
| 1555 | 4. quit |
| 1556 | Your selection [default 1]: |
| 1557 | \end{verbatim} |
| 1558 | |
| 1559 | \noindent Note: if your username and password are saved locally, you will |
| 1560 | not see this menu. |
| 1561 | |
| 1562 | If you have not registered with PyPI, then you will need to do so now. You |
| 1563 | should choose option 2, and enter your details as required. Soon after |
| 1564 | submitting your details, you will receive an email which will be used to |
| 1565 | confirm your registration. |
| 1566 | |
| 1567 | Once you are registered, you may choose option 1 from the menu. You will |
| 1568 | be prompted for your PyPI username and password, and \command{register} |
| 1569 | will then submit your meta-data to the index. |
| 1570 | |
| 1571 | You may submit any number of versions of your distribution to the index. If |
| 1572 | you alter the meta-data for a particular version, you may submit it again |
| 1573 | and the index will be updated. |
| 1574 | |
| 1575 | PyPI holds a record for each (name, version) combination submitted. The |
| 1576 | first user to submit information for a given name is designated the Owner |
| 1577 | of that name. They may submit changes through the \command{register} |
| 1578 | command or through the web interface. They may also designate other users |
| 1579 | as Owners or Maintainers. Maintainers may edit the package information, but |
| 1580 | not designate other Owners or Maintainers. |
| 1581 | |
| 1582 | By default PyPI will list all versions of a given package. To hide certain |
| 1583 | versions, the Hidden property should be set to yes. This must be edited |
| 1584 | through the web interface. |
| 1585 | |
| 1586 | |
| 1587 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1588 | \chapter{Examples} |
Greg Ward | 007c04a | 2002-05-10 14:45:59 +0000 | [diff] [blame] | 1589 | \label{examples} |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 1590 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1591 | \section{Pure Python distribution (by module)} |
Greg Ward | 007c04a | 2002-05-10 14:45:59 +0000 | [diff] [blame] | 1592 | \label{pure-mod} |
| 1593 | |
| 1594 | If you're just distributing a couple of modules, especially if they |
| 1595 | don't live in a particular package, you can specify them individually |
| 1596 | using the \option{py\_modules} option in the setup script. |
| 1597 | |
| 1598 | In the simplest case, you'll have two files to worry about: a setup |
| 1599 | script and the single module you're distributing, \file{foo.py} in this |
| 1600 | example: |
| 1601 | \begin{verbatim} |
| 1602 | <root>/ |
| 1603 | setup.py |
| 1604 | foo.py |
| 1605 | \end{verbatim} |
| 1606 | (In all diagrams in this section, \verb|<root>| will refer to the |
| 1607 | distribution root directory.) A minimal setup script to describe this |
| 1608 | situation would be: |
| 1609 | \begin{verbatim} |
| 1610 | from distutils.core import setup |
| 1611 | setup(name = "foo", version = "1.0", |
| 1612 | py_modules = ["foo"]) |
| 1613 | \end{verbatim} |
| 1614 | Note that the name of the distribution is specified independently with |
| 1615 | the \option{name} option, and there's no rule that says it has to be the |
| 1616 | same as the name of the sole module in the distribution (although that's |
| 1617 | probably a good convention to follow). However, the distribution name |
| 1618 | is used to generate filenames, so you should stick to letters, digits, |
| 1619 | underscores, and hyphens. |
| 1620 | |
| 1621 | Since \option{py\_modules} is a list, you can of course specify multiple |
| 1622 | modules, eg. if you're distributing modules \module{foo} and |
| 1623 | \module{bar}, your setup might look like this: |
| 1624 | \begin{verbatim} |
| 1625 | <root>/ |
| 1626 | setup.py |
| 1627 | foo.py |
| 1628 | bar.py |
| 1629 | \end{verbatim} |
| 1630 | and the setup script might be |
| 1631 | \begin{verbatim} |
| 1632 | from distutils.core import setup |
| 1633 | setup(name = "foobar", version = "1.0", |
| 1634 | py_modules = ["foo", "bar"]) |
| 1635 | \end{verbatim} |
| 1636 | |
| 1637 | You can put module source files into another directory, but if you have |
| 1638 | enough modules to do that, it's probably easier to specify modules by |
| 1639 | package rather than listing them individually. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1640 | |
| 1641 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1642 | \section{Pure Python distribution (by package)} |
Greg Ward | 007c04a | 2002-05-10 14:45:59 +0000 | [diff] [blame] | 1643 | \label{pure-pkg} |
| 1644 | |
| 1645 | If you have more than a couple of modules to distribute, especially if |
| 1646 | they are in multiple packages, it's probably easier to specify whole |
| 1647 | packages rather than individual modules. This works even if your |
| 1648 | modules are not in a package; you can just tell the Distutils to process |
| 1649 | modules from the root package, and that works the same as any other |
| 1650 | package (except that you don't have to have an \file{\_\_init\_\_.py} |
| 1651 | file). |
| 1652 | |
| 1653 | The setup script from the last example could also be written as |
| 1654 | \begin{verbatim} |
| 1655 | from distutils.core import setup |
| 1656 | setup(name = "foobar", version = "1.0", |
| 1657 | packages = [""]) |
| 1658 | \end{verbatim} |
| 1659 | (The empty string stands for the root package.) |
| 1660 | |
| 1661 | If those two files are moved into a subdirectory, but remain in the root |
| 1662 | package, e.g.: |
| 1663 | \begin{verbatim} |
| 1664 | <root>/ |
| 1665 | setup.py |
| 1666 | src/ foo.py |
| 1667 | bar.py |
| 1668 | \end{verbatim} |
| 1669 | then you would still specify the root package, but you have to tell the |
| 1670 | Distutils where source files in the root package live: |
| 1671 | \begin{verbatim} |
| 1672 | from distutils.core import setup |
| 1673 | setup(name = "foobar", version = "1.0", |
| 1674 | package_dir = {"": "src"}, |
| 1675 | packages = [""]) |
| 1676 | \end{verbatim} |
| 1677 | |
| 1678 | More typically, though, you will want to distribute multiple modules in |
| 1679 | the same package (or in sub-packages). For example, if the \module{foo} |
| 1680 | and \module{bar} modules belong in package \module{foobar}, one way to |
| 1681 | layout your source tree is |
| 1682 | \begin{verbatim} |
| 1683 | <root>/ |
| 1684 | setup.py |
| 1685 | foobar/ |
| 1686 | __init__.py |
| 1687 | foo.py |
| 1688 | bar.py |
| 1689 | \end{verbatim} |
| 1690 | This is in fact the default layout expected by the Distutils, and the |
| 1691 | one that requires the least work to describe in your setup script: |
| 1692 | \begin{verbatim} |
| 1693 | from distutils.core import setup |
| 1694 | setup(name = "foobar", version = "1.0", |
| 1695 | packages = ["foobar"]) |
| 1696 | \end{verbatim} |
| 1697 | |
| 1698 | If you want to put modules in directories not named for their package, |
| 1699 | then you need to use the \option{package\_dir} option again. For |
| 1700 | example, if the \file{src} directory holds modules in the |
| 1701 | \module{foobar} package: |
| 1702 | \begin{verbatim} |
| 1703 | <root>/ |
| 1704 | setup.py |
| 1705 | src/ |
| 1706 | __init__.py |
| 1707 | foo.py |
| 1708 | bar.py |
| 1709 | \end{verbatim} |
| 1710 | an appropriate setup script would be |
| 1711 | \begin{verbatim} |
| 1712 | from distutils.core import setup |
| 1713 | setup(name = "foobar", version = "1.0", |
| 1714 | package_dir = {"foobar" : "src"}, |
| 1715 | packages = ["foobar"]) |
| 1716 | \end{verbatim} |
| 1717 | |
| 1718 | Or, you might put modules from your main package right in the |
| 1719 | distribution root: |
| 1720 | \begin{verbatim} |
| 1721 | <root>/ |
| 1722 | setup.py |
| 1723 | __init__.py |
| 1724 | foo.py |
| 1725 | bar.py |
| 1726 | \end{verbatim} |
| 1727 | in which case your setup script would be |
| 1728 | \begin{verbatim} |
| 1729 | from distutils.core import setup |
| 1730 | setup(name = "foobar", version = "1.0", |
| 1731 | package_dir = {"foobar" : ""}, |
| 1732 | packages = ["foobar"]) |
| 1733 | \end{verbatim} |
| 1734 | (The empty string also stands for the current directory.) |
| 1735 | |
| 1736 | If you have sub-packages, they must be explicitly listed in |
| 1737 | \option{packages}, but any entries in \option{package\_dir} |
| 1738 | automatically extend to sub-packages. (In other words, the Distutils |
| 1739 | does \emph{not} scan your source tree, trying to figure out which |
| 1740 | directories correspond to Python packages by looking for |
| 1741 | \file{\_\_init\_\_.py} files.) Thus, if the default layout grows a |
| 1742 | sub-package: |
| 1743 | \begin{verbatim} |
| 1744 | <root>/ |
| 1745 | setup.py |
| 1746 | foobar/ |
| 1747 | __init__.py |
| 1748 | foo.py |
| 1749 | bar.py |
| 1750 | subfoo/ |
| 1751 | __init__.py |
| 1752 | blah.py |
| 1753 | \end{verbatim} |
| 1754 | then the corresponding setup script would be |
| 1755 | \begin{verbatim} |
| 1756 | from distutils.core import setup |
| 1757 | setup(name = "foobar", version = "1.0", |
| 1758 | packages = ["foobar", "foobar.subfoo"]) |
| 1759 | \end{verbatim} |
| 1760 | (Again, the empty string in \option{package\_dir} stands for the current |
| 1761 | directory.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1762 | |
| 1763 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1764 | \section{Single extension module} |
Greg Ward | 007c04a | 2002-05-10 14:45:59 +0000 | [diff] [blame] | 1765 | \label{single-ext} |
| 1766 | |
| 1767 | Extension modules are specified using the \option{ext\_modules} option. |
| 1768 | \option{package\_dir} has no effect on where extension source files are |
| 1769 | found; it only affects the source for pure Python modules. The simplest |
| 1770 | case, a single extension module in a single C source file, is: |
| 1771 | \begin{verbatim} |
| 1772 | <root>/ |
| 1773 | setup.py |
| 1774 | foo.c |
| 1775 | \end{verbatim} |
| 1776 | If the \module{foo} extension belongs in the root package, the setup |
| 1777 | script for this could be |
| 1778 | \begin{verbatim} |
| 1779 | from distutils.core import setup |
| 1780 | setup(name = "foobar", version = "1.0", |
| 1781 | ext_modules = [Extension("foo", ["foo.c"])]) |
| 1782 | \end{verbatim} |
| 1783 | |
| 1784 | If the extension actually belongs in a package, say \module{foopkg}, |
| 1785 | then |
| 1786 | |
| 1787 | With exactly the same source tree layout, this extension can be put in |
| 1788 | the \module{foopkg} package simply by changing the name of the |
| 1789 | extension: |
| 1790 | \begin{verbatim} |
| 1791 | from distutils.core import setup |
| 1792 | setup(name = "foobar", version = "1.0", |
| 1793 | ext_modules = [Extension("foopkg.foo", ["foo.c"])]) |
| 1794 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1795 | |
| 1796 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1797 | %\section{Multiple extension modules} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1798 | %\label{multiple-ext} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1799 | |
| 1800 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1801 | %\section{Putting it all together} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1802 | |
| 1803 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1804 | %\chapter{Extending the Distutils} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1805 | %\label{extending} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1806 | |
| 1807 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1808 | %\section{Extending existing commands} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1809 | %\label{extend-existing} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1810 | |
| 1811 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1812 | %\section{Writing new commands} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1813 | %\label{new-commands} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1814 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1815 | %\XXX{Would an uninstall command be a good example here?} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1816 | |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1817 | |
| 1818 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1819 | \chapter{Command Reference} |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 1820 | \label{reference} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1821 | |
| 1822 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1823 | %\subsection{Building modules: the \protect\command{build} command family} |
| 1824 | %\label{build-cmds} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1825 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1826 | %\subsubsection{\protect\command{build}} |
| 1827 | %\label{build-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1828 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1829 | %\subsubsection{\protect\command{build\_py}} |
| 1830 | %\label{build-py-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1831 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1832 | %\subsubsection{\protect\command{build\_ext}} |
| 1833 | %\label{build-ext-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1834 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1835 | %\subsubsection{\protect\command{build\_clib}} |
| 1836 | %\label{build-clib-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1837 | |
| 1838 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1839 | \section{Installing modules: the \protect\command{install} command family} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1840 | \label{install-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1841 | |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1842 | The install command ensures that the build commands have been run and then |
| 1843 | runs the subcommands \command{install\_lib}, |
| 1844 | \command{install\_data} and |
| 1845 | \command{install\_scripts}. |
| 1846 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1847 | %\subsubsection{\protect\command{install\_lib}} |
| 1848 | %\label{install-lib-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1849 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1850 | \subsection{\protect\command{install\_data}} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 1851 | \label{install-data-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1852 | This command installs all data files provided with the distribution. |
| 1853 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1854 | \subsection{\protect\command{install\_scripts}} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 1855 | \label{install-scripts-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1856 | This command installs all (Python) scripts in the distribution. |
| 1857 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1858 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1859 | %\subsection{Cleaning up: the \protect\command{clean} command} |
| 1860 | %\label{clean-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1861 | |
| 1862 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1863 | \section{Creating a source distribution: the |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1864 | \protect\command{sdist} command} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1865 | \label{sdist-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1866 | |
| 1867 | |
| 1868 | \XXX{fragment moved down from above: needs context!} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1869 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1870 | The manifest template commands are: |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1871 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1872 | \begin{tableii}{ll}{command}{Command}{Description} |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1873 | \lineii{include \var{pat1} \var{pat2} ... } |
| 1874 | {include all files matching any of the listed patterns} |
| 1875 | \lineii{exclude \var{pat1} \var{pat2} ... } |
| 1876 | {exclude all files matching any of the listed patterns} |
| 1877 | \lineii{recursive-include \var{dir} \var{pat1} \var{pat2} ... } |
| 1878 | {include all files under \var{dir} matching any of the listed patterns} |
| 1879 | \lineii{recursive-exclude \var{dir} \var{pat1} \var{pat2} ...} |
| 1880 | {exclude all files under \var{dir} matching any of the listed patterns} |
| 1881 | \lineii{global-include \var{pat1} \var{pat2} ...} |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 1882 | {include all files anywhere in the source tree matching\\& |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1883 | any of the listed patterns} |
| 1884 | \lineii{global-exclude \var{pat1} \var{pat2} ...} |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 1885 | {exclude all files anywhere in the source tree matching\\& |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1886 | any of the listed patterns} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1887 | \lineii{prune \var{dir}}{exclude all files under \var{dir}} |
| 1888 | \lineii{graft \var{dir}}{include all files under \var{dir}} |
| 1889 | \end{tableii} |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1890 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1891 | The patterns here are \UNIX-style ``glob'' patterns: \code{*} matches any |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1892 | sequence of regular filename characters, \code{?} matches any single |
| 1893 | regular filename character, and \code{[\var{range}]} matches any of the |
| 1894 | characters in \var{range} (e.g., \code{a-z}, \code{a-zA-Z}, |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1895 | \code{a-f0-9\_.}). The definition of ``regular filename character'' is |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1896 | platform-specific: on \UNIX{} it is anything except slash; on Windows |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1897 | anything except backslash or colon; on Mac OS anything except colon. |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1898 | |
Fred Drake | 781380c | 2004-02-19 23:17:46 +0000 | [diff] [blame] | 1899 | \XXX{Windows and Mac OS support not there yet} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1900 | |
| 1901 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1902 | %\section{Creating a built distribution: the |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1903 | % \protect\command{bdist} command family} |
| 1904 | %\label{bdist-cmds} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1905 | |
| 1906 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1907 | %\subsection{\protect\command{bdist}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1908 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1909 | %\subsection{\protect\command{bdist\_dumb}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1910 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1911 | %\subsection{\protect\command{bdist\_rpm}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1912 | |
Fred Drake | 211a2eb | 2004-03-22 21:44:43 +0000 | [diff] [blame] | 1913 | %\subsection{\protect\command{bdist\_wininst}} |
Fred Drake | ab70b38 | 2001-08-02 15:13:15 +0000 | [diff] [blame] | 1914 | |
| 1915 | |
Fred Drake | 6fca7cc | 2004-03-23 18:43:03 +0000 | [diff] [blame^] | 1916 | \chapter{API Reference \label{api-reference}} |
| 1917 | |
| 1918 | \section{\module{distutils.core} --- Core Distutils functionality} |
| 1919 | |
| 1920 | \declaremodule{standard}{distutils.core} |
| 1921 | \modulesynopsis{The core Distutils functionality} |
| 1922 | |
| 1923 | The \module{distutils.core} module is the only module that needs to be |
| 1924 | installed to use the Distutils. It provides the \function{setup()} (which |
| 1925 | is called from the setup script). Indirectly provides the |
| 1926 | \class{distutils.dist.Distribution} and \class{distutils.cmd.Command} class. |
| 1927 | |
| 1928 | \begin{funcdesc}{setup}{arguments} |
| 1929 | The basic do-everything function that does most everything you could ever |
| 1930 | ask for from a Distutils method. See XXXXX |
| 1931 | |
| 1932 | The setup function takes a large number of arguments. These |
| 1933 | are laid out in the following table. |
| 1934 | |
| 1935 | \begin{tableiii}{c|l|l}{argument name}{argument name}{value}{type} |
| 1936 | \lineiii{name}{The name of the package}{a string} |
| 1937 | \lineiii{version}{The version number of the package}{See \refmodule{distutils.version}} |
| 1938 | \lineiii{description}{A single line describing the package}{a string} |
| 1939 | \lineiii{long_description}{Longer description of the package}{a string} |
| 1940 | \lineiii{author}{The name of the package author}{a string} |
| 1941 | \lineiii{author_email}{The email address of the package author}{a string} |
| 1942 | \lineiii{maintainer}{The name of the current maintainer, if different from the author}{a string} |
| 1943 | \lineiii{maintainer_email}{The email address of the current maintainer, if different from the author}{} |
| 1944 | \lineiii{url}{A URL for the package (homepage)}{a URL} |
| 1945 | \lineiii{download_url}{A URL to download the package}{a URL} |
| 1946 | \lineiii{packages}{A list of Python packages that distutils will manipulate}{a list of strings} |
| 1947 | \lineiii{py_modules}{A list of Python modules that distutils will manipulate}{a list of strings} |
| 1948 | \lineiii{scripts}{A list of standalone script files to be built and installed}{a list of strings} |
| 1949 | \lineiii{ext_modules}{A list of Python extensions to be built}{A list of |
| 1950 | instances of \class{distutils.core.Extension}} |
| 1951 | \lineiii{classifiers}{A list of Trove categories for the package}{XXX link to better definition} |
| 1952 | \lineiii{distclass}{the \class{Distribution} class to use}{A subclass of \class{distutils.core.Distribution}} |
| 1953 | % What on earth is the use case for script_name? |
| 1954 | \lineiii{script_name}{The name of the setup.py script - defaults to \code{sys.argv[0]}}{a string} |
| 1955 | \lineiii{script_args}{Arguments to supply to the setup script}{a list of strings} |
| 1956 | \lineiii{options}{default options for the setup script}{a string} |
| 1957 | \lineiii{license}{The license for the package}{} |
| 1958 | \lineiii{keywords}{Descriptive meta-data. See \pep{314}}{} |
| 1959 | \lineiii{platforms}{}{} |
| 1960 | \lineiii{cmdclass}{A mapping of command names to \class{Command} subclasses}{a dictionary} |
| 1961 | \end{tableiii} |
| 1962 | |
| 1963 | \end{funcdesc} |
| 1964 | |
| 1965 | \begin{funcdesc}{run_setup}{script_name\optional{, script_args=\code{None}, stop_after=\code{'run'}}} |
| 1966 | Run a setup script in a somewhat controlled environment, and return |
| 1967 | the \class{distutils.dist.Distribution} instance that drives things. |
| 1968 | This is useful if you need to find out the distribution meta-data |
| 1969 | (passed as keyword args from \var{script} to \function{setup()}), or |
| 1970 | the contents of the config files or command-line. |
| 1971 | |
| 1972 | \var{script_name} is a file that will be run with \function{execfile()} |
| 1973 | \var{sys.argv[0]} will be replaced with \var{script} for the duration of the |
| 1974 | call. \var{script_args} is a list of strings; if supplied, |
| 1975 | \var{sys.argv[1:]} will be replaced by \var{script_args} for the duration |
| 1976 | of the call. |
| 1977 | |
| 1978 | \var{stop_after} tells \function{setup()} when to stop processing; possible |
| 1979 | values: |
| 1980 | |
| 1981 | \begin{tableii}{c|l}{value}{value}{description} |
| 1982 | \lineii{init}{Stop after the \class{Distribution} instance has been created |
| 1983 | and populated with the keyword arguments to \function{setup()}} |
| 1984 | \lineii{config}{Stop after config files have been parsed (and their data |
| 1985 | stored in the \class{Distribution} instance)} |
| 1986 | \lineii{commandline}{Stop after the command-line (\code{sys.argv[1:]} or |
| 1987 | \var{script_args}) have been parsed (and the data stored in the |
| 1988 | \class{Distribution} instance.)} |
| 1989 | \lineii{run}{Stop after all commands have been run (the same as |
| 1990 | if \function{setup()} had been called in the usual way). This is the default |
| 1991 | value.} |
| 1992 | \end{tableii} |
| 1993 | \end{funcdesc} |
| 1994 | |
| 1995 | In addition, the \module{distutils.core} module exposed a number of |
| 1996 | classes that live elsewhere. |
| 1997 | |
| 1998 | \begin{itemize} |
| 1999 | \item \class{Extension} from \refmodule{distutils.extension} |
| 2000 | \item \class{Command} from \refmodule{distutils.cmd} |
| 2001 | \item \class{Distribution} from \refmodule{distutils.dist} |
| 2002 | \end{itemize} |
| 2003 | |
| 2004 | A short description of each of these follows, but see the relevant |
| 2005 | module for the full reference. |
| 2006 | |
| 2007 | \begin{classdesc*}{Extension} |
| 2008 | |
| 2009 | The Extension class describes a single C or \Cpp extension module in a |
| 2010 | setup script. It accepts the following keyword arguments in it's |
| 2011 | constructor |
| 2012 | |
| 2013 | \begin{tableiii}{c|l|l}{argument name}{argument name}{value}{type} |
| 2014 | \lineiii{name}{the full name of the extension, including any packages |
| 2015 | --- ie. \emph{not} a filename or pathname, but Python dotted name}{string} |
| 2016 | \lineiii{sources}{list of source filenames, relative to the distribution |
| 2017 | root (where the setup script lives), in Unix form (slash-separated) for |
| 2018 | portability. Source files may be C, \Cpp, SWIG (.i), platform-specific |
| 2019 | resource files, or whatever else is recognized by the \command{build_ext} |
| 2020 | command as source for a Python extension.}{string} |
| 2021 | \lineiii{include_dirs}{list of directories to search for C/\Cpp{} header |
| 2022 | files (in \UNIX{} form for portability)}{string} |
| 2023 | \lineiii{define_macros}{list of macros to define; each macro is defined |
| 2024 | using a 2-tuple, where 'value' is either the string to define it to or |
| 2025 | \code{None} to define it without a particular value (equivalent of |
| 2026 | \code{\#define FOO} in source or \programopt{-DFOO} on \UNIX{} C |
| 2027 | compiler command line) }{ (string,string) |
| 2028 | tuple or (name,\code{None}) } |
| 2029 | \lineiii{undef_macros}{list of macros to undefine explicitly}{string} |
| 2030 | \lineiii{library_dirs}{list of directories to search for C/\Cpp{} libraries |
| 2031 | at link time }{string} |
| 2032 | \lineiii{libraries}{list of library names (not filenames or paths) to |
| 2033 | link against }{string} |
| 2034 | \lineiii{runtime_library_dirs}{list of directories to search for C/\Cpp{} |
| 2035 | libraries at run time (for shared extensions, this is when the extension |
| 2036 | is loaded)}{string} |
| 2037 | \lineiii{extra_objects}{list of extra files to link with (eg. object |
| 2038 | files not implied by 'sources', static library that must be explicitly |
| 2039 | specified, binary resource files, etc.)}{string} |
| 2040 | \lineiii{extra_compile_args}{any extra platform- and compiler-specific |
| 2041 | information to use when compiling the source files in 'sources'. For |
| 2042 | platforms and compilers where a command line makes sense, this is |
| 2043 | typically a list of command-line arguments, but for other platforms it |
| 2044 | could be anything.}{string} |
| 2045 | \lineiii{extra_link_args}{any extra platform- and compiler-specific |
| 2046 | information to use when linking object files together to create the |
| 2047 | extension (or to create a new static Python interpreter). Similar |
| 2048 | interpretation as for 'extra_compile_args'.}{string} |
| 2049 | \lineiii{export_symbols}{list of symbols to be exported from a shared |
| 2050 | extension. Not used on all platforms, and not generally necessary for |
| 2051 | Python extensions, which typically export exactly one symbol: \code{init} + |
| 2052 | extension_name. }{string} |
| 2053 | \lineiii{depends}{list of files that the extension depends on }{string} |
| 2054 | \lineiii{language}{extension language (i.e. \code{'c'}, \code{'c++'}, |
| 2055 | \code{'objc'}). Will be detected from the source extensions if not provided. |
| 2056 | }{string} |
| 2057 | \end{tableiii} |
| 2058 | \end{classdesc*} |
| 2059 | |
| 2060 | \begin{classdesc*}{Distribution} |
| 2061 | A \class{Distribution} describes how to build, install and package up a |
| 2062 | Python software package. |
| 2063 | |
| 2064 | See the \function{setup()} function for a list of keyword arguments accepted |
| 2065 | by the Distribution constructor. \function{setup()} creates a Distribution |
| 2066 | instance. |
| 2067 | \end{classdesc*} |
| 2068 | |
| 2069 | \begin{classdesc*}{Command} |
| 2070 | A \class{Command} class (or rather, an instance of one of it's subclasses) |
| 2071 | implement a single distutils command. |
| 2072 | \end{classdesc*} |
| 2073 | |
| 2074 | |
| 2075 | \section{\module{distutils.ccompiler} --- CCompiler base class} |
| 2076 | \declaremodule{standard}{distutils.ccompiler} |
| 2077 | \modulesynopsis{Abstract CCompiler class} |
| 2078 | |
| 2079 | This module provides the abstract base class for the \class{CCompiler} |
| 2080 | classes. A \class{CCompiler} instance can be used for all the compile |
| 2081 | and link steps needed to build a single project. Methods are provided to |
| 2082 | set options for the compiler --- macro definitions, include directories, |
| 2083 | link path, libraries and the like. |
| 2084 | |
| 2085 | This module provides the following functions. |
| 2086 | |
| 2087 | \begin{funcdesc}{gen_lib_options}{compiler, library_dirs, runtime_library_dirs, libraries} |
| 2088 | Generate linker options for searching library directories and |
| 2089 | linking with specific libraries. \var{libraries} and \var{library_dirs} are, |
| 2090 | respectively, lists of library names (not filenames!) and search |
| 2091 | directories. Returns a list of command-line options suitable for use |
| 2092 | with some compiler (depending on the two format strings passed in). |
| 2093 | \end{funcdesc} |
| 2094 | |
| 2095 | \begin{funcdesc}{gen_preprocess_options}{macros, include_dirs} |
| 2096 | Generate C pre-processor options (-D, -U, -I) as used by at least |
| 2097 | two types of compilers: the typical \UNIX{} compiler and Visual \Cpp. |
| 2098 | \var{macros} is the usual thing, a list of 1- or 2-tuples, where \var{(name,)} |
| 2099 | means undefine (-U) macro \var{name}, and \var{(name,value)} means define (-D) |
| 2100 | macro \var{name} to \var{value}. \var{include_dirs} is just a list of directory |
| 2101 | names to be added to the header file search path (-I). Returns a list |
| 2102 | of command-line options suitable for either \UNIX{} compilers or Visual |
| 2103 | \Cpp. |
| 2104 | \end{funcdesc} |
| 2105 | |
| 2106 | \begin{funcdesc}{get_default_compiler}{osname, platform} |
| 2107 | Determine the default compiler to use for the given platform. |
| 2108 | |
| 2109 | \var{osname} should be one of the standard Python OS names (i.e. the |
| 2110 | ones returned by \var{os.name}) and \var{platform} the common value |
| 2111 | returned by \var{sys.platform} for the platform in question. |
| 2112 | |
| 2113 | The default values are \code{os.name} and \code{sys.platform} in case the |
| 2114 | parameters are not given. |
| 2115 | \end{funcdesc} |
| 2116 | |
| 2117 | \begin{funcdesc}{new_compiler}{plat=\code{None}, compiler=\code{None}, verbose=\code{0}, dry_run=\code{0}, force=\code{0}} |
| 2118 | Factory function to generate an instance of some CCompiler subclass |
| 2119 | for the supplied platform/compiler combination. \var{plat} defaults |
| 2120 | to \code{os.name} (eg. \code{'posix'}, \code{'nt'}), and \var{compiler} |
| 2121 | defaults to the default compiler for that platform. Currently only |
| 2122 | \code{'posix'} and \code{'nt'} are supported, and the default |
| 2123 | compilers are ``traditional \UNIX{} interface'' (\class{UnixCCompiler} |
| 2124 | class) and Visual \Cpp (\class{MSVCCompiler} class). Note that it's |
| 2125 | perfectly possible to ask for a \UNIX{} compiler object under Windows, |
| 2126 | and a Microsoft compiler object under \UNIX---if you supply a value |
| 2127 | for \var{compiler}, \var{plat} is ignored. |
| 2128 | % Is the posix/nt only thing still true? Mac OS X seems to work, and |
| 2129 | % returns a UnixCCompiler instance. How to document this... hmm. |
| 2130 | \end{funcdesc} |
| 2131 | |
| 2132 | \begin{funcdesc}{show_compilers}{} |
| 2133 | Print list of available compilers (used by the |
| 2134 | \longprogramopt{help-compiler} options to \command{build}, |
| 2135 | \command{build_ext}, \command{build_clib}). |
| 2136 | \end{funcdesc} |
| 2137 | |
| 2138 | \begin{classdesc}{CCompiler}{\optional{verbose=\code{0}, dry_run=\code{0}, force=\code{0}}} |
| 2139 | |
| 2140 | The abstract base class \class{CCompiler} defines the interface that |
| 2141 | must be implemented by real compiler classes. The class also has |
| 2142 | some utility methods used by several compiler classes. |
| 2143 | |
| 2144 | The basic idea behind a compiler abstraction class is that each |
| 2145 | instance can be used for all the compile/link steps in building a |
| 2146 | single project. Thus, attributes common to all of those compile and |
| 2147 | link steps --- include directories, macros to define, libraries to link |
| 2148 | against, etc. --- are attributes of the compiler instance. To allow for |
| 2149 | variability in how individual files are treated, most of those |
| 2150 | attributes may be varied on a per-compilation or per-link basis. |
| 2151 | |
| 2152 | The constructor for each subclass creates an instance of the Compiler |
| 2153 | object. Flags are \var{verbose} (show verbose output), \var{dry_run} |
| 2154 | (don't actually execute the steps) and \var{force} (rebuild |
| 2155 | everything, regardless of dependencies). All of these flags default to |
| 2156 | \code{0} (off). Note that you probably don't want to instantiate |
| 2157 | \class{CCompiler} or one of it's subclasses directly - use the |
| 2158 | \function{distutils.CCompiler.new_compiler()} factory function |
| 2159 | instead. |
| 2160 | |
| 2161 | The following methods allow you to manually alter compiler options for |
| 2162 | the instance of the Compiler class. |
| 2163 | |
| 2164 | \begin{methoddesc}{add_include_dir}{dir} |
| 2165 | Add \var{dir} to the list of directories that will be searched for |
| 2166 | header files. The compiler is instructed to search directories in |
| 2167 | the order in which they are supplied by successive calls to |
| 2168 | \method{add_include_dir()}. |
| 2169 | \end{methoddesc} |
| 2170 | |
| 2171 | \begin{methoddesc}{set_include_dirs}{dirs} |
| 2172 | Set the list of directories that will be searched to \var{dirs} (a |
| 2173 | list of strings). Overrides any preceding calls to |
| 2174 | \method{add_include_dir()}; subsequent calls to |
| 2175 | \method{add_include_dir()} add to the list passed to |
| 2176 | \method{set_include_dirs()}. This does not affect any list of |
| 2177 | standard include directories that the compiler may search by default. |
| 2178 | \end{methoddesc} |
| 2179 | |
| 2180 | \begin{methoddesc}{add_library}{libname} |
| 2181 | |
| 2182 | Add \var{libname} to the list of libraries that will be included in |
| 2183 | all links driven by this compiler object. Note that \var{libname} |
| 2184 | should *not* be the name of a file containing a library, but the |
| 2185 | name of the library itself: the actual filename will be inferred by |
| 2186 | the linker, the compiler, or the compiler class (depending on the |
| 2187 | platform). |
| 2188 | |
| 2189 | The linker will be instructed to link against libraries in the |
| 2190 | order they were supplied to \method{add_library()} and/or |
| 2191 | \method{set_libraries()}. It is perfectly valid to duplicate library |
| 2192 | names; the linker will be instructed to link against libraries as |
| 2193 | many times as they are mentioned. |
| 2194 | \end{methoddesc} |
| 2195 | |
| 2196 | \begin{methoddesc}{set_libraries}{libnames} |
| 2197 | Set the list of libraries to be included in all links driven by |
| 2198 | this compiler object to \var{libnames} (a list of strings). This does |
| 2199 | not affect any standard system libraries that the linker may |
| 2200 | include by default. |
| 2201 | \end{methoddesc} |
| 2202 | |
| 2203 | \begin{methoddesc}{add_library_dir}{dir} |
| 2204 | Add \var{dir} to the list of directories that will be searched for |
| 2205 | libraries specified to \method{add_library()} and |
| 2206 | \method{set_libraries()}. The linker will be instructed to search for |
| 2207 | libraries in the order they are supplied to \method{add_library_dir()} |
| 2208 | and/or \method{set_library_dirs()}. |
| 2209 | \end{methoddesc} |
| 2210 | |
| 2211 | \begin{methoddesc}{set_library_dirs}{dirs} |
| 2212 | Set the list of library search directories to \var{dirs} (a list of |
| 2213 | strings). This does not affect any standard library search path |
| 2214 | that the linker may search by default. |
| 2215 | \end{methoddesc} |
| 2216 | |
| 2217 | \begin{methoddesc}{add_runtime_library_dir}{dir} |
| 2218 | Add \var{dir} to the list of directories that will be searched for |
| 2219 | shared libraries at runtime. |
| 2220 | \end{methoddesc} |
| 2221 | |
| 2222 | \begin{methoddesc}{set_runtime_library_dirs}{dirs} |
| 2223 | Set the list of directories to search for shared libraries at |
| 2224 | runtime to \var{dirs} (a list of strings). This does not affect any |
| 2225 | standard search path that the runtime linker may search by |
| 2226 | default. |
| 2227 | \end{methoddesc} |
| 2228 | |
| 2229 | \begin{methoddesc}{define_macro}{name\optional{, value=\code{None}}} |
| 2230 | Define a preprocessor macro for all compilations driven by this |
| 2231 | compiler object. The optional parameter \var{value} should be a |
| 2232 | string; if it is not supplied, then the macro will be defined |
| 2233 | without an explicit value and the exact outcome depends on the |
| 2234 | compiler used (XXX true? does ANSI say anything about this?) |
| 2235 | \end{methoddesc} |
| 2236 | |
| 2237 | \begin{methoddesc}{undefine_macro}{name} |
| 2238 | Undefine a preprocessor macro for all compilations driven by |
| 2239 | this compiler object. If the same macro is defined by |
| 2240 | \method{define_macro()} and undefined by \method{undefine_macro()} |
| 2241 | the last call takes precedence (including multiple redefinitions or |
| 2242 | undefinitions). If the macro is redefined/undefined on a |
| 2243 | per-compilation basis (ie. in the call to \method{compile()}), then that |
| 2244 | takes precedence. |
| 2245 | \end{methoddesc} |
| 2246 | |
| 2247 | \begin{methoddesc}{add_link_object}{object} |
| 2248 | Add \var{object} to the list of object files (or analogues, such as |
| 2249 | explicitly named library files or the output of ``resource |
| 2250 | compilers'') to be included in every link driven by this compiler |
| 2251 | object. |
| 2252 | \end{methoddesc} |
| 2253 | |
| 2254 | \begin{methoddesc}{set_link_objects}{objects} |
| 2255 | Set the list of object files (or analogues) to be included in |
| 2256 | every link to \var{objects}. This does not affect any standard object |
| 2257 | files that the linker may include by default (such as system |
| 2258 | libraries). |
| 2259 | \end{methoddesc} |
| 2260 | |
| 2261 | The following methods implement methods for autodetection of compiler |
| 2262 | options, providing some functionality similar to GNU \program{autoconf}. |
| 2263 | |
| 2264 | \begin{methoddesc}{detect_language}{sources} |
| 2265 | Detect the language of a given file, or list of files. Uses the |
| 2266 | instance attributes \member{language_map} (a dictionary), and |
| 2267 | \member{language_order} (a list) to do the job. |
| 2268 | \end{methoddesc} |
| 2269 | |
| 2270 | \begin{methoddesc}{find_library_file}{dirs, lib\optional{, debug=\code{0}}} |
| 2271 | Search the specified list of directories for a static or shared |
| 2272 | library file \var{lib} and return the full path to that file. If |
| 2273 | \var{debug} is true, look for a debugging version (if that makes sense on |
| 2274 | the current platform). Return \code{None} if \var{lib} wasn't found in any of |
| 2275 | the specified directories. |
| 2276 | \end{methoddesc} |
| 2277 | |
| 2278 | \begin{methoddesc}{has_function}{funcname \optional{, includes=\code{None}, include_dirs=\code{None}, libraries=\code{None}, library_dirs=\code{None}}} |
| 2279 | Return a boolean indicating whether \var{funcname} is supported on |
| 2280 | the current platform. The optional arguments can be used to |
| 2281 | augment the compilation environment by providing additional include |
| 2282 | files and paths and libraries and paths. |
| 2283 | \end{methoddesc} |
| 2284 | |
| 2285 | \begin{methoddesc}{library_dir_option}{dir} |
| 2286 | Return the compiler option to add \var{dir} to the list of |
| 2287 | directories searched for libraries. |
| 2288 | \end{methoddesc} |
| 2289 | |
| 2290 | \begin{methoddesc}{library_option}{lib} |
| 2291 | Return the compiler option to add \var{dir} to the list of libraries |
| 2292 | linked into the shared library or executable. |
| 2293 | \end{methoddesc} |
| 2294 | |
| 2295 | \begin{methoddesc}{runtime_library_dir_option}{dir} |
| 2296 | Return the compiler option to add \var{dir} to the list of |
| 2297 | directories searched for runtime libraries. |
| 2298 | \end{methoddesc} |
| 2299 | |
| 2300 | \begin{methoddesc}{set_executables}{**args} |
| 2301 | Define the executables (and options for them) that will be run |
| 2302 | to perform the various stages of compilation. The exact set of |
| 2303 | executables that may be specified here depends on the compiler |
| 2304 | class (via the 'executables' class attribute), but most will have: |
| 2305 | |
| 2306 | \begin{tableii}{l|l}{attribute}{attribute}{description} |
| 2307 | \lineii{compiler}{the C/\Cpp{} compiler} |
| 2308 | \lineii{linker_so}{linker used to create shared objects and libraries} |
| 2309 | \lineii{linker_exe}{linker used to create binary executables} |
| 2310 | \lineii{archiver}{static library creator} |
| 2311 | \end{tableii} |
| 2312 | |
| 2313 | On platforms with a command-line (\UNIX, DOS/Windows), each of these |
| 2314 | is a string that will be split into executable name and (optional) |
| 2315 | list of arguments. (Splitting the string is done similarly to how |
| 2316 | \UNIX{} shells operate: words are delimited by spaces, but quotes and |
| 2317 | backslashes can override this. See |
| 2318 | \function{distutils.util.split_quoted()}.) |
| 2319 | \end{methoddesc} |
| 2320 | |
| 2321 | The following methods invoke stages in the build process. |
| 2322 | |
| 2323 | \begin{methoddesc}{compile}{sources\optional{, output_dir=\code{None}, macros=\code{None}, include_dirs=\code{None}, debug=\code{0}, extra_preargs=\code{None}, extra_postargs=\code{None}, depends=\code{None}}} |
| 2324 | Compile one or more source files. Generates object files (e.g. |
| 2325 | transforms a \file{.c} file to a \file{.o} file.) |
| 2326 | |
| 2327 | \var{sources} must be a list of filenames, most likely C/\Cpp |
| 2328 | files, but in reality anything that can be handled by a |
| 2329 | particular compiler and compiler class (eg. \class{MSVCCompiler} can |
| 2330 | handle resource files in \var{sources}). Return a list of object |
| 2331 | filenames, one per source filename in \var{sources}. Depending on |
| 2332 | the implementation, not all source files will necessarily be |
| 2333 | compiled, but all corresponding object filenames will be |
| 2334 | returned. |
| 2335 | |
| 2336 | If \var{output_dir} is given, object files will be put under it, while |
| 2337 | retaining their original path component. That is, \file{foo/bar.c} |
| 2338 | normally compiles to \file{foo/bar.o} (for a \UNIX{} implementation); if |
| 2339 | \var{output_dir} is \var{build}, then it would compile to |
| 2340 | \file{build/foo/bar.o}. |
| 2341 | |
| 2342 | \var{macros}, if given, must be a list of macro definitions. A macro |
| 2343 | definition is either a \var{(name, value)} 2-tuple or a \var{(name,)} 1-tuple. |
| 2344 | The former defines a macro; if the value is \code{None}, the macro is |
| 2345 | defined without an explicit value. The 1-tuple case undefines a |
| 2346 | macro. Later definitions/redefinitions/undefinitions take |
| 2347 | precedence. |
| 2348 | |
| 2349 | \var{include_dirs}, if given, must be a list of strings, the |
| 2350 | directories to add to the default include file search path for this |
| 2351 | compilation only. |
| 2352 | |
| 2353 | \var{debug} is a boolean; if true, the compiler will be instructed to |
| 2354 | output debug symbols in (or alongside) the object file(s). |
| 2355 | |
| 2356 | \var{extra_preargs} and \var{extra_postargs} are implementation- dependent. |
| 2357 | On platforms that have the notion of a command-line (e.g. \UNIX, |
| 2358 | DOS/Windows), they are most likely lists of strings: extra |
| 2359 | command-line arguments to prepand/append to the compiler command |
| 2360 | line. On other platforms, consult the implementation class |
| 2361 | documentation. In any event, they are intended as an escape hatch |
| 2362 | for those occasions when the abstract compiler framework doesn't |
| 2363 | cut the mustard. |
| 2364 | |
| 2365 | \var{depends}, if given, is a list of filenames that all targets |
| 2366 | depend on. If a source file is older than any file in |
| 2367 | depends, then the source file will be recompiled. This |
| 2368 | supports dependency tracking, but only at a coarse |
| 2369 | granularity. |
| 2370 | |
| 2371 | Raises \exception{CompileError} on failure. |
| 2372 | \end{methoddesc} |
| 2373 | |
| 2374 | \begin{methoddesc}{create_static_lib}{objects, output_libname\optional{, output_dir=\code{None}, debug=\code{0}, target_lang=\code{None}}} |
| 2375 | Link a bunch of stuff together to create a static library file. |
| 2376 | The ``bunch of stuff'' consists of the list of object files supplied |
| 2377 | as \var{objects}, the extra object files supplied to |
| 2378 | \method{add_link_object()} and/or \method{set_link_objects()}, the libraries |
| 2379 | supplied to \method{add_library()} and/or \method{set_libraries()}, and the |
| 2380 | libraries supplied as \var{libraries} (if any). |
| 2381 | |
| 2382 | \var{output_libname} should be a library name, not a filename; the |
| 2383 | filename will be inferred from the library name. \var{output_dir} is |
| 2384 | the directory where the library file will be put. XXX defaults to what? |
| 2385 | |
| 2386 | \var{debug} is a boolean; if true, debugging information will be |
| 2387 | included in the library (note that on most platforms, it is the |
| 2388 | compile step where this matters: the \var{debug} flag is included here |
| 2389 | just for consistency). |
| 2390 | |
| 2391 | \var{target_lang} is the target language for which the given objects |
| 2392 | are being compiled. This allows specific linkage time treatment of |
| 2393 | certain languages. |
| 2394 | |
| 2395 | Raises \exception{LibError} on failure. |
| 2396 | \end{methoddesc} |
| 2397 | |
| 2398 | \begin{methoddesc}{link}{target_desc, objects, output_filename\optional{, output_dir=\code{None}, libraries=\code{None}, library_dirs=\code{None}, runtime_library_dirs=\code{None}, export_symbols=\code{None}, debug=\code{0}, extra_preargs=\code{None}, extra_postargs=\code{None}, build_temp=\code{None}, target_lang=\code{None}}} |
| 2399 | Link a bunch of stuff together to create an executable or |
| 2400 | shared library file. |
| 2401 | |
| 2402 | The ``bunch of stuff'' consists of the list of object files supplied |
| 2403 | as \var{objects}. \var{output_filename} should be a filename. If |
| 2404 | \var{output_dir} is supplied, \var{output_filename} is relative to it |
| 2405 | (i.e. \var{output_filename} can provide directory components if |
| 2406 | needed). |
| 2407 | |
| 2408 | \var{libraries} is a list of libraries to link against. These are |
| 2409 | library names, not filenames, since they're translated into |
| 2410 | filenames in a platform-specific way (eg. \var{foo} becomes \file{libfoo.a} |
| 2411 | on \UNIX{} and \file{foo.lib} on DOS/Windows). However, they can include a |
| 2412 | directory component, which means the linker will look in that |
| 2413 | specific directory rather than searching all the normal locations. |
| 2414 | |
| 2415 | \var{library_dirs}, if supplied, should be a list of directories to |
| 2416 | search for libraries that were specified as bare library names |
| 2417 | (ie. no directory component). These are on top of the system |
| 2418 | default and those supplied to \method{add_library_dir()} and/or |
| 2419 | \method{set_library_dirs()}. \var{runtime_library_dirs} is a list of |
| 2420 | directories that will be embedded into the shared library and used |
| 2421 | to search for other shared libraries that *it* depends on at |
| 2422 | run-time. (This may only be relevant on \UNIX.) |
| 2423 | |
| 2424 | \var{export_symbols} is a list of symbols that the shared library will |
| 2425 | export. (This appears to be relevant only on Windows.) |
| 2426 | |
| 2427 | \var{debug} is as for \method{compile()} and \method{create_static_lib()}, |
| 2428 | with the slight distinction that it actually matters on most platforms (as |
| 2429 | opposed to \method{create_static_lib()}, which includes a \var{debug} flag |
| 2430 | mostly for form's sake). |
| 2431 | |
| 2432 | \var{extra_preargs} and \var{extra_postargs} are as for \method{compile()} |
| 2433 | (except of course that they supply command-line arguments for the |
| 2434 | particular linker being used). |
| 2435 | |
| 2436 | \var{target_lang} is the target language for which the given objects |
| 2437 | are being compiled. This allows specific linkage time treatment of |
| 2438 | certain languages. |
| 2439 | |
| 2440 | Raises \exception{LinkError} on failure. |
| 2441 | \end{methoddesc} |
| 2442 | |
| 2443 | \begin{methoddesc}{link_executable}{objects, output_progname\optional{, output_dir=\code{None}, libraries=\code{None}, library_dirs=\code{None}, runtime_library_dirs=\code{None}, debug=\code{0}, extra_preargs=\code{None}, extra_postargs=\code{None}, target_lang=\code{None}}} |
| 2444 | Link an executable. |
| 2445 | \var{output_progname} is the name of the file executable, |
| 2446 | while \var{objects} are a list of object filenames to link in. Other arguments |
| 2447 | are as for the \method{link} method. |
| 2448 | \end{methoddesc} |
| 2449 | |
| 2450 | \begin{methoddesc}{link_shared_lib}{objects, output_libname\optional{, output_dir=\code{None}, libraries=\code{None}, library_dirs=\code{None}, runtime_library_dirs=\code{None}, export_symbols=\code{None}, debug=\code{0}, extra_preargs=\code{None}, extra_postargs=\code{None}, build_temp=\code{None}, target_lang=\code{None}}} |
| 2451 | Link a shared library. \var{output_libname} is the name of the output |
| 2452 | library, while \var{objects} is a list of object filenames to link in. |
| 2453 | Other arguments are as for the \method{link} method. |
| 2454 | \end{methoddesc} |
| 2455 | |
| 2456 | \begin{methoddesc}{link_shared_object}{objects, output_filename\optional{, output_dir=\code{None}, libraries=\code{None}, library_dirs=\code{None}, runtime_library_dirs=\code{None}, export_symbols=\code{None}, debug=\code{0}, extra_preargs=\code{None}, extra_postargs=\code{None}, build_temp=\code{None}, target_lang=\code{None}}} |
| 2457 | Link a shared object. \var{output_filename} is the name of the shared object |
| 2458 | that will be created, while \var{objects} is a list of object filenames |
| 2459 | to link in. Other arguments are as for the \method{link} method. |
| 2460 | \end{methoddesc} |
| 2461 | |
| 2462 | \begin{methoddesc}{preprocess}{source\optional{, output_file=\code{None}, macros=\code{None}, include_dirs=\code{None}, extra_preargs=\code{None}, extra_postargs=\code{None}}} |
| 2463 | Preprocess a single C/\Cpp{} source file, named in \var{source}. |
| 2464 | Output will be written to file named \var{output_file}, or \var{stdout} if |
| 2465 | \var{output_file} not supplied. \var{macros} is a list of macro |
| 2466 | definitions as for \method{compile()}, which will augment the macros set |
| 2467 | with \method{define_macro()} and \method{undefine_macro()}. |
| 2468 | \var{include_dirs} is a list of directory names that will be added to the |
| 2469 | default list, in the same way as \method{add_include_dir()}. |
| 2470 | |
| 2471 | Raises \exception{PreprocessError} on failure. |
| 2472 | \end{methoddesc} |
| 2473 | |
| 2474 | The following utility methods are defined by the \class{CCompiler} class, |
| 2475 | for use by the various concrete subclasses. |
| 2476 | |
| 2477 | \begin{methoddesc}{executable_filename}{basename\optional{, strip_dir=\code{0}, output_dir=\code{''}}} |
| 2478 | Returns the filename of the executable for the given \var{basename}. |
| 2479 | Typically for non-Windows platforms this is the same as the basename, |
| 2480 | while Windows will get a \file{.exe} added. |
| 2481 | \end{methoddesc} |
| 2482 | |
| 2483 | \begin{methoddesc}{library_filename}{libname\optional{, lib_type=\code{'static'}, strip_dir=\code{0}, output_dir=\code{''}}} |
| 2484 | Returns the filename for the given library name on the current platform. |
| 2485 | On \UNIX{} a library with \var{lib_type} of \code{'static'} will typically |
| 2486 | be of the form \file{liblibname.a}, while a \var{lib_type} of \code{'dynamic'} |
| 2487 | will be of the form \file{liblibname.so}. |
| 2488 | \end{methoddesc} |
| 2489 | |
| 2490 | \begin{methoddesc}{object_filenames}{source_filenames\optional{, strip_dir=\code{0}, output_dir=\code{''}}} |
| 2491 | Returns the name of the object files for the given source files. |
| 2492 | \var{source_filenames} should be a list of filenames. |
| 2493 | \end{methoddesc} |
| 2494 | |
| 2495 | \begin{methoddesc}{shared_object_filename}{basename\optional{, strip_dir=\code{0}, output_dir=\code{''}}} |
| 2496 | Returns the name of a shared object file for the given file name \var{basename}. |
| 2497 | \end{methoddesc} |
| 2498 | |
| 2499 | \begin{methoddesc}{execute}{func, args\optional{, msg=\code{None}, level=\code{1}}} |
| 2500 | Invokes \function{distutils.util.execute()} This method invokes a |
| 2501 | Python function \var{func} with the given arguments \var{args}, after |
| 2502 | logging and taking into account the \var{dry_run} flag. XXX see also. |
| 2503 | \end{methoddesc} |
| 2504 | |
| 2505 | \begin{methoddesc}{spawn}{cmd} |
| 2506 | Invokes \function{distutils.util.spawn()}. This invokes an external |
| 2507 | process to run the given command. XXX see also. |
| 2508 | \end{methoddesc} |
| 2509 | |
| 2510 | \begin{methoddesc}{mkpath}{name\optional{, mode=\code{511}}} |
| 2511 | |
| 2512 | Invokes \function{distutils.dir_util.mkpath()}. This creates a directory |
| 2513 | and any missing ancestor directories. XXX see also. |
| 2514 | \end{methoddesc} |
| 2515 | |
| 2516 | \begin{methoddesc}{move_file}{src, dst} |
| 2517 | Invokes \method{distutils.file_util.move_file()}. Renames \var{src} to |
| 2518 | \var{dst}. XXX see also. |
| 2519 | \end{methoddesc} |
| 2520 | |
| 2521 | \begin{methoddesc}{announce}{msg\optional{, level=\code{1}}} |
| 2522 | Write a message using \function{distutils.log.debug()}. XXX see also. |
| 2523 | \end{methoddesc} |
| 2524 | |
| 2525 | \begin{methoddesc}{warn}{msg} |
| 2526 | Write a warning message \var{msg} to standard error. |
| 2527 | \end{methoddesc} |
| 2528 | |
| 2529 | \begin{methoddesc}{debug_print}{msg} |
| 2530 | If the \var{debug} flag is set on this \class{CCompiler} instance, print |
| 2531 | \var{msg} to standard output, otherwise do nothing. |
| 2532 | \end{methoddesc} |
| 2533 | |
| 2534 | \end{classdesc} |
| 2535 | |
| 2536 | %\subsection{Compiler-specific modules} |
| 2537 | % |
| 2538 | %The following modules implement concrete subclasses of the abstract |
| 2539 | %\class{CCompiler} class. They should not be instantiated directly, but should |
| 2540 | %be created using \function{distutils.ccompiler.new_compiler()} factory |
| 2541 | %function. |
| 2542 | |
| 2543 | \section{\module{distutils.unixccompiler} --- Unix C Compiler} |
| 2544 | \declaremodule{standard}{distutils.unixccompiler} |
| 2545 | \modulesynopsis{UNIX C Compiler} |
| 2546 | |
| 2547 | This module provides the \class{UnixCCompiler} class, a subclass of |
| 2548 | \class{CCompiler} that handles the typical \UNIX-style command-line |
| 2549 | C compiler: |
| 2550 | |
| 2551 | \begin{itemize} |
| 2552 | \item macros defined with \programopt{-D\var{name}\optional{=value}} |
| 2553 | \item macros undefined with \programopt{-U\var{name}} |
| 2554 | \item include search directories specified with |
| 2555 | \programopt{-I\var{dir}} |
| 2556 | \item libraries specified with \programopt{-l\var{lib}} |
| 2557 | \item library search directories specified with \programopt{-L\var{dir}} |
| 2558 | \item compile handled by \program{cc} (or similar) executable with |
| 2559 | \programopt{-c} option: compiles \file{.c} to \file{.o} |
| 2560 | \item link static library handled by \program{ar} command (possibly |
| 2561 | with \program{ranlib}) |
| 2562 | \item link shared library handled by \program{cc} \programopt{-shared} |
| 2563 | \end{itemize} |
| 2564 | |
| 2565 | \section{\module{distutils.msvccompiler} --- Microsoft Compiler} |
| 2566 | \declaremodule{standard}{distutils.msvccompiler} |
| 2567 | \modulesynopsis{Microsoft Compiler} |
| 2568 | |
| 2569 | This module provides \class{MSVCCompiler}, an implementation of the abstract |
| 2570 | \class{CCompiler} class for Microsoft Visual Studio. It should also work using |
| 2571 | the freely available compiler provided as part of the .Net SDK download. XXX |
| 2572 | download link. |
| 2573 | |
| 2574 | \section{\module{distutils.bcppcompiler} --- Borland Compiler} |
| 2575 | \declaremodule{standard}{distutils.bcppcompiler} |
| 2576 | This module provides \class{BorlandCCompiler}, an subclass of the abstract \class{CCompiler} class for the Borland \Cpp{} compiler. |
| 2577 | |
| 2578 | \section{\module{distutils.cygwincompiler} --- Cygwin Compiler} |
| 2579 | \declaremodule{standard}{distutils.cygwinccompiler} |
| 2580 | |
| 2581 | This module provides the \class{CygwinCCompiler} class, a subclass of \class{UnixCCompiler} that |
| 2582 | handles the Cygwin port of the GNU C compiler to Windows. It also contains |
| 2583 | the Mingw32CCompiler class which handles the mingw32 port of GCC (same as |
| 2584 | cygwin in no-cygwin mode). |
| 2585 | |
| 2586 | \section{\module{distutils.emxccompiler} --- OS/2 EMX Compiler} |
| 2587 | \declaremodule{standard}{distutils.emxccompiler} |
| 2588 | \modulesynopsis{OS/2 EMX Compiler support} |
| 2589 | |
| 2590 | This module provides the EMXCCompiler class, a subclass of \class{UnixCCompiler} that handles the EMX port of the GNU C compiler to OS/2. |
| 2591 | |
| 2592 | \section{\module{distutils.mwerkscompiler} --- Metrowerks CodeWarrior support} |
| 2593 | \declaremodule{standard}{distutils.mwerkscompiler} |
| 2594 | \modulesynopsis{Metrowerks CodeWarrior support} |
| 2595 | |
| 2596 | Contains \class{MWerksCompiler}, an implementation of the abstract |
| 2597 | \class{CCompiler} class for MetroWerks CodeWarrior on the Macintosh. Needs work to support CW on Windows. |
| 2598 | |
| 2599 | |
| 2600 | %\subsection{Utility modules} |
| 2601 | % |
| 2602 | %The following modules all provide general utility functions. They haven't |
| 2603 | %all been documented yet. |
| 2604 | |
| 2605 | \section{\module{distutils.archive_util} --- |
| 2606 | Archiving utilities} |
| 2607 | \declaremodule[distutils.archiveutil]{standard}{distutils.archive_util} |
| 2608 | \modulesynopsis{Utility functions for creating archive files (tarballs, zip files, ...)} |
| 2609 | |
| 2610 | This module provides a few functions for creating archive files, such as |
| 2611 | tarballs or zipfiles. |
| 2612 | |
| 2613 | \begin{funcdesc}{make_archive}{base_name, format\optional{, root_dir=\code{None}, base_dir=\code{None}, verbose=\code{0}, dry_run=\code{0}}} |
| 2614 | Create an archive file (eg. \code{zip} or \code{tar}). \var{base_name} |
| 2615 | is the name of the file to create, minus any format-specific extension; |
| 2616 | \var{format} is the archive format: one of \code{zip}, \code{tar}, |
| 2617 | \code{ztar}, or \code{gztar}. |
| 2618 | \var{root_dir} is a directory that will be the root directory of the |
| 2619 | archive; ie. we typically \code{chdir} into \var{root_dir} before |
| 2620 | creating the archive. \var{base_dir} is the directory where we start |
| 2621 | archiving from; ie. \var{base_dir} will be the common prefix of all files and |
| 2622 | directories in the archive. \var{root_dir} and \var{base_dir} both default |
| 2623 | to the current directory. Returns the name of the archive file. |
| 2624 | |
| 2625 | \warning{This should be changed to support bz2 files} |
| 2626 | \end{funcdesc} |
| 2627 | |
| 2628 | \begin{funcdesc}{make_tarball}{base_name, base_dir\optional{, compress=\code{'gzip'}, verbose=\code{0}, dry_run=\code{0}}}'Create an (optional compressed) archive as a tar file from all files in and under \var{base_dir}. \var{compress} must be \code{'gzip'} (the default), |
| 2629 | \code{'compress'}, \code{'bzip2'}, or \code{None}. Both \code{'tar'} |
| 2630 | and the compression utility named by \var{'compress'} must be on the |
| 2631 | default program search path, so this is probably \UNIX-specific. The |
| 2632 | output tar file will be named \file{\var{base_dir}.tar}, possibly plus |
| 2633 | the appropriate compression extension (\file{.gz}, \file{.bz2} or |
| 2634 | \file{.Z}). Return the output filename. |
| 2635 | |
| 2636 | \warning{This should be replaced with calls to the \module{tarfile} module.} |
| 2637 | \end{funcdesc} |
| 2638 | |
| 2639 | \begin{funcdesc}{make_zipfile}{base_name, base_dir\optional{, verbose=\code{0}, dry_run=\code{0}}} |
| 2640 | Create a zip file from all files in and under \var{base_dir}. The output |
| 2641 | zip file will be named \var{base_dir} + \file{.zip}. Uses either the |
| 2642 | \module{zipfile} Python module (if available) or the InfoZIP \file{zip} |
| 2643 | utility (if installed and found on the default search path). If neither |
| 2644 | tool is available, raises \exception{DistutilsExecError}. |
| 2645 | Returns the name of the output zip file. |
| 2646 | \end{funcdesc} |
| 2647 | |
| 2648 | \section{\module{distutils.dep_util} --- Dependency checking} |
| 2649 | \declaremodule[distutils.deputil]{standard}{distutils.dep_util} |
| 2650 | \modulesynopsis{Utility functions for simple dependency checking} |
| 2651 | |
| 2652 | This module provides functions for performing simple, timestamp-based |
| 2653 | dependency of files and groups of files; also, functions based entirely |
| 2654 | on such timestamp dependency analysis. |
| 2655 | |
| 2656 | \begin{funcdesc}{newer}{source, target} |
| 2657 | Return true if \var{source} exists and is more recently modified than |
| 2658 | \var{target}, or if \var{source} exists and \var{target} doesn't. |
| 2659 | Return false if both exist and \var{target} is the same age or newer |
| 2660 | than \var{source}. |
| 2661 | Raise \exception{DistutilsFileError} if \var{source} does not exist. |
| 2662 | \end{funcdesc} |
| 2663 | |
| 2664 | \begin{funcdesc}{newer_pairwise}{sources, targets} |
| 2665 | Walk two filename lists in parallel, testing if each source is newer |
| 2666 | than its corresponding target. Return a pair of lists (\var{sources}, |
| 2667 | \var{targets}) where source is newer than target, according to the semantics |
| 2668 | of \function{newer()} |
| 2669 | %% equivalent to a listcomp... |
| 2670 | \end{funcdesc} |
| 2671 | |
| 2672 | \begin{funcdesc}{newer_group}{sources, target\optional{, missing=\code{'error'}}} |
| 2673 | Return true if \var{target} is out-of-date with respect to any file |
| 2674 | listed in \var{sources} In other words, if \var{target} exists and is newer |
| 2675 | than every file in \var{sources}, return false; otherwise return true. |
| 2676 | \var{missing} controls what we do when a source file is missing; the |
| 2677 | default (\code{'error'}) is to blow up with an \exception{OSError} from |
| 2678 | inside \function{os.stat()}; |
| 2679 | if it is \code{'ignore'}, we silently drop any missing source files; if it is |
| 2680 | \code{'newer'}, any missing source files make us assume that \var{target} is |
| 2681 | out-of-date (this is handy in ``dry-run'' mode: it'll make you pretend to |
| 2682 | carry out commands that wouldn't work because inputs are missing, but |
| 2683 | that doesn't matter because you're not actually going to run the |
| 2684 | commands). |
| 2685 | \end{funcdesc} |
| 2686 | |
| 2687 | \section{\module{distutils.dir_util} --- Directory tree operations} |
| 2688 | \declaremodule[distutils.dirutil]{standard}{distutils.dir_util} |
| 2689 | \modulesynopsis{Utility functions for operating on directories and directory trees} |
| 2690 | |
| 2691 | This module provides functions for operating on directories and trees |
| 2692 | of directories. |
| 2693 | |
| 2694 | \begin{funcdesc}{mkpath}{name\optional{, mode=\code{0777}, verbose=\code{0}, dry_run=\code{0}}} |
| 2695 | Create a directory and any missing ancestor directories. If the |
| 2696 | directory already exists (or if \var{name} is the empty string, which |
| 2697 | means the current directory, which of course exists), then do |
| 2698 | nothing. Raise \exception{DistutilsFileError} if unable to create some |
| 2699 | directory along the way (eg. some sub-path exists, but is a file |
| 2700 | rather than a directory). If \var{verbose} is true, print a one-line |
| 2701 | summary of each mkdir to stdout. Return the list of directories |
| 2702 | actually created. |
| 2703 | \end{funcdesc} |
| 2704 | |
| 2705 | \begin{funcdesc}{create_tree}{base_dir, files\optional{, mode=\code{0777}, verbose=\code{0}, dry_run=\code{0}}} |
| 2706 | Create all the empty directories under \var{base_dir} needed to |
| 2707 | put \var{files} there. \var{base_dir} is just the a name of a directory |
| 2708 | which doesn't necessarily exist yet; \var{files} is a list of filenames |
| 2709 | to be interpreted relative to \var{base_dir}. \var{base_dir} + the |
| 2710 | directory portion of every file in \var{files} will be created if it |
| 2711 | doesn't already exist. \var{mode}, \var{verbose} and \var{dry_run} flags |
| 2712 | are as for \function{mkpath()}. |
| 2713 | \end{funcdesc} |
| 2714 | |
| 2715 | \begin{funcdesc}{copy_tree}{src, dst\optional{preserve_mode=\code{1}, preserve_times=\code{1}, preserve_symlinks=\code{0}, update=\code{0}, verbose=\code{0}, dry_run=\code{0}}} |
| 2716 | Copy an entire directory tree \var{src} to a new location \var{dst}. Both |
| 2717 | \var{src} and \var{dst} must be directory names. If \var{src} is not a |
| 2718 | directory, raise \exception{DistutilsFileError}. If \var{dst} does |
| 2719 | not exist, it is created with \var{mkpath()}. The end result of the |
| 2720 | copy is that every file in \var{src} is copied to \var{dst}, and |
| 2721 | directories under \var{src} are recursively copied to \var{dst}. |
| 2722 | Return the list of files that were copied or might have been copied, |
| 2723 | using their output name. The return value is unaffected by \var{update} |
| 2724 | or \var{dry_run}: it is simply the list of all files under \var{src}, |
| 2725 | with the names changed to be under \var{dst}. |
| 2726 | |
| 2727 | \var{preserve_mode} and \var{preserve_times} are the same as for |
| 2728 | \function{copy_file} in \refmodule[distutils.fileutil]{distutils.file_util}; |
| 2729 | note that they only apply to regular files, not to directories. If |
| 2730 | \var{preserve_symlinks} is true, symlinks will be copied as symlinks |
| 2731 | (on platforms that support them!); otherwise (the default), the |
| 2732 | destination of the symlink will be copied. \var{update} and |
| 2733 | \var{verbose} are the same as for |
| 2734 | \function{copy_file()}. |
| 2735 | \end{funcdesc} |
| 2736 | |
| 2737 | \begin{funcdesc}{remove_tree}{directory\optional{verbose=\code{0}, dry_run=\code{0}}} |
| 2738 | Recursively remove \var{directory} and all files and directories underneath |
| 2739 | it. Any errors are ignored (apart from being reported to \code{stdout} if |
| 2740 | \var{verbose} is true). |
| 2741 | \end{funcdesc} |
| 2742 | |
| 2743 | \XXX{Some of this could be replaced with the shutil module?} |
| 2744 | |
| 2745 | \section{\module{distutils.file_util} --- Single file operations} |
| 2746 | \declaremodule[distutils.fileutil]{standard}{distutils.file_util} |
| 2747 | \modulesynopsis{Utility functions for operating on single files} |
| 2748 | |
| 2749 | This module contains some utility functions for operating on individual files. |
| 2750 | |
| 2751 | \begin{funcdesc}{copy_file}{src, dst\optional{preserve_mode=\code{1}, preserve_times=\code{1}, update=\code{0}, link=\code{None}, verbose=\code{0}, dry_run=\code{0}}} |
| 2752 | Copy file \var{src} to \var{dst}. If \var{dst} is a directory, then |
| 2753 | \var{src} is copied there with the same name; otherwise, it must be a |
| 2754 | filename. (If the file exists, it will be ruthlessly clobbered.) If |
| 2755 | \var{preserve_mode} is true (the default), the file's mode (type and |
| 2756 | permission bits, or whatever is analogous on the current platform) is |
| 2757 | copied. If \var{preserve_times} is true (the default), the last-modified |
| 2758 | and last-access times are copied as well. If \var{update} is true, |
| 2759 | \var{src} will only be copied if \var{dst} does not exist, or if |
| 2760 | \var{dst} does exist but is older than \var{src}. |
| 2761 | |
| 2762 | \var{link} allows you to make hard links (using \function{os.link}) or |
| 2763 | symbolic links (using \function{os.symlink}) instead of copying: set it |
| 2764 | to \code{'hard'} or \code{'sym'}; if it is \code{None} (the default), |
| 2765 | files are copied. Don't set \var{link} on systems that don't support |
| 2766 | it: \function{copy_file()} doesn't check if hard or symbolic linking is |
| 2767 | available. |
| 2768 | |
| 2769 | Under Mac OS 9, uses the native file copy function in \module{macostools}; |
| 2770 | on other systems, uses \var{_copy_file_contents()} to copy file contents. |
| 2771 | |
| 2772 | Return a tuple \samp{(dest_name, copied)}: \var{dest_name} is the actual |
| 2773 | name of the output file, and \var{copied} is true if the file was copied |
| 2774 | (or would have been copied, if \var{dry_run} true). |
| 2775 | % XXX if the destination file already exists, we clobber it if |
| 2776 | % copying, but blow up if linking. Hmmm. And I don't know what |
| 2777 | % macostools.copyfile() does. Should definitely be consistent, and |
| 2778 | % should probably blow up if destination exists and we would be |
| 2779 | % changing it (ie. it's not already a hard/soft link to src OR |
| 2780 | % (not update) and (src newer than dst)). |
| 2781 | \end{funcdesc} |
| 2782 | |
| 2783 | \begin{funcdesc}{move_file}{src, dst\optional{verbose, dry_run}} |
| 2784 | Move file \var{src} to \var{dst}. If \var{dst} is a directory, the file will |
| 2785 | be moved into it with the same name; otherwise, \var{src} is just renamed |
| 2786 | to \var{dst}. Returns the new full name of the file. |
| 2787 | \warning{Handles cross-device moves on Unix using \function{copy_file()}. |
| 2788 | What about other systems???} |
| 2789 | \end{funcdesc} |
| 2790 | |
| 2791 | \begin{funcdesc}{write_file}{filename, contents} |
| 2792 | Create a file called \var{filename} and write \var{contents} (a |
| 2793 | sequence of strings without line terminators) to it. |
| 2794 | \end{funcdesc} |
| 2795 | |
| 2796 | \section{\module{distutils.utils} --- Miscellaneous other utility functions} |
| 2797 | \declaremodule{standard}{distutils.util} |
| 2798 | \modulesynopsis{Miscellaneous other utility functions} |
| 2799 | |
| 2800 | This module contains other assorted bits and pieces that don't fit into |
| 2801 | any other utility module. |
| 2802 | |
| 2803 | \begin{funcdesc}{get_platform}{} |
| 2804 | Return a string that identifies the current platform. This is used |
| 2805 | mainly to distinguish platform-specific build directories and |
| 2806 | platform-specific built distributions. Typically includes the OS name |
| 2807 | and version and the architecture (as supplied by 'os.uname()'), |
| 2808 | although the exact information included depends on the OS; eg. for IRIX |
| 2809 | the architecture isn't particularly important (IRIX only runs on SGI |
| 2810 | hardware), but for Linux the kernel version isn't particularly |
| 2811 | important. |
| 2812 | |
| 2813 | Examples of returned values: |
| 2814 | \begin{itemize} |
| 2815 | \item \code{linux-i586} |
| 2816 | \item \code{linux-alpha} |
| 2817 | \item \code{solaris-2.6-sun4u} |
| 2818 | \item \code{irix-5.3} |
| 2819 | \item \code{irix64-6.2} |
| 2820 | \end{itemize} |
| 2821 | |
| 2822 | For non-\POSIX{} platforms, currently just returns \code{sys.platform}. |
| 2823 | % XXX isn't this also provided by some other non-distutils module? |
| 2824 | \end{funcdesc} |
| 2825 | |
| 2826 | \begin{funcdesc}{convert_path}{pathname} |
| 2827 | Return 'pathname' as a name that will work on the native filesystem, |
| 2828 | i.e. split it on '/' and put it back together again using the current |
| 2829 | directory separator. Needed because filenames in the setup script are |
| 2830 | always supplied in Unix style, and have to be converted to the local |
| 2831 | convention before we can actually use them in the filesystem. Raises |
| 2832 | \exception{ValueError} on non-\UNIX-ish systems if \var{pathname} either |
| 2833 | starts or ends with a slash. |
| 2834 | \end{funcdesc} |
| 2835 | |
| 2836 | \begin{funcdesc}{change_root}{new_root, pathname} |
| 2837 | Return \var{pathname} with \var{new_root} prepended. If \var{pathname} is |
| 2838 | relative, this is equivalent to \samp{os.path.join(new_root,pathname)} |
| 2839 | Otherwise, it requires making \var{pathname} relative and then joining the |
| 2840 | two, which is tricky on DOS/Windows and Mac OS. |
| 2841 | \end{funcdesc} |
| 2842 | |
| 2843 | \begin{funcdesc}{check_environ}{} |
| 2844 | Ensure that 'os.environ' has all the environment variables we |
| 2845 | guarantee that users can use in config files, command-line options, |
| 2846 | etc. Currently this includes: |
| 2847 | \begin{itemize} |
| 2848 | \item \envvar{HOME} - user's home directory (\UNIX{} only) |
| 2849 | \item \envvar{PLAT} - description of the current platform, including |
| 2850 | hardware and OS (see \function{get_platform()}) |
| 2851 | \end{itemize} |
| 2852 | \end{funcdesc} |
| 2853 | |
| 2854 | \begin{funcdesc}{subst_vars}{s, local_vars} |
| 2855 | Perform shell/Perl-style variable substitution on \var{s}. Every |
| 2856 | occurrence of \code{\$} followed by a name is considered a variable, and |
| 2857 | variable is substituted by the value found in the \var{local_vars} |
| 2858 | dictionary, or in \code{os.environ} if it's not in \var{local_vars}. |
| 2859 | \var{os.environ} is first checked/augmented to guarantee that it contains |
| 2860 | certain values: see \function{check_environ()}. Raise \exception{ValueError} |
| 2861 | for any variables not found in either \var{local_vars} or \code{os.environ}. |
| 2862 | |
| 2863 | Note that this is not a fully-fledged string interpolation function. A |
| 2864 | valid \code{\$variable} can consist only of upper and lower case letters, |
| 2865 | numbers and an underscore. No \{ \} or \( \) style quoting is available. |
| 2866 | \end{funcdesc} |
| 2867 | |
| 2868 | \begin{funcdesc}{grok_environment_error}{exc\optional{, prefix=\samp{'error: '}}} |
| 2869 | Generate a useful error message from an \exception{EnvironmentError} |
| 2870 | (\exception{IOError} or \exception{OSError}) exception object. |
| 2871 | Handles Python 1.5.1 and later styles, and does what it can to deal with |
| 2872 | exception objects that don't have a filename (which happens when the error |
| 2873 | is due to a two-file operation, such as \function{rename()} or |
| 2874 | \function{link()}). Returns the error message as a string prefixed |
| 2875 | with \var{prefix}. |
| 2876 | \end{funcdesc} |
| 2877 | |
| 2878 | \begin{funcdesc}{split_quoted}{s} |
| 2879 | Split a string up according to Unix shell-like rules for quotes and |
| 2880 | backslashes. In short: words are delimited by spaces, as long as those |
| 2881 | spaces are not escaped by a backslash, or inside a quoted string. |
| 2882 | Single and double quotes are equivalent, and the quote characters can |
| 2883 | be backslash-escaped. The backslash is stripped from any two-character |
| 2884 | escape sequence, leaving only the escaped character. The quote |
| 2885 | characters are stripped from any quoted string. Returns a list of |
| 2886 | words. |
| 2887 | % Should probably be moved into the standard library. |
| 2888 | \end{funcdesc} |
| 2889 | |
| 2890 | \begin{funcdesc}{execute}{func, args\optional{, msg=\code{None}, verbose=\code{0}, dry_run=\code{0}}} |
| 2891 | Perform some action that affects the outside world (for instance, |
| 2892 | writing to the filesystem). Such actions are special because they |
| 2893 | are disabled by the \var{dry_run} flag. This method takes |
| 2894 | care of all that bureaucracy for you; all you have to do is supply the |
| 2895 | function to call and an argument tuple for it (to embody the |
| 2896 | ``external action'' being performed), and an optional message to |
| 2897 | print. |
| 2898 | \end{funcdesc} |
| 2899 | |
| 2900 | \begin{funcdesc}{strtobool}{val} |
| 2901 | Convert a string representation of truth to true (1) or false (0). |
| 2902 | |
| 2903 | True values are \code{y}, \code{yes}, \code{t}, \code{true}, \code{on} |
| 2904 | and \code{1}; false values are \code{n}, \code{no}, \code{f}, \code{false}, |
| 2905 | \code{off} and \code{0}. Raises \exception{ValueError} if \var{val} |
| 2906 | is anything else. |
| 2907 | \end{funcdesc} |
| 2908 | |
| 2909 | \begin{funcdesc}{byte_compile}{py_files\optional{, |
| 2910 | optimize=\code{0}, force=\code{0}, |
| 2911 | prefix=\code{None}, base_dir=\code{None}, |
| 2912 | verbose=\code{1}, dry_run=\code{0}, |
| 2913 | direct=\code{None}}} |
| 2914 | Byte-compile a collection of Python source files to either \file{.pyc} |
| 2915 | or \file{.pyo} files in the same directory. \var{py_files} is a list of files |
| 2916 | to compile; any files that don't end in \file{.py} are silently skipped. |
| 2917 | \var{optimize} must be one of the following: |
| 2918 | \begin{itemize} |
| 2919 | \item \code{0} - don't optimize (generate \file{.pyc}) |
| 2920 | \item \code{1} - normal optimization (like \samp{python -O}) |
| 2921 | \item \code{2} - extra optimization (like \samp{python -OO}) |
| 2922 | \end{itemize} |
| 2923 | |
| 2924 | If \var{force} is true, all files are recompiled regardless of |
| 2925 | timestamps. |
| 2926 | |
| 2927 | The source filename encoded in each bytecode file defaults to the |
| 2928 | filenames listed in \var{py_files}; you can modify these with \var{prefix} and |
| 2929 | \var{basedir}. \var{prefix} is a string that will be stripped off of each |
| 2930 | source filename, and \var{base_dir} is a directory name that will be |
| 2931 | prepended (after \var{prefix} is stripped). You can supply either or both |
| 2932 | (or neither) of \var{prefix} and \var{base_dir}, as you wish. |
| 2933 | |
| 2934 | If \var{dry_run} is true, doesn't actually do anything that would |
| 2935 | affect the filesystem. |
| 2936 | |
| 2937 | Byte-compilation is either done directly in this interpreter process |
| 2938 | with the standard \module{py_compile} module, or indirectly by writing a |
| 2939 | temporary script and executing it. Normally, you should let |
| 2940 | \function{byte_compile()} figure out to use direct compilation or not (see |
| 2941 | the source for details). The \var{direct} flag is used by the script |
| 2942 | generated in indirect mode; unless you know what you're doing, leave |
| 2943 | it set to \code{None}. |
| 2944 | \end{funcdesc} |
| 2945 | |
| 2946 | \begin{funcdesc}{rfc822_escape}{header} |
| 2947 | Return a version of \var{header} escaped for inclusion in an |
| 2948 | \rfc{822} header, by ensuring there are 8 spaces space after each newline. |
| 2949 | Note that it does no other modification of the string. |
| 2950 | % this _can_ be replaced |
| 2951 | \end{funcdesc} |
| 2952 | |
| 2953 | %\subsection{Distutils objects} |
| 2954 | |
| 2955 | \section{\module{distutils.dist} --- The Distribution class} |
| 2956 | \declaremodule{standard}{distutils.dist} |
| 2957 | \modulesynopsis{Provides the Distribution class, which represents the |
| 2958 | module distribution being built/installed/distributed} |
| 2959 | |
| 2960 | This module provides the \class{Distribution} class, which represents |
| 2961 | the module distribution being built/installed/distributed. |
| 2962 | |
| 2963 | |
| 2964 | \section{\module{distutils.extension} --- The Extension class} |
| 2965 | \declaremodule{standard}{distutils.extension} |
| 2966 | \modulesynopsis{Provides the Extension class, used to describe |
| 2967 | C/\Cpp{} extension modules in setup scripts} |
| 2968 | |
| 2969 | This module provides the \class{Extension} class, used to describe |
| 2970 | C/\Cpp{} extension modules in setup scripts. |
| 2971 | |
| 2972 | %\subsection{Ungrouped modules} |
| 2973 | %The following haven't been moved into a more appropriate section yet. |
| 2974 | |
| 2975 | \section{\module{distutils.debug} --- Distutils debug mode} |
| 2976 | \declaremodule{standard}{distutils.debug} |
| 2977 | \modulesynopsis{Provides the debug flag for distutils} |
| 2978 | |
| 2979 | This module provides the DEBUG flag. |
| 2980 | |
| 2981 | \section{\module{distutils.errors} --- Distutils exceptions} |
| 2982 | \declaremodule{standard}{distutils.errors} |
| 2983 | \modulesynopsis{Provides standard distutils exceptions} |
| 2984 | |
| 2985 | Provides exceptions used by the Distutils modules. Note that Distutils |
| 2986 | modules may raise standard exceptions; in particular, SystemExit is |
| 2987 | usually raised for errors that are obviously the end-user's fault |
| 2988 | (eg. bad command-line arguments). |
| 2989 | |
| 2990 | This module is safe to use in \samp{from ... import *} mode; it only exports |
| 2991 | symbols whose names start with \code{Distutils} and end with \code{Error}. |
| 2992 | |
| 2993 | \section{\module{distutils.fancy_getopt} |
| 2994 | --- Wrapper around the standard getopt module} |
| 2995 | \declaremodule[distutils.fancygetopt]{standard}{distutils.fancy_getopt} |
| 2996 | \modulesynopsis{Additional \module{getopt} functionality} |
| 2997 | |
| 2998 | This module provides a wrapper around the standard \module{getopt} |
| 2999 | module that provides the following additional features: |
| 3000 | |
| 3001 | \begin{itemize} |
| 3002 | \item short and long options are tied together |
| 3003 | \item options have help strings, so \function{fancy_getopt} could potentially |
| 3004 | create a complete usage summary |
| 3005 | \item options set attributes of a passed-in object |
| 3006 | \item boolean options can have ``negative aliases'' --- eg. if |
| 3007 | \longprogramopt{quiet} is the ``negative alias'' of |
| 3008 | \longprogramopt{verbose}, then \longprogramopt{quiet} on the command |
| 3009 | line sets \var{verbose} to false. |
| 3010 | |
| 3011 | \end{itemize} |
| 3012 | |
| 3013 | \XXX{Should be replaced with \module{optik} (which is also now |
| 3014 | known as \module{optparse} in Python 2.3 and later).} |
| 3015 | |
| 3016 | \begin{funcdesc}{fancy_getopt}{options, negative_opt, object, args} |
| 3017 | Wrapper function. \var{options} is a list of |
| 3018 | \samp{(long_option, short_option, help_string)} 3-tuples as described in the |
| 3019 | constructor for \class{FancyGetopt}. \var{negative_opt} should be a dictionary |
| 3020 | mapping option names to option names, both the key and value should be in the |
| 3021 | \var{options} list. \var{object} is an object which will be used to store |
| 3022 | values (see the \method{getopt()} method of the \class{FancyGetopt} class). |
| 3023 | \var{args} is the argument list. Will use \code{sys.argv[1:]} if you |
| 3024 | pass \code{None} as \var{args}. |
| 3025 | \end{funcdesc} |
| 3026 | |
| 3027 | \begin{funcdesc}{wrap_text}{text, width} |
| 3028 | Wraps \var{text} to less than \var{width} wide. |
| 3029 | |
| 3030 | \warning{Should be replaced with \module{textwrap} (which is available |
| 3031 | in Python 2.3 and later).} |
| 3032 | \end{funcdesc} |
| 3033 | |
| 3034 | \begin{classdesc}{FancyGetopt}{\optional{option_table=\code{None}}} |
| 3035 | The option_table is a list of 3-tuples: \samp{(long_option, |
| 3036 | short_option, help_string)} |
| 3037 | |
| 3038 | If an option takes an argument, it's \var{long_option} should have \code{'='} |
| 3039 | appended; \var{short_option} should just be a single character, no \code{':'} |
| 3040 | in any case. \var{short_option} should be \code{None} if a \var{long_option} |
| 3041 | doesn't have a corresponding \var{short_option}. All option tuples must have |
| 3042 | long options. |
| 3043 | \end{classdesc} |
| 3044 | |
| 3045 | The \class{FancyGetopt} class provides the following methods: |
| 3046 | |
| 3047 | \begin{methoddesc}{getopt}{\optional{args=\code{None}, object=\code{None}}} |
| 3048 | Parse command-line options in args. Store as attributes on \var{object}. |
| 3049 | |
| 3050 | If \var{args} is \code{None} or not supplied, uses \code{sys.argv[1:]}. If |
| 3051 | \var{object} is \code{None} or not supplied, creates a new \class{OptionDummy} |
| 3052 | instance, stores option values there, and returns a tuple \samp{(args, |
| 3053 | object)}. If \var{object} is supplied, it is modified in place and |
| 3054 | \function{getopt()} just returns \var{args}; in both cases, the returned |
| 3055 | \var{args} is a modified copy of the passed-in \var{args} list, which |
| 3056 | is left untouched. |
| 3057 | % and args returned are? |
| 3058 | \end{methoddesc} |
| 3059 | |
| 3060 | \begin{methoddesc}{get_option_order}{} |
| 3061 | Returns the list of \samp{(option, value)} tuples processed by the |
| 3062 | previous run of \method{getopt()} Raises \exception{RuntimeError} if |
| 3063 | \method{getopt()} hasn't been called yet. |
| 3064 | \end{methoddesc} |
| 3065 | |
| 3066 | \begin{methoddesc}{generate_help}{\optional{header=\code{None}}} |
| 3067 | Generate help text (a list of strings, one per suggested line of |
| 3068 | output) from the option table for this \class{FancyGetopt} object. |
| 3069 | |
| 3070 | If supplied, prints the supplied \var{header} at the top of the help. |
| 3071 | \end{methoddesc} |
| 3072 | |
| 3073 | \section{\module{distutils.filelist} --- The FileList class} |
| 3074 | \declaremodule{standard}{distutils.filelist} |
| 3075 | \modulesynopsis{The \class{FileList} class, used for poking about the |
| 3076 | file system and building lists of files.} |
| 3077 | |
| 3078 | This module provides the \class{FileList} class, used for poking about |
| 3079 | the filesystem and building lists of files. |
| 3080 | |
| 3081 | |
| 3082 | \section{\module{distutils.log} --- Simple PEP 282-style logging} |
| 3083 | \declaremodule{standard}{distutils.log} |
| 3084 | \modulesynopsis{A simple logging mechanism, \pep{282}-style} |
| 3085 | |
| 3086 | \warning{Should be replaced with standard \module{logging} module.} |
| 3087 | |
| 3088 | %\subsubsection{\module{} --- } |
| 3089 | %\declaremodule{standard}{distutils.magic} |
| 3090 | %\modulesynopsis{ } |
| 3091 | |
| 3092 | |
| 3093 | \section{\module{distutils.spawn} --- Spawn a sub-process} |
| 3094 | \declaremodule{standard}{distutils.spawn} |
| 3095 | \modulesynopsis{Provides the spawn() function} |
| 3096 | |
| 3097 | This module provides the \function{spawn()} function, a front-end to |
| 3098 | various platform-specific functions for launching another program in a |
| 3099 | sub-process. |
| 3100 | Also provides \function{find_executable()} to search the path for a given |
| 3101 | executable name. |
| 3102 | |
| 3103 | |
Fred Drake | ab70b38 | 2001-08-02 15:13:15 +0000 | [diff] [blame] | 3104 | \input{sysconfig} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 3105 | |
| 3106 | |
Fred Drake | 6fca7cc | 2004-03-23 18:43:03 +0000 | [diff] [blame^] | 3107 | \section{\module{distutils.text_file} --- The TextFile class} |
| 3108 | \declaremodule[distutils.textfile]{standard}{distutils.text_file} |
| 3109 | \modulesynopsis{provides the TextFile class, a simple interface to text files} |
| 3110 | |
| 3111 | This module provides the \class{TextFile} class, which gives an interface |
| 3112 | to text files that (optionally) takes care of stripping comments, ignoring |
| 3113 | blank lines, and joining lines with backslashes. |
| 3114 | |
| 3115 | \begin{classdesc}{TextFile}{\optional{filename=\code{None}, file=\code{None}, **options}} |
| 3116 | This class provides a file-like object that takes care of all |
| 3117 | the things you commonly want to do when processing a text file |
| 3118 | that has some line-by-line syntax: strip comments (as long as \code{\#} |
| 3119 | is your comment character), skip blank lines, join adjacent lines by |
| 3120 | escaping the newline (ie. backslash at end of line), strip |
| 3121 | leading and/or trailing whitespace. All of these are optional |
| 3122 | and independently controllable. |
| 3123 | |
| 3124 | The class provides a \method{warn()} method so you can generate |
| 3125 | warning messages that report physical line number, even if the |
| 3126 | logical line in question spans multiple physical lines. Also |
| 3127 | provides \method{unreadline()} for implementing line-at-a-time lookahead. |
| 3128 | |
| 3129 | \class{TextFile} instances are create with either \var{filename}, \var{file}, |
| 3130 | or both. \exception{RuntimeError} is raised if both are \code{None}. |
| 3131 | \var{filename} should be a string, and \var{file} a file object (or |
| 3132 | something that provides \method{readline()} and \method{close()} |
| 3133 | methods). It is recommended that you supply at least \var{filename}, |
| 3134 | so that \class{TextFile} can include it in warning messages. If |
| 3135 | \var{file} is not supplied, TextFile creates its own using the |
| 3136 | \var{open()} builtin. |
| 3137 | |
| 3138 | The options are all boolean, and affect the values returned by |
| 3139 | \var{readline()} |
| 3140 | |
| 3141 | \begin{tableiii}{c|l|l}{option name}{option name}{description}{default} |
| 3142 | \lineiii{strip_comments}{ |
| 3143 | strip from \character{\#} to end-of-line, as well as any whitespace |
| 3144 | leading up to the \character{\#}---unless it is escaped by a backslash} |
| 3145 | {true} |
| 3146 | \lineiii{lstrip_ws}{ |
| 3147 | strip leading whitespace from each line before returning it} |
| 3148 | {false} |
| 3149 | \lineiii{rstrip_ws}{ |
| 3150 | strip trailing whitespace (including line terminator!) from |
| 3151 | each line before returning it.} |
| 3152 | {true} |
| 3153 | \lineiii{skip_blanks}{ |
| 3154 | skip lines that are empty *after* stripping comments and |
| 3155 | whitespace. (If both lstrip_ws and rstrip_ws are false, |
| 3156 | then some lines may consist of solely whitespace: these will |
| 3157 | *not* be skipped, even if \var{skip_blanks} is true.)} |
| 3158 | {true} |
| 3159 | \lineiii{join_lines}{ |
| 3160 | if a backslash is the last non-newline character on a line |
| 3161 | after stripping comments and whitespace, join the following line |
| 3162 | to it to form one logical line; if N consecutive lines end |
| 3163 | with a backslash, then N+1 physical lines will be joined to |
| 3164 | form one logical line.} |
| 3165 | {false} |
| 3166 | \lineiii{collapse_join}{ |
| 3167 | strip leading whitespace from lines that are joined to their |
| 3168 | predecessor; only matters if \samp{(join_lines and not lstrip_ws)}} |
| 3169 | {false} |
| 3170 | \end{tableiii} |
| 3171 | |
| 3172 | Note that since \var{rstrip_ws} can strip the trailing newline, the |
| 3173 | semantics of \method{readline()} must differ from those of the builtin file |
| 3174 | object's \method{readline()} method! In particular, \method{readline()} |
| 3175 | returns \code{None} for end-of-file: an empty string might just be a |
| 3176 | blank line (or an all-whitespace line), if \var{rstrip_ws} is true |
| 3177 | but \var{skip_blanks} is not. |
| 3178 | |
| 3179 | \begin{methoddesc}{open}{filename} |
| 3180 | Open a new file \var{filename}. This overrides any \var{file} or |
| 3181 | \var{filename} constructor arguments. |
| 3182 | \end{methoddesc} |
| 3183 | |
| 3184 | \begin{methoddesc}{close}{} |
| 3185 | Close the current file and forget everything we know about it (including |
| 3186 | the filename and the current line number). |
| 3187 | \end{methoddesc} |
| 3188 | |
| 3189 | \begin{methoddesc}{warn}{msg\optional{,line=\code{None}}} |
| 3190 | Print (to stderr) a warning message tied to the current logical |
| 3191 | line in the current file. If the current logical line in the |
| 3192 | file spans multiple physical lines, the warning refers to the |
| 3193 | whole range, such as \samp{"lines 3-5"}. If \var{line} is supplied, |
| 3194 | it overrides the current line number; it may be a list or tuple |
| 3195 | to indicate a range of physical lines, or an integer for a |
| 3196 | single physical line. |
| 3197 | \end{methoddesc} |
| 3198 | |
| 3199 | \begin{methoddesc}{readline}{} |
| 3200 | Read and return a single logical line from the current file (or |
| 3201 | from an internal buffer if lines have previously been ``unread'' |
| 3202 | with \method{unreadline()}). If the \var{join_lines} option |
| 3203 | is true, this may involve reading multiple physical lines |
| 3204 | concatenated into a single string. Updates the current line number, |
| 3205 | so calling \method{warn()} after \method{readline()} emits a warning |
| 3206 | about the physical line(s) just read. Returns \code{None} on end-of-file, |
| 3207 | since the empty string can occur if \var{rstrip_ws} is true but |
| 3208 | \var{strip_blanks} is not. |
| 3209 | \end{methoddesc} |
| 3210 | \begin{methoddesc}{readlines}{} |
| 3211 | Read and return the list of all logical lines remaining in the current file. |
| 3212 | This updates the current line number to the last line of the file. |
| 3213 | \end{methoddesc} |
| 3214 | \begin{methoddesc}{unreadline}{line} |
| 3215 | Push \var{line} (a string) onto an internal buffer that will be |
| 3216 | checked by future \method{readline()} calls. Handy for implementing |
| 3217 | a parser with line-at-a-time lookahead. Note that lines that are ``unread'' |
| 3218 | with \method{unreadline} are not subsequently re-cleansed (whitespace |
| 3219 | stripped, or whatever) when read with \method{readline}. If multiple |
| 3220 | calls are made to \method{unreadline} before a call to \method{readline}, |
| 3221 | the lines will be returned most in most recent first order. |
| 3222 | \end{methoddesc} |
| 3223 | |
| 3224 | \end{classdesc} |
| 3225 | |
| 3226 | |
| 3227 | \section{\module{distutils.version} --- Version number classes} |
| 3228 | \declaremodule{standard}{distutils.version} |
| 3229 | \modulesynopsis{implements classes that represent module version numbers. } |
| 3230 | |
| 3231 | % todo |
| 3232 | |
| 3233 | %\section{Distutils Commands} |
| 3234 | % |
| 3235 | %This part of Distutils implements the various Distutils commands, such |
| 3236 | %as \code{build}, \code{install} \&c. Each command is implemented as a |
| 3237 | %separate module, with the command name as the name of the module. |
| 3238 | |
| 3239 | \section{\module{distutils.cmd} --- Abstract base class for Distutils commands} |
| 3240 | \declaremodule{standard}{distutils.cmd} |
| 3241 | \modulesynopsis{This module provides the abstract base class Command. This |
| 3242 | class is subclassed by the modules in the \refmodule{distutils.command} |
| 3243 | subpackage. } |
| 3244 | |
| 3245 | This module supplies the abstract base class \class{Command}. |
| 3246 | |
| 3247 | \begin{classdesc}{Command}{dist} |
| 3248 | Abstract base class for defining command classes, the ``worker bees'' |
| 3249 | of the Distutils. A useful analogy for command classes is to think of |
| 3250 | them as subroutines with local variables called \var{options}. The |
| 3251 | options are declared in \method{initialize_options()} and defined |
| 3252 | (given their final values) in \method{finalize_options()}, both of |
| 3253 | which must be defined by every command class. The distinction between |
| 3254 | the two is necessary because option values might come from the outside |
| 3255 | world (command line, config file, ...), and any options dependent on |
| 3256 | other options must be computed after these outside influences have |
| 3257 | been processed --- hence \method{finalize_options()}. The body of the |
| 3258 | subroutine, where it does all its work based on the values of its |
| 3259 | options, is the \method{run()} method, which must also be implemented |
| 3260 | by every command class. |
| 3261 | |
| 3262 | The class constructor takes a single argument \var{dist}, a |
| 3263 | \class{Distribution} instance. |
| 3264 | \end{classdesc} |
| 3265 | |
| 3266 | |
| 3267 | \section{\module{distutils.command} --- Individual Distutils commands} |
| 3268 | \declaremodule{standard}{distutils.command} |
| 3269 | \modulesynopsis{This subpackage contains one module for each standard Distutils command.} |
| 3270 | |
| 3271 | %\subsubsection{Individual Distutils commands} |
| 3272 | |
| 3273 | % todo |
| 3274 | |
| 3275 | \section{\module{distutils.command.bdist} --- Build a binary installer} |
| 3276 | \declaremodule{standard}{distutils.command.bdist} |
| 3277 | \modulesynopsis{Build a binary installer for a package} |
| 3278 | |
| 3279 | % todo |
| 3280 | |
| 3281 | \section{\module{distutils.command.bdist_packager} --- Abstract base class for packagers} |
| 3282 | \declaremodule[distutils.command.bdistpackager]{standard}{distutils.command.bdist_packager} |
| 3283 | \modulesynopsis{Abstract base class for packagers} |
| 3284 | |
| 3285 | % todo |
| 3286 | |
| 3287 | \section{\module{distutils.command.bdist_dumb} --- Build a ``dumb'' installer} |
| 3288 | \declaremodule[distutils.command.bdistdumb]{standard}{distutils.command.bdist_dumb} |
| 3289 | \modulesynopsis{Build a ``dumb'' installer - a simple archive of files} |
| 3290 | |
| 3291 | % todo |
| 3292 | |
| 3293 | |
| 3294 | \section{\module{distutils.command.bdist_rpm} --- Build a binary distribution as a Redhat RPM and SRPM} |
| 3295 | \declaremodule[distutils.command.bdistrpm]{standard}{distutils.command.bdist_rpm} |
| 3296 | \modulesynopsis{Build a binary distribution as a Redhat RPM and SRPM} |
| 3297 | |
| 3298 | % todo |
| 3299 | |
| 3300 | \section{\module{distutils.command.bdist_wininst} --- Build a Windows installer} |
| 3301 | \declaremodule[distutils.command.bdistwininst]{standard}{distutils.command.bdist_wininst} |
| 3302 | \modulesynopsis{Build a Windows installer} |
| 3303 | |
| 3304 | % todo |
| 3305 | |
| 3306 | \section{\module{distutils.command.sdist} --- Build a source distribution} |
| 3307 | \declaremodule{standard}{distutils.command.sdist} |
| 3308 | \modulesynopsis{Build a source distribution} |
| 3309 | |
| 3310 | % todo |
| 3311 | |
| 3312 | \section{\module{distutils.command.build} --- Build all files of a package} |
| 3313 | \declaremodule{standard}{distutils.command.build} |
| 3314 | \modulesynopsis{Build all files of a package} |
| 3315 | |
| 3316 | % todo |
| 3317 | |
| 3318 | \section{\module{distutils.command.build_clib} --- Build any C libraries in a package} |
| 3319 | \declaremodule[distutils.command.buildclib]{standard}{distutils.command.build_clib} |
| 3320 | \modulesynopsis{Build any C libraries in a package} |
| 3321 | |
| 3322 | % todo |
| 3323 | |
| 3324 | \section{\module{distutils.command.build_ext} --- Build any extensions in a package} |
| 3325 | \declaremodule[distutils.command.buildext]{standard}{distutils.command.build_ext} |
| 3326 | \modulesynopsis{Build any extensions in a package} |
| 3327 | |
| 3328 | % todo |
| 3329 | |
| 3330 | \section{\module{distutils.command.build_py} --- Build the .py/.pyc files of a package} |
| 3331 | \declaremodule[distutils.command.buildpy]{standard}{distutils.command.build_py} |
| 3332 | \modulesynopsis{Build the .py/.pyc files of a package} |
| 3333 | |
| 3334 | % todo |
| 3335 | |
| 3336 | \section{\module{distutils.command.build_scripts} --- Build the scripts of a package} |
| 3337 | \declaremodule[distutils.command.buildscripts]{standard}{distutils.command.build_scripts} |
| 3338 | \modulesynopsis{Build the scripts of a package} |
| 3339 | |
| 3340 | % todo |
| 3341 | |
| 3342 | \section{\module{distutils.command.clean} --- Clean a package build area} |
| 3343 | \declaremodule{standard}{distutils.command.clean} |
| 3344 | \modulesynopsis{Clean a package build area} |
| 3345 | |
| 3346 | % todo |
| 3347 | |
| 3348 | \section{\module{distutils.command.config} --- Perform package configuration} |
| 3349 | \declaremodule{standard}{distutils.command.config} |
| 3350 | \modulesynopsis{Perform package configuration} |
| 3351 | |
| 3352 | % todo |
| 3353 | |
| 3354 | \subsubsection{\module{distutils.command.install} --- Install a package} |
| 3355 | \declaremodule{standard}{distutils.command.install} |
| 3356 | \modulesynopsis{Install a package} |
| 3357 | |
| 3358 | % todo |
| 3359 | |
| 3360 | \subsubsection{\module{distutils.command.install_data} |
| 3361 | --- Install data files from a package} |
| 3362 | \declaremodule[distutils.command.installdata]{standard}{distutils.command.install_data} |
| 3363 | \modulesynopsis{Install data files from a package} |
| 3364 | |
| 3365 | % todo |
| 3366 | |
| 3367 | \subsubsection{\module{distutils.command.install_headers} |
| 3368 | --- Install C/\Cpp{} header files from a package} |
| 3369 | \declaremodule[distutils.command.installheaders]{standard}{distutils.command.install_headers} |
| 3370 | \modulesynopsis{Install C/\Cpp{} header files from a package} |
| 3371 | |
| 3372 | % todo |
| 3373 | |
| 3374 | \subsubsection{\module{distutils.command.install_lib} |
| 3375 | --- Install library files from a package} |
| 3376 | \declaremodule[distutils.command.installlib]{standard}{distutils.command.install_lib} |
| 3377 | \modulesynopsis{Install library files from a package} |
| 3378 | |
| 3379 | % todo |
| 3380 | |
| 3381 | \subsubsection{\module{distutils.command.install_scripts} |
| 3382 | --- Install script files from a package} |
| 3383 | \declaremodule[distutils.command.installscripts]{standard}{distutils.command.install_scripts} |
| 3384 | \modulesynopsis{Install script files from a package} |
| 3385 | |
| 3386 | % todo |
| 3387 | |
| 3388 | \subsubsection{\module{distutils.command.register} |
| 3389 | --- Register a module with the Python Package Index} |
| 3390 | \declaremodule{standard}{distutils.command.register} |
| 3391 | \modulesynopsis{Register a module with the Python Package Index} |
| 3392 | |
| 3393 | The \code{register} command registers the package with the Python Package |
| 3394 | Index. This is described in more detail in \pep{301}. |
| 3395 | % todo |
| 3396 | |
| 3397 | \subsubsection{Creating a new Distutils command} |
| 3398 | |
| 3399 | This section outlines the steps to create a new Distutils command. |
| 3400 | |
| 3401 | A new command lives in a module in the \module{distutils.command} |
| 3402 | package. There is a sample template in that directory called |
| 3403 | \file{command_template}. Copy this file to a new module with the |
| 3404 | same name as the new command you're implementing. This module should |
| 3405 | implement a class with the same name as the module (and the command). |
| 3406 | So, for instance, to create the command \code{peel_banana} (so that users |
| 3407 | can run \samp{setup.py peel_banana}), you'd copy \file{command_template} |
| 3408 | to \file{distutils/command/peel_banana.py}, then edit it so that it's |
| 3409 | implementing the class \class{peel_banana}, a subclass of |
| 3410 | \class{distutils.cmd.Command}. |
| 3411 | |
| 3412 | Subclasses of \class{Command} must define the following methods. |
| 3413 | |
| 3414 | \begin{methoddesc}{initialize_options()} |
| 3415 | Set default values for all the options that this command |
| 3416 | supports. Note that these defaults may be overridden by other |
| 3417 | commands, by the setup script, by config files, or by the |
| 3418 | command-line. Thus, this is not the place to code dependencies |
| 3419 | between options; generally, \method{initialize_options()} implementations |
| 3420 | are just a bunch of \samp{self.foo = None} assignments. |
| 3421 | \end{methoddesc} |
| 3422 | |
| 3423 | \begin{methoddesc}{finalize_options}{} |
| 3424 | Set final values for all the options that this command supports. |
| 3425 | This is always called as late as possible, ie. after any option |
| 3426 | assignments from the command-line or from other commands have been |
| 3427 | done. Thus, this is the place to to code option dependencies: if |
| 3428 | \var{foo} depends on \var{bar}, then it is safe to set \var{foo} from |
| 3429 | \var{bar} as long as \var{foo} still has the same value it was assigned in |
| 3430 | \method{initialize_options()}. |
| 3431 | \end{methoddesc} |
| 3432 | \begin{methoddesc}{run}{} |
| 3433 | A command's raison d'etre: carry out the action it exists to |
| 3434 | perform, controlled by the options initialized in |
| 3435 | \method{initialize_options()}, customized by other commands, the setup |
| 3436 | script, the command-line, and config files, and finalized in |
| 3437 | \method{finalize_options()}. All terminal output and filesystem |
| 3438 | interaction should be done by \method{run()}. |
| 3439 | \end{methoddesc} |
| 3440 | |
| 3441 | \var{sub_commands} formalizes the notion of a ``family'' of commands, |
| 3442 | eg. \code{install} as the parent with sub-commands \code{install_lib}, |
| 3443 | \code{install_headers}, etc. The parent of a family of commands |
| 3444 | defines \var{sub_commands} as a class attribute; it's a list of |
| 3445 | 2-tuples \samp{(command_name, predicate)}, with \var{command_name} a string |
| 3446 | and \var{predicate} an unbound method, a string or None. |
| 3447 | \var{predicate} is a method of the parent command that |
| 3448 | determines whether the corresponding command is applicable in the |
| 3449 | current situation. (Eg. we \code{install_headers} is only applicable if |
| 3450 | we have any C header files to install.) If \var{predicate} is None, |
| 3451 | that command is always applicable. |
| 3452 | |
| 3453 | \var{sub_commands} is usually defined at the *end* of a class, because |
| 3454 | predicates can be unbound methods, so they must already have been |
| 3455 | defined. The canonical example is the \command{install} command. |
| 3456 | |
| 3457 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 3458 | \end{document} |