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