Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
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 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 6 | \title{Distributing Python Modules} |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 7 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 8 | \author{Greg Ward} |
Fred Drake | 17f690f | 2001-07-14 02:14:42 +0000 | [diff] [blame^] | 9 | \authoraddress{Email: \email{gward@python.net}} |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 10 | |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 11 | \makeindex |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 12 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 13 | \begin{document} |
| 14 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 15 | \maketitle |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 16 | \begin{abstract} |
| 17 | \noindent |
| 18 | This document describes the Python Distribution Utilities |
| 19 | (``Distutils'') from the module developer's point-of-view, describing |
| 20 | how to use the Distutils to make Python modules and extensions easily |
| 21 | available to a wider audience with very little overhead for |
| 22 | build/release/install mechanics. |
| 23 | \end{abstract} |
| 24 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 25 | % The ugly "%begin{latexonly}" pseudo-environment supresses the table |
| 26 | % of contents for HTML generation. |
| 27 | % |
| 28 | %begin{latexonly} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 29 | \tableofcontents |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 30 | %end{latexonly} |
| 31 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 32 | |
| 33 | \section{Introduction} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 34 | \label{intro} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 35 | |
| 36 | In the past, Python module developers have not had much infrastructure |
| 37 | support for distributing modules, nor have Python users had much support |
| 38 | for installing and maintaining third-party modules. With the |
| 39 | introduction of the Python Distribution Utilities (Distutils for short) |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 40 | in Python 1.6, this situation should start to improve. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 41 | |
| 42 | This document only covers using the Distutils to distribute your Python |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 43 | modules. Using the Distutils does not tie you to Python 1.6, though: |
| 44 | the Distutils work just fine with Python 1.5.2, and it is reasonable |
| 45 | (and expected to become commonplace) to expect users of Python 1.5.2 to |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 46 | download and install the Distutils separately before they can install |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 47 | your modules. Python 1.6 (or later) users, of course, won't have to add |
| 48 | anything to their Python installation in order to use the Distutils to |
| 49 | install third-party modules. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 50 | |
| 51 | This document concentrates on the role of developer/distributor: if |
Fred Drake | 01df453 | 2000-06-30 03:36:41 +0000 | [diff] [blame] | 52 | you're looking for information on installing Python modules, you |
| 53 | should refer to the \citetitle[../inst/inst.html]{Installing Python |
| 54 | Modules} manual. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 55 | |
| 56 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 57 | \section{Concepts \& Terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 58 | \label{concepts} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 59 | |
| 60 | Using the Distutils is quite simple, both for module developers and for |
| 61 | users/administrators installing third-party modules. As a developer, |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 62 | your responsibilities (apart from writing solid, well-documented and |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 63 | well-tested code, of course!) are: |
| 64 | \begin{itemize} |
| 65 | \item write a setup script (\file{setup.py} by convention) |
| 66 | \item (optional) write a setup configuration file |
| 67 | \item create a source distribution |
| 68 | \item (optional) create one or more built (binary) distributions |
| 69 | \end{itemize} |
| 70 | Each of these tasks is covered in this document. |
| 71 | |
| 72 | Not all module developers have access to a multitude of platforms, so |
| 73 | it's not always feasible to expect them to create a multitude of built |
| 74 | distributions. It is hoped that a class of intermediaries, called |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 75 | \emph{packagers}, will arise to address this need. Packagers will take |
| 76 | source distributions released by module developers, build them on one or |
| 77 | more platforms, and release the resulting built distributions. Thus, |
| 78 | users on the most popular platforms will be able to install most popular |
| 79 | Python module distributions in the most natural way for their platform, |
| 80 | 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] | 81 | |
| 82 | |
| 83 | \subsection{A simple example} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 84 | \label{simple-example} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 85 | |
| 86 | The setup script is usually quite simple, although since it's written in |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 87 | Python, there are no arbitrary limits to what you can do with |
| 88 | it.\footnote{But be careful about putting arbitrarily expensive |
| 89 | operations in your setup script; unlike, say, Autoconf-style configure |
| 90 | scripts, the setup script may be run multiple times in the course of |
| 91 | building and installing your module distribution. If you need to |
| 92 | insert potentially expensive processing steps into the Distutils |
| 93 | chain, see section~\ref{extending} on extending the Distutils.} If |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 94 | all you want to do is distribute a module called \module{foo}, contained |
| 95 | in a file \file{foo.py}, then your setup script can be as little as |
| 96 | 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 | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 100 | setup(name="foo", |
| 101 | version="1.0", |
| 102 | py_modules=["foo"]) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 103 | \end{verbatim} |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 104 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 105 | Some observations: |
| 106 | \begin{itemize} |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 107 | \item most information that you supply to the Distutils is supplied as |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 108 | keyword arguments to the \function{setup()} function |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 109 | \item those keyword arguments fall into two categories: package |
| 110 | meta-data (name, version number) and information about what's in the |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 111 | package (a list of pure Python modules, in this case) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 112 | \item modules are specified by module name, not filename (the same will |
| 113 | hold true for packages and extensions) |
| 114 | \item it's recommended that you supply a little more meta-data, in |
| 115 | particular your name, email address and a URL for the project |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 116 | (see section~\ref{setup-script} for an example) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 117 | \end{itemize} |
| 118 | |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 119 | To create a source distribution for this module, you would create a |
| 120 | setup script, \file{setup.py}, containing the above code, and run: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 121 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 122 | \begin{verbatim} |
| 123 | python setup.py sdist |
| 124 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 125 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 126 | which will create an archive file (e.g., tarball on \UNIX, ZIP file on |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 127 | Windows) containing your setup script, \file{setup.py}, and your module, |
| 128 | \file{foo.py}. The archive file will be named \file{Foo-1.0.tar.gz} (or |
| 129 | \file{.zip}), and will unpack into a directory \file{Foo-1.0}. |
| 130 | |
| 131 | If an end-user wishes to install your \module{foo} module, all she has |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 132 | to do is download \file{Foo-1.0.tar.gz} (or \file{.zip}), unpack it, |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 133 | and---from the \file{Foo-1.0} directory---run |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 134 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 135 | \begin{verbatim} |
| 136 | python setup.py install |
| 137 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 138 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 139 | which will ultimately copy \file{foo.py} to the appropriate directory |
| 140 | for third-party modules in their Python installation. |
| 141 | |
| 142 | This simple example demonstrates some fundamental concepts of the |
| 143 | Distutils: first, both developers and installers have the same basic |
| 144 | user interface, i.e. the setup script. The difference is which |
| 145 | Distutils \emph{commands} they use: the \command{sdist} command is |
| 146 | almost exclusively for module developers, while \command{install} is |
| 147 | more often for installers (although most developers will want to install |
| 148 | their own code occasionally). |
| 149 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 150 | If you want to make things really easy for your users, you can create |
| 151 | one or more built distributions for them. For instance, if you are |
| 152 | running on a Windows machine, and want to make things easy for other |
| 153 | Windows users, you can create an executable installer (the most |
| 154 | appropriate type of built distribution for this platform) with the |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 155 | \command{bdist\_wininst} command. For example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 156 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 157 | \begin{verbatim} |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 158 | python setup.py bdist_wininst |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 159 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 160 | |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 161 | will create an executable installer, \file{Foo-1.0.win32.exe}, in the |
| 162 | current directory. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 163 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 164 | Currently (Distutils 0.9.2), the only other useful built |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 165 | distribution format is RPM, implemented by the \command{bdist\_rpm} |
| 166 | command. For example, the following command will create an RPM file |
| 167 | called \file{Foo-1.0.noarch.rpm}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 168 | |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 169 | \begin{verbatim} |
| 170 | python setup.py bdist_rpm |
| 171 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 172 | |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 173 | (This uses the \command{rpm} command, so has to be run on an RPM-based |
| 174 | system such as Red Hat Linux, SuSE Linux, or Mandrake Linux.) |
| 175 | |
| 176 | You can find out what distribution formats are available at any time by |
| 177 | running |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 178 | |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 179 | \begin{verbatim} |
| 180 | python setup.py bdist --help-formats |
| 181 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 182 | |
| 183 | |
| 184 | \subsection{General Python terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 185 | \label{python-terms} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 186 | |
| 187 | If you're reading this document, you probably have a good idea of what |
| 188 | modules, extensions, and so forth are. Nevertheless, just to be sure |
| 189 | that everyone is operating from a common starting point, we offer the |
| 190 | following glossary of common Python terms: |
| 191 | \begin{description} |
| 192 | \item[module] the basic unit of code reusability in Python: a block of |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 193 | code imported by some other code. Three types of modules concern us |
| 194 | here: pure Python modules, extension modules, and packages. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 195 | \item[pure Python module] a module written in Python and contained in a |
| 196 | single \file{.py} file (and possibly associated \file{.pyc} and/or |
| 197 | \file{.pyo} files). Sometimes referred to as a ``pure module.'' |
| 198 | \item[extension module] a module written in the low-level language of |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 199 | the Python implementation: C/C++ for Python, Java for JPython. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 200 | Typically contained in a single dynamically loadable pre-compiled |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 201 | file, e.g. a shared object (\file{.so}) file for Python extensions on |
| 202 | \UNIX, a DLL (given the \file{.pyd} extension) for Python extensions |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 203 | on Windows, or a Java class file for JPython extensions. (Note that |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 204 | currently, the Distutils only handles C/C++ extensions for Python.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 205 | \item[package] a module that contains other modules; typically contained |
| 206 | in a directory in the filesystem and distinguished from other |
| 207 | directories by the presence of a file \file{\_\_init\_\_.py}. |
Greg Ward | 6153fa1 | 2000-05-26 02:24:28 +0000 | [diff] [blame] | 208 | \item[root package] the root of the hierarchy of packages. (This isn't |
| 209 | really a package, since it doesn't have an \file{\_\_init\_\_.py} |
| 210 | file. But we have to call it something.) The vast majority of the |
| 211 | standard library is in the root package, as are many small, standalone |
| 212 | third-party modules that don't belong to a larger module collection. |
| 213 | Unlike regular packages, modules in the root package can be found in |
| 214 | many directories: in fact, every directory listed in \code{sys.path} |
| 215 | can contribute modules to the root package. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 216 | \end{description} |
| 217 | |
| 218 | |
| 219 | \subsection{Distutils-specific terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 220 | \label{distutils-term} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 221 | |
| 222 | The following terms apply more specifically to the domain of |
| 223 | distributing Python modules using the Distutils: |
| 224 | \begin{description} |
| 225 | \item[module distribution] a collection of Python modules distributed |
| 226 | together as a single downloadable resource and meant to be installed |
| 227 | \emph{en masse}. Examples of some well-known module distributions are |
| 228 | Numeric Python, PyXML, PIL (the Python Imaging Library), or |
| 229 | mxDateTime. (This would be called a \emph{package}, except that term |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 230 | is already taken in the Python context: a single module distribution |
| 231 | may contain zero, one, or many Python packages.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 232 | \item[pure module distribution] a module distribution that contains only |
| 233 | pure Python modules and packages. Sometimes referred to as a ``pure |
| 234 | distribution.'' |
| 235 | \item[non-pure module distribution] a module distribution that contains |
| 236 | at least one extension module. Sometimes referred to as a ``non-pure |
| 237 | distribution.'' |
| 238 | \item[distribution root] the top-level directory of your source tree (or |
| 239 | source distribution); the directory where \file{setup.py} exists and |
| 240 | is run from |
| 241 | \end{description} |
| 242 | |
| 243 | |
| 244 | \section{Writing the Setup Script} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 245 | \label{setup-script} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 246 | |
| 247 | The setup script is the centre of all activity in building, |
| 248 | distributing, and installing modules using the Distutils. The main |
| 249 | purpose of the setup script is to describe your module distribution to |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 250 | the Distutils, so that the various commands that operate on your modules |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 251 | do the right thing. As we saw in section~\ref{simple-example} above, |
| 252 | the setup script consists mainly of a call to \function{setup()}, and |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 253 | most information supplied to the Distutils by the module developer is |
| 254 | supplied as keyword arguments to \function{setup()}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 255 | |
| 256 | Here's a slightly more involved example, which we'll follow for the next |
| 257 | couple of sections: the Distutils' own setup script. (Keep in mind that |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 258 | although the Distutils are included with Python 1.6 and later, they also |
| 259 | have an independent existence so that Python 1.5.2 users can use them to |
| 260 | install other module distributions. The Distutils' own setup script, |
| 261 | 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] | 262 | |
| 263 | \begin{verbatim} |
| 264 | #!/usr/bin/env python |
| 265 | |
| 266 | from distutils.core import setup |
| 267 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 268 | setup(name="Distutils", |
| 269 | version="1.0", |
| 270 | description="Python Distribution Utilities", |
| 271 | author="Greg Ward", |
| 272 | author_email="gward@python.net", |
| 273 | url="http://www.python.org/sigs/distutils-sig/", |
| 274 | packages=['distutils', 'distutils.command'], |
| 275 | ) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 276 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 277 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 278 | There are only two differences between this and the trivial one-file |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 279 | distribution presented in section~\ref{simple-example}: more |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 280 | meta-data, and the specification of pure Python modules by package, |
| 281 | rather than by module. This is important since the Distutils consist of |
| 282 | a couple of dozen modules split into (so far) two packages; an explicit |
| 283 | list of every module would be tedious to generate and difficult to |
| 284 | maintain. |
| 285 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 286 | Note that any pathnames (files or directories) supplied in the setup |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 287 | script should be written using the \UNIX{} convention, i.e. |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 288 | slash-separated. The Distutils will take care of converting this |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 289 | platform-neutral representation into whatever is appropriate on your |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 290 | current platform before actually using the pathname. This makes your |
| 291 | setup script portable across operating systems, which of course is one |
| 292 | of the major goals of the Distutils. In this spirit, all pathnames in |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 293 | this document are slash-separated (MacOS programmers should keep in |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 294 | mind that the \emph{absence} of a leading slash indicates a relative |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 295 | path, the opposite of the MacOS convention with colons). |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 296 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 297 | This, of course, only applies to pathnames given to Distutils functions. |
| 298 | If you, for example, use standard python functions such as glob.glob |
| 299 | or os.listdir to specify files, you should be careful to write portable |
| 300 | code instead of hardcoding path separators: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 301 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 302 | \begin{verbatim} |
| 303 | glob.glob(os.path.join('mydir', 'subdir', '*.html')) |
| 304 | os.listdir(os.path.join('mydir', 'subdir')) |
| 305 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 306 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 307 | \subsection{Listing whole packages} |
| 308 | \label{listing-packages} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 309 | |
| 310 | The \option{packages} option tells the Distutils to process (build, |
| 311 | distribute, install, etc.) all pure Python modules found in each package |
| 312 | mentioned in the \option{packages} list. In order to do this, of |
| 313 | course, there has to be a correspondence between package names and |
| 314 | directories in the filesystem. The default correspondence is the most |
Greg Ward | 1ecc251 | 2000-04-19 22:36:24 +0000 | [diff] [blame] | 315 | obvious one, i.e. package \module{distutils} is found in the directory |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 316 | \file{distutils} relative to the distribution root. Thus, when you say |
| 317 | \code{packages = ['foo']} in your setup script, you are promising that |
| 318 | the Distutils will find a file \file{foo/\_\_init\_\_.py} (which might |
| 319 | be spelled differently on your system, but you get the idea) relative to |
| 320 | the directory where your setup script lives. (If you break this |
| 321 | promise, the Distutils will issue a warning but process the broken |
| 322 | package anyways.) |
| 323 | |
| 324 | If you use a different convention to lay out your source directory, |
| 325 | that's no problem: you just have to supply the \option{package\_dir} |
| 326 | option to tell the Distutils about your convention. For example, say |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 327 | you keep all Python source under \file{lib}, so that modules in the |
| 328 | ``root package'' (i.e., not in any package at all) are right in |
| 329 | \file{lib}, modules in the \module{foo} package are in \file{lib/foo}, |
| 330 | and so forth. Then you would put |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 331 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 332 | \begin{verbatim} |
| 333 | package_dir = {'': 'lib'} |
| 334 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 335 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 336 | in your setup script. (The keys to this dictionary are package names, |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 337 | and an empty package name stands for the root package. The values are |
| 338 | directory names relative to your distribution root.) In this case, when |
| 339 | you say \code{packages = ['foo']}, you are promising that the file |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 340 | \file{lib/foo/\_\_init\_\_.py} exists. |
| 341 | |
Greg Ward | 1ecc251 | 2000-04-19 22:36:24 +0000 | [diff] [blame] | 342 | Another possible convention is to put the \module{foo} package right in |
| 343 | \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] | 344 | would be written in the setup script as |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 345 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 346 | \begin{verbatim} |
| 347 | package_dir = {'foo': 'lib'} |
| 348 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 349 | |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 350 | A \code{\var{package}: \var{dir}} entry in the \option{package\_dir} |
| 351 | dictionary implicitly applies to all packages below \var{package}, so |
| 352 | the \module{foo.bar} case is automatically handled here. In this |
| 353 | example, having \code{packages = ['foo', 'foo.bar']} tells the Distutils |
| 354 | to look for \file{lib/\_\_init\_\_.py} and |
| 355 | \file{lib/bar/\_\_init\_\_.py}. (Keep in mind that although |
| 356 | \option{package\_dir} applies recursively, you must explicitly list all |
| 357 | packages in \option{packages}: the Distutils will \emph{not} recursively |
| 358 | scan your source tree looking for any directory with an |
| 359 | \file{\_\_init\_\_.py} file.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 360 | |
| 361 | |
| 362 | \subsection{Listing individual modules} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 363 | \label{listing-modules} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 364 | |
| 365 | For a small module distribution, you might prefer to list all modules |
| 366 | rather than listing packages---especially the case of a single module |
| 367 | 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] | 368 | simplest case was shown in section~\ref{simple-example}; here is a |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 369 | slightly more involved example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 370 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 371 | \begin{verbatim} |
| 372 | py_modules = ['mod1', 'pkg.mod2'] |
| 373 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 374 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 375 | This describes two modules, one of them in the ``root'' package, the |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 376 | other in the \module{pkg} package. Again, the default package/directory |
| 377 | layout implies that these two modules can be found in \file{mod1.py} and |
| 378 | \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] | 379 | And again, you can override the package/directory correspondence using |
| 380 | the \option{package\_dir} option. |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 381 | |
| 382 | |
| 383 | \subsection{Describing extension modules} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 384 | \label{describing-extensions} |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 385 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 386 | Just as writing Python extension modules is a bit more complicated than |
| 387 | writing pure Python modules, describing them to the Distutils is a bit |
| 388 | more complicated. Unlike pure modules, it's not enough just to list |
| 389 | modules or packages and expect the Distutils to go out and find the |
| 390 | right files; you have to specify the extension name, source file(s), and |
| 391 | any compile/link requirements (include directories, libraries to link |
| 392 | with, etc.). |
| 393 | |
| 394 | All of this is done through another keyword argument to |
| 395 | \function{setup()}, the \option{extensions} option. \option{extensions} |
| 396 | is just a list of \class{Extension} instances, each of which describes a |
| 397 | single extension module. Suppose your distribution includes a single |
| 398 | extension, called \module{foo} and implemented by \file{foo.c}. If no |
| 399 | additional instructions to the compiler/linker are needed, describing |
| 400 | this extension is quite simple: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 401 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 402 | \begin{verbatim} |
| 403 | Extension("foo", ["foo.c"]) |
| 404 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 405 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 406 | The \class{Extension} class can be imported from |
| 407 | \module{distutils.core}, along with \function{setup()}. Thus, the setup |
| 408 | script for a module distribution that contains only this one extension |
| 409 | and nothing else might be: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 410 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 411 | \begin{verbatim} |
| 412 | from distutils.core import setup, Extension |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 413 | setup(name="foo", version="1.0", |
| 414 | ext_modules=[Extension("foo", ["foo.c"])]) |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 415 | \end{verbatim} |
| 416 | |
| 417 | The \class{Extension} class (actually, the underlying extension-building |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 418 | machinery implemented by the \command{build\_ext} command) supports a |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 419 | great deal of flexibility in describing Python extensions, which is |
| 420 | explained in the following sections. |
| 421 | |
| 422 | |
| 423 | \subsubsection{Extension names and packages} |
| 424 | |
| 425 | The first argument to the \class{Extension} constructor is always the |
| 426 | name of the extension, including any package names. For example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 427 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 428 | \begin{verbatim} |
| 429 | Extension("foo", ["src/foo1.c", "src/foo2.c"]) |
| 430 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 431 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 432 | describes an extension that lives in the root package, while |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 433 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 434 | \begin{verbatim} |
| 435 | Extension("pkg.foo", ["src/foo1.c", "src/foo2.c"]) |
| 436 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 437 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 438 | describes the same extension in the \module{pkg} package. The source |
| 439 | files and resulting object code are identical in both cases; the only |
| 440 | difference is where in the filesystem (and therefore where in Python's |
| 441 | namespace hierarchy) the resulting extension lives. |
| 442 | |
| 443 | If you have a number of extensions all in the same package (or all under |
| 444 | the same base package), use the \option{ext\_package} keyword argument |
| 445 | to \function{setup()}. For example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 446 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 447 | \begin{verbatim} |
| 448 | setup(... |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 449 | ext_package="pkg", |
| 450 | ext_modules=[Extension("foo", ["foo.c"]), |
| 451 | Extension("subpkg.bar", ["bar.c"])] |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 452 | ) |
| 453 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 454 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 455 | will compile \file{foo.c} to the extension \module{pkg.foo}, and |
| 456 | \file{bar.c} to \module{pkg.subpkg.bar}. |
| 457 | |
| 458 | |
| 459 | \subsubsection{Extension source files} |
| 460 | |
| 461 | The second argument to the \class{Extension} constructor is a list of |
| 462 | source files. Since the Distutils currently only support C/C++ |
| 463 | extensions, these are normally C/C++ source files. (Be sure to use |
| 464 | appropriate extensions to distinguish C++ source files: \file{.cc} and |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 465 | \file{.cpp} seem to be recognized by both \UNIX{} and Windows compilers.) |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 466 | |
| 467 | However, you can also include SWIG interface (\file{.i}) files in the |
| 468 | list; the \command{build\_ext} command knows how to deal with SWIG |
| 469 | extensions: it will run SWIG on the interface file and compile the |
| 470 | resulting C/C++ file into your extension. |
| 471 | |
| 472 | \XXX{SWIG support is rough around the edges and largely untested; |
| 473 | especially SWIG support of C++ extensions! Explain in more detail |
| 474 | here when the interface firms up.} |
| 475 | |
| 476 | On some platforms, you can include non-source files that are processed |
| 477 | by the compiler and included in your extension. Currently, this just |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 478 | means Windows message text (\file{.mc}) files and resource definition |
| 479 | (\file{.rc}) files for Visual C++. These will be compiled to binary resource |
| 480 | (\file{.res}) files and linked into the executable. |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 481 | |
| 482 | |
| 483 | \subsubsection{Preprocessor options} |
| 484 | |
| 485 | Three optional arguments to \class{Extension} will help if you need to |
| 486 | specify include directories to search or preprocessor macros to |
| 487 | define/undefine: \code{include\_dirs}, \code{define\_macros}, and |
| 488 | \code{undef\_macros}. |
| 489 | |
| 490 | For example, if your extension requires header files in the |
| 491 | \file{include} directory under your distribution root, use the |
| 492 | \code{include\_dirs} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 493 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 494 | \begin{verbatim} |
| 495 | Extension("foo", ["foo.c"], include_dirs=["include"]) |
| 496 | \end{verbatim} |
| 497 | |
| 498 | You can specify absolute directories there; if you know that your |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 499 | extension will only be built on \UNIX{} systems with X11R6 installed to |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 500 | \file{/usr}, you can get away with |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 501 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 502 | \begin{verbatim} |
| 503 | Extension("foo", ["foo.c"], include_dirs=["/usr/include/X11"]) |
| 504 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 505 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 506 | You should avoid this sort of non-portable usage if you plan to |
| 507 | distribute your code: it's probably better to write your code to include |
| 508 | (e.g.) \code{<X11/Xlib.h>}. |
| 509 | |
| 510 | If you need to include header files from some other Python extension, |
| 511 | you can take advantage of the fact that the Distutils install extension |
| 512 | header files in a consistent way. For example, the Numerical Python |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 513 | header files are installed (on a standard \UNIX{} installation) to |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 514 | \file{/usr/local/include/python1.5/Numerical}. (The exact location will |
| 515 | differ according to your platform and Python installation.) Since the |
| 516 | Python include directory---\file{/usr/local/include/python1.5} in this |
| 517 | case---is always included in the search path when building Python |
| 518 | extensions, the best approach is to include (e.g.) |
| 519 | \code{<Numerical/arrayobject.h>}. If you insist on putting the |
| 520 | \file{Numerical} include directory right into your header search path, |
| 521 | though, you can find that directory using the Distutils |
| 522 | \module{sysconfig} module: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 523 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 524 | \begin{verbatim} |
| 525 | from distutils.sysconfig import get_python_inc |
| 526 | incdir = os.path.join(get_python_inc(plat_specific=1), "Numerical") |
| 527 | setup(..., |
| 528 | Extension(..., include_dirs=[incdir])) |
| 529 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 530 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 531 | Even though this is quite portable---it will work on any Python |
| 532 | installation, regardless of platform---it's probably easier to just |
| 533 | write your C code in the sensible way. |
| 534 | |
| 535 | You can define and undefine pre-processor macros with the |
| 536 | \code{define\_macros} and \code{undef\_macros} options. |
| 537 | \code{define\_macros} takes a list of \code{(name, value)} tuples, where |
| 538 | \code{name} is the name of the macro to define (a string) and |
| 539 | \code{value} is its value: either a string or \code{None}. (Defining a |
| 540 | macro \code{FOO} to \code{None} is the equivalent of a bare |
| 541 | \code{\#define FOO} in your C source: with most compilers, this sets |
| 542 | \code{FOO} to the string \code{1}.) \code{undef\_macros} is just |
| 543 | a list of macros to undefine. |
| 544 | |
| 545 | For example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 546 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 547 | \begin{verbatim} |
| 548 | Extension(..., |
| 549 | define_macros=[('NDEBUG', '1')], |
| 550 | ('HAVE_STRFTIME', None), |
| 551 | undef_macros=['HAVE_FOO', 'HAVE_BAR']) |
| 552 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 553 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 554 | 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] | 555 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 556 | \begin{verbatim} |
| 557 | #define NDEBUG 1 |
| 558 | #define HAVE_STRFTIME |
| 559 | #undef HAVE_FOO |
| 560 | #undef HAVE_BAR |
| 561 | \end{verbatim} |
| 562 | |
| 563 | |
| 564 | \subsubsection{Library options} |
| 565 | |
| 566 | You can also specify the libraries to link against when building your |
| 567 | extension, and the directories to search for those libraries. The |
| 568 | \code{libraries} option is a list of libraries to link against, |
| 569 | \code{library\_dirs} is a list of directories to search for libraries at |
| 570 | link-time, and \code{runtime\_library\_dirs} is a list of directories to |
| 571 | search for shared (dynamically loaded) libraries at run-time. |
| 572 | |
| 573 | For example, if you need to link against libraries known to be in the |
| 574 | standard library search path on target systems |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 575 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 576 | \begin{verbatim} |
| 577 | Extension(..., |
| 578 | libraries=["gdbm", "readline"]) |
| 579 | \end{verbatim} |
| 580 | |
| 581 | If you need to link with libraries in a non-standard location, you'll |
| 582 | have to include the location in \code{library\_dirs}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 583 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 584 | \begin{verbatim} |
| 585 | Extension(..., |
| 586 | library_dirs=["/usr/X11R6/lib"], |
| 587 | libraries=["X11", "Xt"]) |
| 588 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 589 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 590 | (Again, this sort of non-portable construct should be avoided if you |
| 591 | intend to distribute your code.) |
| 592 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 593 | \XXX{Should mention clib libraries here or somewhere else!} |
| 594 | |
| 595 | \subsubsection{Other options} |
| 596 | |
| 597 | There are still some other options which can be used to handle special |
| 598 | cases. |
| 599 | |
| 600 | The \option{extra\_objects} option is a list of object files to be passed |
| 601 | to the linker. These files must not have extensions, as the default |
| 602 | extension for the compiler is used. |
| 603 | |
| 604 | \option{extra\_compile\_args} and \option{extra\_link\_args} can be used |
| 605 | to specify additional command line options for the compiler resp. |
| 606 | the linker command line. |
| 607 | |
| 608 | \option{export\_symbols} is only useful on windows, it can contain a list |
| 609 | of symbols (functions or variables) to be exported. This option |
| 610 | is not needed when building compiled extensions: the \code{initmodule} |
| 611 | function will automatically be added to the exported symbols list |
| 612 | by Distutils. |
| 613 | |
| 614 | \subsection{Listing scripts} |
| 615 | So far we have been dealing with pure and non-pure Python modules, |
| 616 | which are usually not run by themselves but imported by scripts. |
| 617 | |
| 618 | Scripts are files containing Python source code, indended to be started |
| 619 | from the command line. |
| 620 | Distutils doesn't provide much functionality for the scripts: the only |
| 621 | support Distutils gives is to adjust the first line of the script |
Fred Drake | f2502ad | 2001-02-19 19:14:50 +0000 | [diff] [blame] | 622 | if it starts with \code{\#!} and contains the word ``python'' to refer |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 623 | to the current interpreter location. |
| 624 | |
| 625 | The \option{scripts} option simply is a list of files to be handled |
| 626 | in this way. |
| 627 | |
| 628 | |
| 629 | \subsection{Listing additional files} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 630 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 631 | The \option{data\_files} option can be used to specify additional |
| 632 | files needed by the module distribution: configuration files, |
| 633 | data files, anything which does not fit in the previous categories. |
| 634 | |
| 635 | \option{data\_files} specify a sequence of \code{(directory, files)} |
| 636 | pairs in the following way: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 637 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 638 | \begin{verbatim} |
| 639 | setup(... |
| 640 | data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']), |
| 641 | ('config', ['cfg/data.cfg'])]) |
| 642 | \end{verbatim} |
| 643 | |
| 644 | Note that you can specify the directory names where the data files |
| 645 | will be installed, but you cannot rename the data files themselves. |
| 646 | |
| 647 | You can specify the \option{data\_files} options as a simple sequence |
| 648 | of files without specifying a target directory, but this is not recommended, |
| 649 | and the \command{install} command will print a warning in this case. |
| 650 | To install data files directly in the target directory, an empty |
| 651 | string should be given as the directory. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 652 | |
| 653 | |
| 654 | \section{Writing the Setup Configuration File} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 655 | \label{setup-config} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 656 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 657 | 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] | 658 | distribution \emph{a priori}: you may need to get some information from |
| 659 | the user, or from the user's system, in order to proceed. As long as |
| 660 | that information is fairly simple---a list of directories to search for |
| 661 | C header files or libraries, for example---then providing a |
| 662 | configuration file, \file{setup.cfg}, for users to edit is a cheap and |
| 663 | easy way to solicit it. Configuration files also let you provide |
| 664 | default values for any command option, which the installer can then |
| 665 | override either on the command-line or by editing the config file. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 666 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 667 | (If you have more advanced needs, such as determining which extensions |
| 668 | to build based on what capabilities are present on the target system, |
| 669 | then you need the Distutils ``auto-configuration'' facility. This |
| 670 | started to appear in Distutils 0.9 but, as of this writing, isn't mature |
| 671 | or stable enough yet for real-world use.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 672 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 673 | The setup configuration file is a useful middle-ground between the setup |
| 674 | script---which, ideally, would be opaque to installers\footnote{This |
| 675 | ideal probably won't be achieved until auto-configuration is fully |
| 676 | supported by the Distutils.}---and the command-line to the setup |
| 677 | script, which is outside of your control and entirely up to the |
| 678 | installer. In fact, \file{setup.cfg} (and any other Distutils |
| 679 | configuration files present on the target system) are processed after |
| 680 | the contents of the setup script, but before the command-line. This has |
| 681 | several useful consequences: |
| 682 | \begin{itemize} |
| 683 | \item installers can override some of what you put in \file{setup.py} by |
| 684 | editing \file{setup.cfg} |
| 685 | \item you can provide non-standard defaults for options that are not |
| 686 | easily set in \file{setup.py} |
| 687 | \item installers can override anything in \file{setup.cfg} using the |
| 688 | command-line options to \file{setup.py} |
| 689 | \end{itemize} |
| 690 | |
| 691 | The basic syntax of the configuration file is simple: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 692 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 693 | \begin{verbatim} |
| 694 | [command] |
| 695 | option=value |
| 696 | ... |
| 697 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 698 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 699 | where \var{command} is one of the Distutils commands (e.g. |
| 700 | \command{build\_py}, \command{install}), and \var{option} is one of the |
| 701 | options that command supports. Any number of options can be supplied |
| 702 | for each command, and any number of command sections can be included in |
Fred Drake | 78489a3 | 2000-11-22 16:06:16 +0000 | [diff] [blame] | 703 | the file. Blank lines are ignored, as are comments (from a |
| 704 | \character{\#} character to end-of-line). Long option values can be |
| 705 | split across multiple lines simply by indenting the continuation lines. |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 706 | |
| 707 | You can find out the list of options supported by a particular command |
| 708 | with the universal \longprogramopt{help} option, e.g. |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 709 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 710 | \begin{verbatim} |
| 711 | > python setup.py --help build_ext |
| 712 | [...] |
| 713 | Options for 'build_ext' command: |
| 714 | --build-lib (-b) directory for compiled extension modules |
| 715 | --build-temp (-t) directory for temporary files (build by-products) |
| 716 | --inplace (-i) ignore build-lib and put compiled extensions into the |
| 717 | source directory alongside your pure Python modules |
| 718 | --include-dirs (-I) list of directories to search for header files |
| 719 | --define (-D) C preprocessor macros to define |
| 720 | --undef (-U) C preprocessor macros to undefine |
| 721 | [...] |
| 722 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 723 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 724 | Or consult section \ref{reference} of this document (the command |
| 725 | reference). |
| 726 | |
| 727 | Note that an option spelled \longprogramopt{foo-bar} on the command-line |
| 728 | is spelled \option{foo\_bar} in configuration files. |
| 729 | |
| 730 | For example, say you want your extensions to be built |
| 731 | ``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] | 732 | 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] | 733 | in the same source directory as your pure Python modules |
| 734 | \module{pkg.mod1} and \module{pkg.mod2}. You can always use the |
| 735 | \longprogramopt{inplace} option on the command-line to ensure this: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 736 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 737 | \begin{verbatim} |
| 738 | python setup.py build_ext --inplace |
| 739 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 740 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 741 | But this requires that you always specify the \command{build\_ext} |
| 742 | command explicitly, and remember to provide \longprogramopt{inplace}. |
| 743 | An easier way is to ``set and forget'' this option, by encoding it in |
| 744 | \file{setup.cfg}, the configuration file for this distribution: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 745 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 746 | \begin{verbatim} |
| 747 | [build_ext] |
| 748 | inplace=1 |
| 749 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 750 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 751 | This will affect all builds of this module distribution, whether or not |
| 752 | you explcitly specify \command{build\_ext}. If you include |
| 753 | \file{setup.cfg} in your source distribution, it will also affect |
| 754 | end-user builds---which is probably a bad idea for this option, since |
| 755 | always building extensions in-place would break installation of the |
| 756 | module distribution. In certain peculiar cases, though, modules are |
| 757 | built right in their installation directory, so this is conceivably a |
| 758 | useful ability. (Distributing extensions that expect to be built in |
| 759 | their installation directory is almost always a bad idea, though.) |
| 760 | |
| 761 | Another example: certain commands take a lot of options that don't |
| 762 | change from run-to-run; for example, \command{bdist\_rpm} needs to know |
| 763 | everything required to generate a ``spec'' file for creating an RPM |
| 764 | distribution. Some of this information comes from the setup script, and |
| 765 | some is automatically generated by the Distutils (such as the list of |
| 766 | files installed). But some of it has to be supplied as options to |
| 767 | \command{bdist\_rpm}, which would be very tedious to do on the |
| 768 | command-line for every run. Hence, here is a snippet from the |
| 769 | Distutils' own \file{setup.cfg}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 770 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 771 | \begin{verbatim} |
| 772 | [bdist_rpm] |
| 773 | release = 1 |
| 774 | packager = Greg Ward <gward@python.net> |
| 775 | doc_files = CHANGES.txt |
| 776 | README.txt |
| 777 | USAGE.txt |
| 778 | doc/ |
| 779 | examples/ |
| 780 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 781 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 782 | Note that the \option{doc\_files} option is simply a |
| 783 | whitespace-separated string split across multiple lines for readability. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 784 | |
| 785 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 786 | \begin{seealso} |
| 787 | \seetitle[../inst/config-syntax.html]{Installing Python |
| 788 | Modules}{More information on the configuration files is |
| 789 | available in the manual for system administrators.} |
| 790 | \end{seealso} |
| 791 | |
| 792 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 793 | \section{Creating a Source Distribution} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 794 | \label{source-dist} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 795 | |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 796 | As shown in section~\ref{simple-example}, you use the |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 797 | \command{sdist} command to create a source distribution. In the |
| 798 | simplest case, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 799 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 800 | \begin{verbatim} |
| 801 | python setup.py sdist |
| 802 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 803 | |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 804 | (assuming you haven't specified any \command{sdist} options in the setup |
| 805 | script or config file), \command{sdist} creates the archive of the |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 806 | default format for the current platform. The default format is gzip'ed |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 807 | tar file (\file{.tar.gz}) on \UNIX, and ZIP file on Windows. |
| 808 | \XXX{no MacOS support here} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 809 | |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 810 | You can specify as many formats as you like using the |
| 811 | \longprogramopt{formats} option, for example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 812 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 813 | \begin{verbatim} |
| 814 | python setup.py sdist --formats=gztar,zip |
| 815 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 816 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 817 | to create a gzipped tarball and a zip file. The available formats are: |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 818 | \begin{tableiii}{l|l|c}{code}% |
| 819 | {Format}{Description}{Notes} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 820 | \lineiii{zip}{zip file (\file{.zip})}{(1),(3)} |
| 821 | \lineiii{gztar}{gzip'ed tar file (\file{.tar.gz})}{(2),(4)} |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 822 | \lineiii{bztar}{bzip2'ed tar file (\file{.tar.gz})}{(4)} |
| 823 | \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(4)} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 824 | \lineiii{tar}{tar file (\file{.tar})}{(4)} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 825 | \end{tableiii} |
| 826 | |
| 827 | \noindent Notes: |
| 828 | \begin{description} |
| 829 | \item[(1)] default on Windows |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 830 | \item[(2)] default on \UNIX |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 831 | \item[(3)] requires either external \program{zip} utility or |
| 832 | \module{zipfile} module (not part of the standard Python library) |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 833 | \item[(4)] requires external utilities: \program{tar} and possibly one |
| 834 | of \program{gzip}, \program{bzip2}, or \program{compress} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 835 | \end{description} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 836 | |
| 837 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 838 | |
| 839 | \subsection{Specifying the files to distribute} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 840 | \label{manifest} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 841 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 842 | If you don't supply an explicit list of files (or instructions on how to |
| 843 | generate one), the \command{sdist} command puts a minimal default set |
| 844 | into the source distribution: |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 845 | \begin{itemize} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 846 | \item all Python source files implied by the \option{py\_modules} and |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 847 | \option{packages} options |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 848 | \item all C source files mentioned in the \option{ext\_modules} or |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 849 | \option{libraries} options (\XXX{getting C library sources currently |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 850 | broken -- no get\_source\_files() method in build\_clib.py!}) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 851 | \item anything that looks like a test script: \file{test/test*.py} |
| 852 | (currently, the Distutils don't do anything with test scripts except |
| 853 | include them in source distributions, but in the future there will be |
| 854 | a standard for testing Python module distributions) |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 855 | \item \file{README.txt} (or \file{README}), \file{setup.py} (or whatever |
| 856 | you called your setup script), and \file{setup.cfg} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 857 | \end{itemize} |
| 858 | Sometimes this is enough, but usually you will want to specify |
| 859 | additional files to distribute. The typical way to do this is to write |
| 860 | a \emph{manifest template}, called \file{MANIFEST.in} by default. The |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 861 | manifest template is just a list of instructions for how to generate |
| 862 | your manifest file, \file{MANIFEST}, which is the exact list of files to |
| 863 | include in your source distribution. The \command{sdist} command |
| 864 | processes this template and generates a manifest based on its |
| 865 | instructions and what it finds in the filesystem. |
| 866 | |
| 867 | If you prefer to roll your own manifest file, the format is simple: one |
| 868 | filename per line, regular files (or symlinks to them) only. If you do |
| 869 | supply your own \file{MANIFEST}, you must specify everything: the |
| 870 | default set of files described above does not apply in this case. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 871 | |
| 872 | The manifest template has one command per line, where each command |
| 873 | specifies a set of files to include or exclude from the source |
| 874 | distribution. For an example, again we turn to the Distutils' own |
| 875 | manifest template: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 876 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 877 | \begin{verbatim} |
| 878 | include *.txt |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 879 | recursive-include examples *.txt *.py |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 880 | prune examples/sample?/build |
| 881 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 882 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 883 | The meanings should be fairly clear: include all files in the |
| 884 | distribution root matching \code{*.txt}, all files anywhere under the |
| 885 | \file{examples} directory matching \code{*.txt} or \code{*.py}, and |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 886 | exclude all directories matching \code{examples/sample?/build}. All of |
| 887 | this is done \emph{after} the standard include set, so you can exclude |
| 888 | files from the standard set with explicit instructions in the manifest |
| 889 | template. (Or, you can use the \longprogramopt{no-defaults} option to |
| 890 | disable the standard set entirely.) There are several other commands |
| 891 | available in the manifest template mini-language; see |
| 892 | section~\ref{sdist-cmd}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 893 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 894 | The order of commands in the manifest template matters: initially, we |
| 895 | have the list of default files as described above, and each command in |
| 896 | the template adds to or removes from that list of files. Once we have |
| 897 | fully processed the manifest template, we remove files that should not |
| 898 | be included in the source distribution: |
| 899 | \begin{itemize} |
| 900 | \item all files in the Distutils ``build'' tree (default \file{build/}) |
| 901 | \item all files in directories named \file{RCS} or \file{CVS} |
| 902 | \end{itemize} |
| 903 | Now we have our complete list of files, which is written to the manifest |
| 904 | for future reference, and then used to build the source distribution |
| 905 | archive(s). |
| 906 | |
| 907 | You can disable the default set of included files with the |
| 908 | \longprogramopt{no-defaults} option, and you can disable the standard |
| 909 | exclude set with \longprogramopt{no-prune}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 910 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 911 | Following the Distutils' own manifest template, let's trace how the |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 912 | \command{sdist} command builds the list of files to include in the |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 913 | Distutils source distribution: |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 914 | \begin{enumerate} |
| 915 | \item include all Python source files in the \file{distutils} and |
| 916 | \file{distutils/command} subdirectories (because packages |
| 917 | corresponding to those two directories were mentioned in the |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 918 | \option{packages} option in the setup script---see |
| 919 | section~\ref{setup-script}) |
| 920 | \item include \file{README.txt}, \file{setup.py}, and \file{setup.cfg} |
| 921 | (standard files) |
| 922 | \item include \file{test/test*.py} (standard files) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 923 | \item include \file{*.txt} in the distribution root (this will find |
| 924 | \file{README.txt} a second time, but such redundancies are weeded out |
| 925 | later) |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 926 | \item include anything matching \file{*.txt} or \file{*.py} in the |
| 927 | sub-tree under \file{examples}, |
| 928 | \item exclude all files in the sub-trees starting at directories |
| 929 | matching \file{examples/sample?/build}---this may exclude files |
| 930 | included by the previous two steps, so it's important that the |
| 931 | \code{prune} command in the manifest template comes after the |
| 932 | \code{recursive-include} command |
| 933 | \item exclude the entire \file{build} tree, and any \file{RCS} or |
| 934 | \file{CVS} directories |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 935 | \end{enumerate} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 936 | Just like in the setup script, file and directory names in the manifest |
| 937 | template should always be slash-separated; the Distutils will take care |
| 938 | of converting them to the standard representation on your platform. |
| 939 | That way, the manifest template is portable across operating systems. |
| 940 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 941 | |
| 942 | \subsection{Manifest-related options} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 943 | \label{manifest-options} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 944 | |
| 945 | The normal course of operations for the \command{sdist} command is as |
| 946 | follows: |
| 947 | \begin{itemize} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 948 | \item if the manifest file, \file{MANIFEST} doesn't exist, read |
| 949 | \file{MANIFEST.in} and create the manifest |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 950 | \item if neither \file{MANIFEST} nor \file{MANIFEST.in} exist, create a |
| 951 | manifest with just the default file set\footnote{In versions of the |
| 952 | Distutils up to and including 0.9.2 (Python 2.0b1), this feature was |
| 953 | broken; use the \programopt{-f} (\longprogramopt{force-manifest}) |
| 954 | option to work around the bug.} |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 955 | \item if either \file{MANIFEST.in} or the setup script (\file{setup.py}) |
| 956 | are more recent than \file{MANIFEST}, recreate \file{MANIFEST} by |
| 957 | reading \file{MANIFEST.in} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 958 | \item use the list of files now in \file{MANIFEST} (either just |
| 959 | generated or read in) to create the source distribution archive(s) |
| 960 | \end{itemize} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 961 | There are a couple of options that modify this behaviour. First, use |
| 962 | the \longprogramopt{no-defaults} and \longprogramopt{no-prune} to |
| 963 | disable the standard ``include'' and ``exclude'' sets.\footnote{Note |
| 964 | that if you have no manifest template, no manifest, and use the |
| 965 | \longprogramopt{no-defaults}, you will get an empty manifest. Another |
| 966 | bug in Distutils 0.9.2 and earlier causes an uncaught exception in |
| 967 | this case. The workaround is: Don't Do That.} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 968 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 969 | Second, you might want to force the manifest to be regenerated---for |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 970 | example, if you have added or removed files or directories that match an |
| 971 | existing pattern in the manifest template, you should regenerate the |
| 972 | manifest: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 973 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 974 | \begin{verbatim} |
| 975 | python setup.py sdist --force-manifest |
| 976 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 977 | |
| 978 | Or, you might just want to (re)generate the manifest, but not create a |
| 979 | source distribution: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 980 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 981 | \begin{verbatim} |
| 982 | python setup.py sdist --manifest-only |
| 983 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 984 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 985 | \longprogramopt{manifest-only} implies \longprogramopt{force-manifest}. |
| 986 | \programopt{-o} is a shortcut for \longprogramopt{manifest-only}, and |
| 987 | \programopt{-f} for \longprogramopt{force-manifest}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 988 | |
| 989 | |
| 990 | \section{Creating Built Distributions} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 991 | \label{built-dist} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 992 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 993 | A ``built distribution'' is what you're probably used to thinking of |
| 994 | either as a ``binary package'' or an ``installer'' (depending on your |
| 995 | background). It's not necessarily binary, though, because it might |
| 996 | contain only Python source code and/or byte-code; and we don't call it a |
| 997 | package, because that word is already spoken for in Python. (And |
| 998 | ``installer'' is a term specific to the Windows world. \XXX{do Mac |
| 999 | people use it?}) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1000 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1001 | A built distribution is how you make life as easy as possible for |
| 1002 | installers of your module distribution: for users of RPM-based Linux |
| 1003 | systems, it's a binary RPM; for Windows users, it's an executable |
| 1004 | installer; for Debian-based Linux users, it's a Debian package; and so |
| 1005 | forth. Obviously, no one person will be able to create built |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1006 | distributions for every platform under the sun, so the Distutils are |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1007 | designed to enable module developers to concentrate on their |
| 1008 | specialty---writing code and creating source distributions---while an |
| 1009 | intermediary species of \emph{packager} springs up to turn source |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 1010 | distributions into built distributions for as many platforms as there |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1011 | are packagers. |
| 1012 | |
| 1013 | Of course, the module developer could be his own packager; or the |
| 1014 | packager could be a volunteer ``out there'' somewhere who has access to |
| 1015 | a platform which the original developer does not; or it could be |
| 1016 | software periodically grabbing new source distributions and turning them |
| 1017 | into built distributions for as many platforms as the software has |
| 1018 | access to. Regardless of the nature of the beast, a packager uses the |
| 1019 | setup script and the \command{bdist} command family to generate built |
| 1020 | distributions. |
| 1021 | |
| 1022 | As a simple example, if I run the following command in the Distutils |
| 1023 | source tree: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1024 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1025 | \begin{verbatim} |
| 1026 | python setup.py bdist |
| 1027 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1028 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1029 | then the Distutils builds my module distribution (the Distutils itself |
| 1030 | in this case), does a ``fake'' installation (also in the \file{build} |
| 1031 | directory), and creates the default type of built distribution for my |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1032 | platform. The default format for built distributions is a ``dumb'' tar |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1033 | file on \UNIX, and an simple executable installer on Windows. (That tar |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1034 | file is considered ``dumb'' because it has to be unpacked in a specific |
| 1035 | location to work.) |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1036 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1037 | Thus, the above command on a \UNIX{} system creates |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1038 | \file{Distutils-0.9.1.\filevar{plat}.tar.gz}; unpacking this tarball |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1039 | from the right place installs the Distutils just as though you had |
| 1040 | downloaded the source distribution and run \code{python setup.py |
| 1041 | install}. (The ``right place'' is either the root of the filesystem or |
| 1042 | Python's \filevar{prefix} directory, depending on the options given to |
| 1043 | the \command{bdist\_dumb} command; the default is to make dumb |
| 1044 | distributions relative to \filevar{prefix}.) |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1045 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1046 | Obviously, for pure Python distributions, this isn't a huge win---but |
| 1047 | for non-pure distributions, which include extensions that would need to |
| 1048 | be compiled, it can mean the difference between someone being able to |
| 1049 | use your extensions or not. And creating ``smart'' built distributions, |
| 1050 | such as an RPM package or an executable installer for Windows, is a big |
| 1051 | win for users even if your distribution doesn't include any extensions. |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1052 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1053 | The \command{bdist} command has a \longprogramopt{formats} option, |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1054 | similar to the \command{sdist} command, which you can use to select the |
| 1055 | types of built distribution to generate: for example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1056 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1057 | \begin{verbatim} |
| 1058 | python setup.py bdist --format=zip |
| 1059 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1060 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1061 | would, when run on a \UNIX{} system, create |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1062 | \file{Distutils-0.8.\filevar{plat}.zip}---again, this archive would be |
| 1063 | unpacked from the root directory to install the Distutils. |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1064 | |
| 1065 | The available formats for built distributions are: |
| 1066 | \begin{tableiii}{l|l|c}{code}% |
| 1067 | {Format}{Description}{Notes} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1068 | \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1),(3)} |
| 1069 | \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(3)} |
| 1070 | \lineiii{tar}{tar file (\file{.tar})}{(3)} |
| 1071 | \lineiii{zip}{zip file (\file{.zip})}{(4)} |
| 1072 | \lineiii{rpm}{RPM}{(5)} |
| 1073 | \lineiii{srpm}{source RPM}{(5) \XXX{to do!}} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1074 | \lineiii{wininst}{self-extracting ZIP file for Windows}{(2),(4)} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1075 | \end{tableiii} |
| 1076 | |
| 1077 | \noindent Notes: |
| 1078 | \begin{description} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1079 | \item[(1)] default on \UNIX |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1080 | \item[(2)] default on Windows \XXX{to-do!} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1081 | \item[(3)] requires external utilities: \program{tar} and possibly one |
| 1082 | of \program{gzip}, \program{bzip2}, or \program{compress} |
| 1083 | \item[(4)] requires either external \program{zip} utility or |
| 1084 | \module{zipfile} module (not part of the standard Python library) |
| 1085 | \item[(5)] requires external \program{rpm} utility, version 3.0.4 or |
| 1086 | better (use \code{rpm --version} to find out which version you have) |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1087 | \end{description} |
| 1088 | |
| 1089 | You don't have to use the \command{bdist} command with the |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 1090 | \longprogramopt{formats} option; you can also use the command that |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1091 | directly implements the format you're interested in. Some of these |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1092 | \command{bdist} ``sub-commands'' actually generate several similar |
| 1093 | formats; for instance, the \command{bdist\_dumb} command generates all |
| 1094 | the ``dumb'' archive formats (\code{tar}, \code{ztar}, \code{gztar}, and |
| 1095 | \code{zip}), and \command{bdist\_rpm} generates both binary and source |
| 1096 | RPMs. The \command{bdist} sub-commands, and the formats generated by |
| 1097 | each, are: |
| 1098 | \begin{tableii}{l|l}{command}% |
| 1099 | {Command}{Formats} |
| 1100 | \lineii{bdist\_dumb}{tar, ztar, gztar, zip} |
| 1101 | \lineii{bdist\_rpm}{rpm, srpm} |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1102 | \lineii{bdist\_wininst}{wininst} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1103 | \end{tableii} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1104 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1105 | The following sections give details on the individual \command{bdist\_*} |
| 1106 | commands. |
| 1107 | |
| 1108 | |
| 1109 | \subsection{Creating dumb built distributions} |
| 1110 | \label{creating-dumb} |
| 1111 | |
| 1112 | \XXX{Need to document absolute vs. prefix-relative packages here, but |
| 1113 | first I have to implement it!} |
| 1114 | |
| 1115 | |
| 1116 | \subsection{Creating RPM packages} |
| 1117 | \label{creating-rpms} |
| 1118 | |
| 1119 | The RPM format is used by many of popular Linux distributions, including |
| 1120 | Red Hat, SuSE, and Mandrake. If one of these (or any of the other |
| 1121 | RPM-based Linux distributions) is your usual environment, creating RPM |
| 1122 | packages for other users of that same distribution is trivial. |
| 1123 | Depending on the complexity of your module distribution and differences |
| 1124 | between Linux distributions, you may also be able to create RPMs that |
| 1125 | work on different RPM-based distributions. |
| 1126 | |
| 1127 | The usual way to create an RPM of your module distribution is to run the |
| 1128 | \command{bdist\_rpm} command: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1129 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1130 | \begin{verbatim} |
| 1131 | python setup.py bdist_rpm |
| 1132 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1133 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1134 | or the \command{bdist} command with the \longprogramopt{format} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1135 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1136 | \begin{verbatim} |
| 1137 | python setup.py bdist --formats=rpm |
| 1138 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1139 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1140 | The former allows you to specify RPM-specific options; the latter allows |
| 1141 | you to easily specify multiple formats in one run. If you need to do |
| 1142 | both, you can explicitly specify multiple \command{bdist\_*} commands |
| 1143 | and their options: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1144 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1145 | \begin{verbatim} |
| 1146 | python setup.py bdist_rpm --packager="John Doe <jdoe@python.net>" \ |
| 1147 | bdist_wininst --target_version="2.0" |
| 1148 | \end{verbatim} |
| 1149 | |
| 1150 | Creating RPM packages is driven by a \file{.spec} file, much as using |
| 1151 | the Distutils is driven by the setup script. To make your life easier, |
| 1152 | the \command{bdist\_rpm} command normally creates a \file{.spec} file |
| 1153 | based on the information you supply in the setup script, on the command |
| 1154 | line, and in any Distutils configuration files. Various options and |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 1155 | 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] | 1156 | script as follows: |
| 1157 | \begin{tableii}{l|l}{textrm}% |
| 1158 | {RPM \file{.spec} file option or section}{Distutils setup script option} |
| 1159 | \lineii{Name}{\option{name}} |
| 1160 | \lineii{Summary (in preamble)}{\option{description}} |
| 1161 | \lineii{Version}{\option{version}} |
| 1162 | \lineii{Vendor}{\option{author} and \option{author\_email}, or \\& |
| 1163 | \option{maintainer} and \option{maintainer\_email}} |
| 1164 | \lineii{Copyright}{\option{licence}} |
| 1165 | \lineii{Url}{\option{url}} |
| 1166 | \lineii{\%description (section)}{\option{long\_description}} |
| 1167 | \end{tableii} |
| 1168 | |
| 1169 | Additionally, there many options in \file{.spec} files that don't have |
| 1170 | corresponding options in the setup script. Most of these are handled |
| 1171 | through options to the \command{bdist\_rpm} command as follows: |
| 1172 | \begin{tableiii}{l|l|l}{textrm}% |
| 1173 | {RPM \file{.spec} file option or section}% |
| 1174 | {\command{bdist\_rpm} option}% |
| 1175 | {default value} |
| 1176 | \lineiii{Release}{\option{release}}{``1''} |
| 1177 | \lineiii{Group}{\option{group}}{``Development/Libraries''} |
| 1178 | \lineiii{Vendor}{\option{vendor}}{(see above)} |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 1179 | \lineiii{Packager}{\option{packager}}{(none)} |
| 1180 | \lineiii{Provides}{\option{provides}}{(none)} |
| 1181 | \lineiii{Requires}{\option{requires}}{(none)} |
| 1182 | \lineiii{Conflicts}{\option{conflicts}}{(none)} |
| 1183 | \lineiii{Obsoletes}{\option{obsoletes}}{(none)} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1184 | \lineiii{Distribution}{\option{distribution\_name}}{(none)} |
| 1185 | \lineiii{BuildRequires}{\option{build\_requires}}{(none)} |
| 1186 | \lineiii{Icon}{\option{icon}}{(none)} |
| 1187 | \end{tableiii} |
| 1188 | Obviously, supplying even a few of these options on the command-line |
| 1189 | would be tedious and error-prone, so it's usually best to put them in |
| 1190 | the setup configuration file, \file{setup.cfg}---see |
| 1191 | section~\ref{setup-config}. If you distribute or package many Python |
| 1192 | module distributions, you might want to put options that apply to all of |
| 1193 | them in your personal Distutils configuration file |
| 1194 | (\file{\textasciitilde/.pydistutils.cfg}). |
| 1195 | |
| 1196 | There are three steps to building a binary RPM package, all of which are |
| 1197 | handled automatically by the Distutils: |
| 1198 | \begin{enumerate} |
| 1199 | \item create a \file{.spec} file, which describes the package (analogous |
| 1200 | to the Distutils setup script; in fact, much of the information in the |
| 1201 | setup script winds up in the \file{.spec} file) |
| 1202 | \item create the source RPM |
| 1203 | \item create the ``binary'' RPM (which may or may not contain binary |
| 1204 | code, depending on whether your module distribution contains Python |
| 1205 | extensions) |
| 1206 | \end{enumerate} |
| 1207 | Normally, RPM bundles the last two steps together; when you use the |
| 1208 | Distutils, all three steps are typically bundled together. |
| 1209 | |
| 1210 | If you wish, you can separate these three steps. You can use the |
| 1211 | \longprogramopt{spec-only} option to make \command{bdist\_rpm} just |
| 1212 | create the \file{.spec} file and exit; in this case, the \file{.spec} |
| 1213 | file will be written to the ``distribution directory''---normally |
| 1214 | \file{dist/}, but customizable with the \longprogramopt{dist-dir} |
| 1215 | option. (Normally, the \file{.spec} file winds up deep in the ``build |
| 1216 | tree,'' in a temporary directory created by \command{bdist\_rpm}.) |
| 1217 | |
| 1218 | \XXX{this isn't implemented yet---is it needed?!} |
| 1219 | You can also specify a custom \file{.spec} file with the |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1220 | \longprogramopt{spec-file} option; used in conjunction with |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1221 | \longprogramopt{spec-only}, this gives you an opportunity to customize |
| 1222 | the \file{.spec} file manually: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1223 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1224 | \begin{verbatim} |
| 1225 | > python setup.py bdist_rpm --spec-only |
| 1226 | # ...edit dist/FooBar-1.0.spec |
| 1227 | > python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec |
| 1228 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1229 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1230 | (Although a better way to do this is probably to override the standard |
| 1231 | \command{bdist\_rpm} command with one that writes whatever else you want |
| 1232 | to the \file{.spec} file; see section~\ref{extending} for information on |
| 1233 | extending the Distutils.) |
| 1234 | |
| 1235 | |
| 1236 | \subsection{Creating Windows installers} |
| 1237 | \label{creating-wininst} |
| 1238 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1239 | Executable Windows installers are the natural format for binary |
Fred Drake | 17f690f | 2001-07-14 02:14:42 +0000 | [diff] [blame^] | 1240 | distributions on Windows. They display a nice graphical user interface, |
| 1241 | display some information of the module distribution to be installed, taken |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1242 | from the meta-dada in the setup script, let the user select a few |
| 1243 | (currently maybe too few) options, and start or cancel the installation. |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1244 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1245 | Since the meta-data is taken from the setup script, creating |
| 1246 | Windows installers is usually as easy as running: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1247 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1248 | \begin{verbatim} |
| 1249 | python setup.py bdist_wininst |
| 1250 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1251 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1252 | or the \command{bdist} command with the \longprogramopt{format} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1253 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1254 | \begin{verbatim} |
| 1255 | python setup.py bdist --formats=wininst |
| 1256 | \end{verbatim} |
| 1257 | |
| 1258 | If you have a pure module distribution (only containing pure |
| 1259 | Python modules and packages), the resulting installer will be |
| 1260 | version independent and have a name like \file{Foo-1.0.win32.exe}. |
| 1261 | These installers can even be created on \UNIX{} or MacOS platforms. |
| 1262 | |
| 1263 | If you have a non-pure distribution, the extensions can only be |
| 1264 | created on a Windows platform, and will be Python version dependend. |
| 1265 | The installer filename will reflect this and now has the form |
| 1266 | \file{Foo-1.0.win32-py2.0.exe}. You have to create a separate installer |
| 1267 | for every Python version you want to support. |
| 1268 | |
| 1269 | The installer will try to compile pure modules into bytecode after |
| 1270 | installation on the target system in normal and optimizing mode. |
| 1271 | If you don't want this to happen for some reason, you can run |
| 1272 | the bdist_wininst command with the \longprogramopt{no-target-compile} and/or |
| 1273 | the \longprogramopt{no-target-optimize} option. |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1274 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1275 | %\section{Examples} |
| 1276 | %\label{examples} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1277 | |
| 1278 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1279 | %\subsection{Pure Python distribution (by module)} |
| 1280 | %\label{pure-mod} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1281 | |
| 1282 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1283 | %\subsection{Pure Python distribution (by package)} |
| 1284 | %\label{pure-pkg} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1285 | |
| 1286 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1287 | %\subsection{Single extension module} |
| 1288 | %\label{single-ext} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1289 | |
| 1290 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1291 | %\subsection{Multiple extension modules} |
| 1292 | %\label{multiple-ext} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1293 | |
| 1294 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1295 | %\subsection{Putting it all together} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1296 | |
| 1297 | |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1298 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1299 | %\section{Extending the Distutils} |
| 1300 | %\label{extending} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1301 | |
| 1302 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1303 | %\subsection{Extending existing commands} |
| 1304 | %\label{extend-existing} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1305 | |
| 1306 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1307 | %\subsection{Writing new commands} |
| 1308 | %\label{new-commands} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1309 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1310 | %\XXX{Would an uninstall command be a good example here?} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1311 | |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1312 | |
| 1313 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1314 | \section{Reference} |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 1315 | \label{reference} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1316 | |
| 1317 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1318 | %\subsection{Building modules: the \protect\command{build} command family} |
| 1319 | %\label{build-cmds} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1320 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1321 | %\subsubsection{\protect\command{build}} |
| 1322 | %\label{build-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1323 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1324 | %\subsubsection{\protect\command{build\_py}} |
| 1325 | %\label{build-py-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1326 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1327 | %\subsubsection{\protect\command{build\_ext}} |
| 1328 | %\label{build-ext-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1329 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1330 | %\subsubsection{\protect\command{build\_clib}} |
| 1331 | %\label{build-clib-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1332 | |
| 1333 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1334 | \subsection{Installing modules: the \protect\command{install} command family} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1335 | \label{install-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1336 | |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1337 | The install command ensures that the build commands have been run and then |
| 1338 | runs the subcommands \command{install\_lib}, |
| 1339 | \command{install\_data} and |
| 1340 | \command{install\_scripts}. |
| 1341 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1342 | %\subsubsection{\protect\command{install\_lib}} |
| 1343 | %\label{install-lib-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1344 | |
| 1345 | \subsubsection{\protect\command{install\_data}} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 1346 | \label{install-data-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1347 | This command installs all data files provided with the distribution. |
| 1348 | |
| 1349 | \subsubsection{\protect\command{install\_scripts}} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 1350 | \label{install-scripts-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1351 | This command installs all (Python) scripts in the distribution. |
| 1352 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1353 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1354 | %\subsection{Cleaning up: the \protect\command{clean} command} |
| 1355 | %\label{clean-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1356 | |
| 1357 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1358 | \subsection{Creating a source distribution: the |
| 1359 | \protect\command{sdist} command} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1360 | \label{sdist-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1361 | |
| 1362 | |
| 1363 | \XXX{fragment moved down from above: needs context!} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1364 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1365 | The manifest template commands are: |
| 1366 | \begin{tableii}{ll}{command}{Command}{Description} |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1367 | \lineii{include \var{pat1} \var{pat2} ... } |
| 1368 | {include all files matching any of the listed patterns} |
| 1369 | \lineii{exclude \var{pat1} \var{pat2} ... } |
| 1370 | {exclude all files matching any of the listed patterns} |
| 1371 | \lineii{recursive-include \var{dir} \var{pat1} \var{pat2} ... } |
| 1372 | {include all files under \var{dir} matching any of the listed patterns} |
| 1373 | \lineii{recursive-exclude \var{dir} \var{pat1} \var{pat2} ...} |
| 1374 | {exclude all files under \var{dir} matching any of the listed patterns} |
| 1375 | \lineii{global-include \var{pat1} \var{pat2} ...} |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 1376 | {include all files anywhere in the source tree matching\\& |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1377 | any of the listed patterns} |
| 1378 | \lineii{global-exclude \var{pat1} \var{pat2} ...} |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 1379 | {exclude all files anywhere in the source tree matching\\& |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1380 | any of the listed patterns} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1381 | \lineii{prune \var{dir}}{exclude all files under \var{dir}} |
| 1382 | \lineii{graft \var{dir}}{include all files under \var{dir}} |
| 1383 | \end{tableii} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1384 | The patterns here are \UNIX-style ``glob'' patterns: \code{*} matches any |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1385 | sequence of regular filename characters, \code{?} matches any single |
| 1386 | regular filename character, and \code{[\var{range}]} matches any of the |
| 1387 | 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] | 1388 | \code{a-f0-9\_.}). The definition of ``regular filename character'' is |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1389 | platform-specific: on \UNIX{} it is anything except slash; on Windows |
| 1390 | anything except backslash or colon; on MacOS anything except colon. |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1391 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1392 | \XXX{Windows and MacOS support not there yet} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1393 | |
| 1394 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1395 | %\subsection{Creating a built distribution: the |
| 1396 | % \protect\command{bdist} command family} |
| 1397 | %\label{bdist-cmds} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1398 | |
| 1399 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1400 | %\subsubsection{\protect\command{blib}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1401 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1402 | %\subsubsection{\protect\command{blib\_dumb}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1403 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1404 | %\subsubsection{\protect\command{blib\_rpm}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1405 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1406 | %\subsubsection{\protect\command{blib\_wise}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1407 | |
| 1408 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 1409 | \end{document} |