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