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 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 6 | % TODO |
| 7 | % Document extension.read_setup_file |
| 8 | % Document build_clib command |
| 9 | % |
| 10 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 11 | \title{Distributing Python Modules} |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 12 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 13 | \author{Greg Ward} |
Andrew M. Kuchling | 55fa3bb | 2003-03-04 19:36:11 +0000 | [diff] [blame] | 14 | \authoraddress{Email: \email{distutils-sig@python.org}} |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 15 | |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 16 | \makeindex |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 17 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 18 | \begin{document} |
| 19 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 20 | \maketitle |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 21 | \begin{abstract} |
| 22 | \noindent |
| 23 | This document describes the Python Distribution Utilities |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 24 | (``Distutils'') from the module developer's point of view, describing |
Greg Ward | e3cca26 | 2000-08-31 16:36:31 +0000 | [diff] [blame] | 25 | how to use the Distutils to make Python modules and extensions easily |
| 26 | available to a wider audience with very little overhead for |
| 27 | build/release/install mechanics. |
| 28 | \end{abstract} |
| 29 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 30 | % The ugly "%begin{latexonly}" pseudo-environment supresses the table |
| 31 | % of contents for HTML generation. |
| 32 | % |
| 33 | %begin{latexonly} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 34 | \tableofcontents |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 35 | %end{latexonly} |
| 36 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 37 | |
| 38 | \section{Introduction} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 39 | \label{intro} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 40 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 41 | This document covers using the Distutils to distribute your Python |
| 42 | modules, concentrating on the role of developer/distributor: if |
Fred Drake | 01df453 | 2000-06-30 03:36:41 +0000 | [diff] [blame] | 43 | you're looking for information on installing Python modules, you |
| 44 | should refer to the \citetitle[../inst/inst.html]{Installing Python |
| 45 | Modules} manual. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 46 | |
| 47 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 48 | \section{Concepts \& Terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 49 | \label{concepts} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 50 | |
| 51 | Using the Distutils is quite simple, both for module developers and for |
| 52 | users/administrators installing third-party modules. As a developer, |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 53 | your responsibilities (apart from writing solid, well-documented and |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 54 | well-tested code, of course!) are: |
| 55 | \begin{itemize} |
| 56 | \item write a setup script (\file{setup.py} by convention) |
| 57 | \item (optional) write a setup configuration file |
| 58 | \item create a source distribution |
| 59 | \item (optional) create one or more built (binary) distributions |
| 60 | \end{itemize} |
| 61 | Each of these tasks is covered in this document. |
| 62 | |
| 63 | Not all module developers have access to a multitude of platforms, so |
| 64 | it's not always feasible to expect them to create a multitude of built |
| 65 | distributions. It is hoped that a class of intermediaries, called |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 66 | \emph{packagers}, will arise to address this need. Packagers will take |
| 67 | source distributions released by module developers, build them on one or |
| 68 | more platforms, and release the resulting built distributions. Thus, |
| 69 | users on the most popular platforms will be able to install most popular |
| 70 | Python module distributions in the most natural way for their platform, |
| 71 | 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] | 72 | |
| 73 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 74 | \subsection{A Simple Example} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 75 | \label{simple-example} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 76 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 77 | The setup script is usually quite simple, although since it's written |
| 78 | in Python, there are no arbitrary limits to what you can do with it, |
| 79 | though you should be careful about putting arbitrarily expensive |
| 80 | operations in your setup script. Unlike, say, Autoconf-style configure |
| 81 | scripts, the setup script may be run multiple times in the course of |
Andrew M. Kuchling | e9a54a3 | 2003-05-13 15:02:06 +0000 | [diff] [blame] | 82 | building and installing your module distribution. |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 83 | |
| 84 | If all you want to do is distribute a module called \module{foo}, |
| 85 | contained in a file \file{foo.py}, then your setup script can be as |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 86 | simple as this: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 87 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 88 | \begin{verbatim} |
| 89 | from distutils.core import setup |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 90 | setup(name="foo", |
| 91 | version="1.0", |
| 92 | py_modules=["foo"]) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 93 | \end{verbatim} |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 94 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 95 | Some observations: |
| 96 | \begin{itemize} |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 97 | \item most information that you supply to the Distutils is supplied as |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 98 | keyword arguments to the \function{setup()} function |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 99 | \item those keyword arguments fall into two categories: package |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 100 | metadata (name, version number) and information about what's in the |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 101 | package (a list of pure Python modules, in this case) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 102 | \item modules are specified by module name, not filename (the same will |
| 103 | hold true for packages and extensions) |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 104 | \item it's recommended that you supply a little more metadata, in |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 105 | particular your name, email address and a URL for the project |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 106 | (see section~\ref{setup-script} for an example) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 107 | \end{itemize} |
| 108 | |
Greg Ward | 370248d | 2000-06-24 01:45:47 +0000 | [diff] [blame] | 109 | To create a source distribution for this module, you would create a |
| 110 | setup script, \file{setup.py}, containing the above code, and run: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 111 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 112 | \begin{verbatim} |
| 113 | python setup.py sdist |
| 114 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 115 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 116 | which will create an archive file (e.g., tarball on \UNIX, ZIP file on |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 117 | Windows) containing your setup script \file{setup.py}, and your module |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 118 | \file{foo.py}. The archive file will be named \file{foo-1.0.tar.gz} (or |
| 119 | \file{.zip}), and will unpack into a directory \file{foo-1.0}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 120 | |
| 121 | If an end-user wishes to install your \module{foo} module, all she has |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 122 | to do is download \file{foo-1.0.tar.gz} (or \file{.zip}), unpack it, |
| 123 | and---from the \file{foo-1.0} directory---run |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 124 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 125 | \begin{verbatim} |
| 126 | python setup.py install |
| 127 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 128 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 129 | which will ultimately copy \file{foo.py} to the appropriate directory |
| 130 | for third-party modules in their Python installation. |
| 131 | |
| 132 | This simple example demonstrates some fundamental concepts of the |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 133 | Distutils. First, both developers and installers have the same basic |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 134 | user interface, i.e. the setup script. The difference is which |
| 135 | Distutils \emph{commands} they use: the \command{sdist} command is |
| 136 | almost exclusively for module developers, while \command{install} is |
| 137 | more often for installers (although most developers will want to install |
| 138 | their own code occasionally). |
| 139 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 140 | If you want to make things really easy for your users, you can create |
| 141 | one or more built distributions for them. For instance, if you are |
| 142 | running on a Windows machine, and want to make things easy for other |
| 143 | Windows users, you can create an executable installer (the most |
| 144 | appropriate type of built distribution for this platform) with the |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 145 | \command{bdist\_wininst} command. For example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 146 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 147 | \begin{verbatim} |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 148 | python setup.py bdist_wininst |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 149 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 150 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 151 | will create an executable installer, \file{foo-1.0.win32.exe}, in the |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 152 | current directory. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 153 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 154 | Other useful built distribution formats are RPM, implemented by the |
| 155 | \command{bdist\_rpm} command, Solaris \program{pkgtool} |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 156 | (\command{bdist\_pkgtool}), and HP-UX \program{swinstall} |
| 157 | (\command{bdist_sdux}). For example, the following command will |
| 158 | create an RPM file called \file{foo-1.0.noarch.rpm}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 159 | |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 160 | \begin{verbatim} |
| 161 | python setup.py bdist_rpm |
| 162 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 163 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 164 | (The \command{bdist\_rpm} command uses the \command{rpm} executable, |
| 165 | therefore this has to be run on an RPM-based system such as Red Hat |
| 166 | Linux, SuSE Linux, or Mandrake Linux.) |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 167 | |
| 168 | You can find out what distribution formats are available at any time by |
| 169 | running |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 170 | |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 171 | \begin{verbatim} |
| 172 | python setup.py bdist --help-formats |
| 173 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 174 | |
| 175 | |
| 176 | \subsection{General Python terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 177 | \label{python-terms} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 178 | |
| 179 | If you're reading this document, you probably have a good idea of what |
| 180 | modules, extensions, and so forth are. Nevertheless, just to be sure |
| 181 | that everyone is operating from a common starting point, we offer the |
| 182 | following glossary of common Python terms: |
| 183 | \begin{description} |
| 184 | \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] | 185 | code imported by some other code. Three types of modules concern us |
| 186 | here: pure Python modules, extension modules, and packages. |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 187 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 188 | \item[pure Python module] a module written in Python and contained in a |
| 189 | single \file{.py} file (and possibly associated \file{.pyc} and/or |
| 190 | \file{.pyo} files). Sometimes referred to as a ``pure module.'' |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 191 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 192 | \item[extension module] a module written in the low-level language of |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 193 | the Python implementation: C/\Cpp{} for Python, Java for Jython. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 194 | Typically contained in a single dynamically loadable pre-compiled |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 195 | file, e.g. a shared object (\file{.so}) file for Python extensions on |
| 196 | \UNIX, a DLL (given the \file{.pyd} extension) for Python extensions |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 197 | on Windows, or a Java class file for Jython extensions. (Note that |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 198 | currently, the Distutils only handles C/\Cpp{} extensions for Python.) |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 199 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 200 | \item[package] a module that contains other modules; typically contained |
| 201 | in a directory in the filesystem and distinguished from other |
| 202 | directories by the presence of a file \file{\_\_init\_\_.py}. |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 203 | |
Greg Ward | 6153fa1 | 2000-05-26 02:24:28 +0000 | [diff] [blame] | 204 | \item[root package] the root of the hierarchy of packages. (This isn't |
| 205 | really a package, since it doesn't have an \file{\_\_init\_\_.py} |
| 206 | file. But we have to call it something.) The vast majority of the |
| 207 | standard library is in the root package, as are many small, standalone |
| 208 | third-party modules that don't belong to a larger module collection. |
| 209 | Unlike regular packages, modules in the root package can be found in |
| 210 | many directories: in fact, every directory listed in \code{sys.path} |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 211 | contributes modules to the root package. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 212 | \end{description} |
| 213 | |
| 214 | |
| 215 | \subsection{Distutils-specific terminology} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 216 | \label{distutils-term} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 217 | |
| 218 | The following terms apply more specifically to the domain of |
| 219 | distributing Python modules using the Distutils: |
| 220 | \begin{description} |
| 221 | \item[module distribution] a collection of Python modules distributed |
| 222 | together as a single downloadable resource and meant to be installed |
| 223 | \emph{en masse}. Examples of some well-known module distributions are |
| 224 | Numeric Python, PyXML, PIL (the Python Imaging Library), or |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 225 | mxBase. (This would be called a \emph{package}, except that term |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 226 | is already taken in the Python context: a single module distribution |
| 227 | may contain zero, one, or many Python packages.) |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 228 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 229 | \item[pure module distribution] a module distribution that contains only |
| 230 | pure Python modules and packages. Sometimes referred to as a ``pure |
| 231 | distribution.'' |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 232 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 233 | \item[non-pure module distribution] a module distribution that contains |
| 234 | at least one extension module. Sometimes referred to as a ``non-pure |
| 235 | distribution.'' |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 236 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 237 | \item[distribution root] the top-level directory of your source tree (or |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 238 | source distribution); the directory where \file{setup.py} exists. Generally |
| 239 | \file{setup.py} will be run from this directory. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 240 | \end{description} |
| 241 | |
| 242 | |
| 243 | \section{Writing the Setup Script} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 244 | \label{setup-script} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 245 | |
| 246 | The setup script is the centre of all activity in building, |
| 247 | distributing, and installing modules using the Distutils. The main |
| 248 | purpose of the setup script is to describe your module distribution to |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 249 | the Distutils, so that the various commands that operate on your modules |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 250 | do the right thing. As we saw in section~\ref{simple-example} above, |
| 251 | the setup script consists mainly of a call to \function{setup()}, and |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 252 | most information supplied to the Distutils by the module developer is |
| 253 | supplied as keyword arguments to \function{setup()}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 254 | |
| 255 | Here's a slightly more involved example, which we'll follow for the next |
| 256 | couple of sections: the Distutils' own setup script. (Keep in mind that |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 257 | although the Distutils are included with Python 1.6 and later, they also |
| 258 | have an independent existence so that Python 1.5.2 users can use them to |
| 259 | install other module distributions. The Distutils' own setup script, |
| 260 | 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] | 261 | |
| 262 | \begin{verbatim} |
| 263 | #!/usr/bin/env python |
| 264 | |
| 265 | from distutils.core import setup |
| 266 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 267 | setup(name="Distutils", |
| 268 | version="1.0", |
| 269 | description="Python Distribution Utilities", |
| 270 | author="Greg Ward", |
| 271 | author_email="gward@python.net", |
| 272 | url="http://www.python.org/sigs/distutils-sig/", |
| 273 | packages=['distutils', 'distutils.command'], |
| 274 | ) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 275 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 276 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 277 | There are only two differences between this and the trivial one-file |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 278 | distribution presented in section~\ref{simple-example}: more |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 279 | metadata, and the specification of pure Python modules by package, |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 280 | rather than by module. This is important since the Distutils consist of |
| 281 | a couple of dozen modules split into (so far) two packages; an explicit |
| 282 | list of every module would be tedious to generate and difficult to |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 283 | maintain. For more information on the additional meta-data, see |
| 284 | section~\ref{meta-data}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 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 |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39: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 |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39: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 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 297 | This, of course, only applies to pathnames given to Distutils |
Fred Drake | 2a04623 | 2003-03-31 16:23:09 +0000 | [diff] [blame] | 298 | functions. If you, for example, use standard Python functions such as |
| 299 | \function{glob.glob()} or \function{os.listdir()} to specify files, you |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 300 | should be careful to write portable code instead of hardcoding path |
| 301 | separators: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 302 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 303 | \begin{verbatim} |
| 304 | glob.glob(os.path.join('mydir', 'subdir', '*.html')) |
| 305 | os.listdir(os.path.join('mydir', 'subdir')) |
| 306 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 307 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 308 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 309 | \subsection{Listing whole packages} |
| 310 | \label{listing-packages} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 311 | |
| 312 | The \option{packages} option tells the Distutils to process (build, |
| 313 | distribute, install, etc.) all pure Python modules found in each package |
| 314 | mentioned in the \option{packages} list. In order to do this, of |
| 315 | course, there has to be a correspondence between package names and |
| 316 | directories in the filesystem. The default correspondence is the most |
Greg Ward | 1ecc251 | 2000-04-19 22:36:24 +0000 | [diff] [blame] | 317 | obvious one, i.e. package \module{distutils} is found in the directory |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 318 | \file{distutils} relative to the distribution root. Thus, when you say |
| 319 | \code{packages = ['foo']} in your setup script, you are promising that |
| 320 | the Distutils will find a file \file{foo/\_\_init\_\_.py} (which might |
| 321 | be spelled differently on your system, but you get the idea) relative to |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 322 | the directory where your setup script lives. If you break this |
| 323 | promise, the Distutils will issue a warning but still process the broken |
| 324 | package anyways. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 325 | |
| 326 | If you use a different convention to lay out your source directory, |
| 327 | that's no problem: you just have to supply the \option{package\_dir} |
| 328 | option to tell the Distutils about your convention. For example, say |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 329 | you keep all Python source under \file{lib}, so that modules in the |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 330 | ``root package'' (i.e., not in any package at all) are in |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 331 | \file{lib}, modules in the \module{foo} package are in \file{lib/foo}, |
| 332 | and so forth. Then you would put |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 333 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 334 | \begin{verbatim} |
| 335 | package_dir = {'': 'lib'} |
| 336 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 337 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 338 | in your setup script. The keys to this dictionary are package names, |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 339 | and an empty package name stands for the root package. The values are |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 340 | directory names relative to your distribution root. In this case, when |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 341 | you say \code{packages = ['foo']}, you are promising that the file |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 342 | \file{lib/foo/\_\_init\_\_.py} exists. |
| 343 | |
Greg Ward | 1ecc251 | 2000-04-19 22:36:24 +0000 | [diff] [blame] | 344 | Another possible convention is to put the \module{foo} package right in |
| 345 | \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] | 346 | would be written in the setup script as |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 347 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 348 | \begin{verbatim} |
| 349 | package_dir = {'foo': 'lib'} |
| 350 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 351 | |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 352 | A \code{\var{package}: \var{dir}} entry in the \option{package\_dir} |
| 353 | dictionary implicitly applies to all packages below \var{package}, so |
| 354 | the \module{foo.bar} case is automatically handled here. In this |
| 355 | example, having \code{packages = ['foo', 'foo.bar']} tells the Distutils |
| 356 | to look for \file{lib/\_\_init\_\_.py} and |
| 357 | \file{lib/bar/\_\_init\_\_.py}. (Keep in mind that although |
| 358 | \option{package\_dir} applies recursively, you must explicitly list all |
| 359 | packages in \option{packages}: the Distutils will \emph{not} recursively |
| 360 | scan your source tree looking for any directory with an |
| 361 | \file{\_\_init\_\_.py} file.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 362 | |
| 363 | |
| 364 | \subsection{Listing individual modules} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 365 | \label{listing-modules} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 366 | |
| 367 | For a small module distribution, you might prefer to list all modules |
| 368 | rather than listing packages---especially the case of a single module |
| 369 | 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] | 370 | simplest case was shown in section~\ref{simple-example}; here is a |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 371 | slightly more involved example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 372 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 373 | \begin{verbatim} |
| 374 | py_modules = ['mod1', 'pkg.mod2'] |
| 375 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 376 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 377 | This describes two modules, one of them in the ``root'' package, the |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 378 | other in the \module{pkg} package. Again, the default package/directory |
| 379 | layout implies that these two modules can be found in \file{mod1.py} and |
| 380 | \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] | 381 | And again, you can override the package/directory correspondence using |
| 382 | the \option{package\_dir} option. |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 383 | |
| 384 | |
| 385 | \subsection{Describing extension modules} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 386 | \label{describing-extensions} |
Greg Ward | 59d382e | 2000-05-26 01:04:47 +0000 | [diff] [blame] | 387 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 388 | % XXX read over this section |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 389 | Just as writing Python extension modules is a bit more complicated than |
| 390 | writing pure Python modules, describing them to the Distutils is a bit |
| 391 | more complicated. Unlike pure modules, it's not enough just to list |
| 392 | modules or packages and expect the Distutils to go out and find the |
| 393 | right files; you have to specify the extension name, source file(s), and |
| 394 | any compile/link requirements (include directories, libraries to link |
| 395 | with, etc.). |
| 396 | |
| 397 | All of this is done through another keyword argument to |
| 398 | \function{setup()}, the \option{extensions} option. \option{extensions} |
| 399 | is just a list of \class{Extension} instances, each of which describes a |
| 400 | single extension module. Suppose your distribution includes a single |
| 401 | extension, called \module{foo} and implemented by \file{foo.c}. If no |
| 402 | additional instructions to the compiler/linker are needed, describing |
| 403 | this extension is quite simple: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 404 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 405 | \begin{verbatim} |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 406 | uExtension("foo", ["foo.c"]) |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 407 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 408 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 409 | The \class{Extension} class can be imported from |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 410 | \module{distutils.core} along with \function{setup()}. Thus, the setup |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 411 | script for a module distribution that contains only this one extension |
| 412 | and nothing else might be: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 413 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 414 | \begin{verbatim} |
| 415 | from distutils.core import setup, Extension |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 416 | setup(name="foo", version="1.0", |
| 417 | ext_modules=[Extension("foo", ["foo.c"])]) |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 418 | \end{verbatim} |
| 419 | |
| 420 | The \class{Extension} class (actually, the underlying extension-building |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 421 | machinery implemented by the \command{build\_ext} command) supports a |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 422 | great deal of flexibility in describing Python extensions, which is |
| 423 | explained in the following sections. |
| 424 | |
| 425 | |
| 426 | \subsubsection{Extension names and packages} |
| 427 | |
| 428 | The first argument to the \class{Extension} constructor is always the |
| 429 | name of the extension, including any package names. For example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 430 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 431 | \begin{verbatim} |
| 432 | Extension("foo", ["src/foo1.c", "src/foo2.c"]) |
| 433 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 434 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 435 | describes an extension that lives in the root package, while |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 436 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 437 | \begin{verbatim} |
| 438 | Extension("pkg.foo", ["src/foo1.c", "src/foo2.c"]) |
| 439 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 440 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 441 | describes the same extension in the \module{pkg} package. The source |
| 442 | files and resulting object code are identical in both cases; the only |
| 443 | difference is where in the filesystem (and therefore where in Python's |
| 444 | namespace hierarchy) the resulting extension lives. |
| 445 | |
| 446 | If you have a number of extensions all in the same package (or all under |
| 447 | the same base package), use the \option{ext\_package} keyword argument |
| 448 | to \function{setup()}. For example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 449 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 450 | \begin{verbatim} |
| 451 | setup(... |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 452 | ext_package="pkg", |
| 453 | ext_modules=[Extension("foo", ["foo.c"]), |
| 454 | Extension("subpkg.bar", ["bar.c"])] |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 455 | ) |
| 456 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 457 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 458 | will compile \file{foo.c} to the extension \module{pkg.foo}, and |
| 459 | \file{bar.c} to \module{pkg.subpkg.bar}. |
| 460 | |
| 461 | |
| 462 | \subsubsection{Extension source files} |
| 463 | |
| 464 | The second argument to the \class{Extension} constructor is a list of |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 465 | source files. Since the Distutils currently only support C, \Cpp, and |
| 466 | Objective-C extensions, these are normally C/\Cpp/Objective-C source |
| 467 | files. (Be sure to use appropriate extensions to distinguish \Cpp\ |
| 468 | source files: \file{.cc} and \file{.cpp} seem to be recognized by both |
| 469 | \UNIX{} and Windows compilers.) |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 470 | |
| 471 | However, you can also include SWIG interface (\file{.i}) files in the |
| 472 | list; the \command{build\_ext} command knows how to deal with SWIG |
| 473 | extensions: it will run SWIG on the interface file and compile the |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 474 | resulting C/\Cpp{} file into your extension. |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 475 | |
| 476 | \XXX{SWIG support is rough around the edges and largely untested; |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 477 | especially SWIG support for \Cpp{} extensions! Explain in more detail |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 478 | here when the interface firms up.} |
| 479 | |
| 480 | On some platforms, you can include non-source files that are processed |
| 481 | by the compiler and included in your extension. Currently, this just |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 482 | means Windows message text (\file{.mc}) files and resource definition |
Fred Drake | 2884d6d | 2003-07-02 12:27:43 +0000 | [diff] [blame] | 483 | (\file{.rc}) files for Visual \Cpp. These will be compiled to binary resource |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 484 | (\file{.res}) files and linked into the executable. |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 485 | |
| 486 | |
| 487 | \subsubsection{Preprocessor options} |
| 488 | |
| 489 | Three optional arguments to \class{Extension} will help if you need to |
| 490 | specify include directories to search or preprocessor macros to |
| 491 | define/undefine: \code{include\_dirs}, \code{define\_macros}, and |
| 492 | \code{undef\_macros}. |
| 493 | |
| 494 | For example, if your extension requires header files in the |
| 495 | \file{include} directory under your distribution root, use the |
| 496 | \code{include\_dirs} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 497 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 498 | \begin{verbatim} |
| 499 | Extension("foo", ["foo.c"], include_dirs=["include"]) |
| 500 | \end{verbatim} |
| 501 | |
| 502 | You can specify absolute directories there; if you know that your |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 503 | extension will only be built on \UNIX{} systems with X11R6 installed to |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 504 | \file{/usr}, you can get away with |
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 | \begin{verbatim} |
| 507 | Extension("foo", ["foo.c"], include_dirs=["/usr/include/X11"]) |
| 508 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 509 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 510 | You should avoid this sort of non-portable usage if you plan to |
Greg Ward | 58437f2 | 2002-05-10 14:40:22 +0000 | [diff] [blame] | 511 | distribute your code: it's probably better to write C code like |
| 512 | \begin{verbatim} |
| 513 | #include <X11/Xlib.h> |
| 514 | \end{verbatim} |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 515 | |
| 516 | If you need to include header files from some other Python extension, |
Greg Ward | 58437f2 | 2002-05-10 14:40:22 +0000 | [diff] [blame] | 517 | you can take advantage of the fact that header files are installed in a |
| 518 | consistent way by the Distutils \command{install\_header} command. For |
| 519 | example, the Numerical Python header files are installed (on a standard |
| 520 | Unix installation) to \file{/usr/local/include/python1.5/Numerical}. |
| 521 | (The exact location will differ according to your platform and Python |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 522 | installation.) Since the Python include |
Greg Ward | 58437f2 | 2002-05-10 14:40:22 +0000 | [diff] [blame] | 523 | directory---\file{/usr/local/include/python1.5} in this case---is always |
| 524 | included in the search path when building Python extensions, the best |
| 525 | approach is to write C code like |
| 526 | \begin{verbatim} |
| 527 | #include <Numerical/arrayobject.h> |
| 528 | \end{verbatim} |
| 529 | If you must put the \file{Numerical} include directory right into your |
| 530 | header search path, though, you can find that directory using the |
| 531 | Distutils \module{sysconfig} module: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 532 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 533 | \begin{verbatim} |
| 534 | from distutils.sysconfig import get_python_inc |
| 535 | incdir = os.path.join(get_python_inc(plat_specific=1), "Numerical") |
| 536 | setup(..., |
| 537 | Extension(..., include_dirs=[incdir])) |
| 538 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 539 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 540 | Even though this is quite portable---it will work on any Python |
| 541 | installation, regardless of platform---it's probably easier to just |
| 542 | write your C code in the sensible way. |
| 543 | |
| 544 | You can define and undefine pre-processor macros with the |
| 545 | \code{define\_macros} and \code{undef\_macros} options. |
| 546 | \code{define\_macros} takes a list of \code{(name, value)} tuples, where |
| 547 | \code{name} is the name of the macro to define (a string) and |
| 548 | \code{value} is its value: either a string or \code{None}. (Defining a |
| 549 | macro \code{FOO} to \code{None} is the equivalent of a bare |
| 550 | \code{\#define FOO} in your C source: with most compilers, this sets |
| 551 | \code{FOO} to the string \code{1}.) \code{undef\_macros} is just |
| 552 | a list of macros to undefine. |
| 553 | |
| 554 | For example: |
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 | Extension(..., |
Thomas Heller | 95a97d5 | 2003-10-08 12:01:33 +0000 | [diff] [blame] | 558 | define_macros=[('NDEBUG', '1'), |
| 559 | ('HAVE_STRFTIME', None)], |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 560 | undef_macros=['HAVE_FOO', 'HAVE_BAR']) |
| 561 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 562 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 563 | 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] | 564 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 565 | \begin{verbatim} |
| 566 | #define NDEBUG 1 |
| 567 | #define HAVE_STRFTIME |
| 568 | #undef HAVE_FOO |
| 569 | #undef HAVE_BAR |
| 570 | \end{verbatim} |
| 571 | |
| 572 | |
| 573 | \subsubsection{Library options} |
| 574 | |
| 575 | You can also specify the libraries to link against when building your |
| 576 | extension, and the directories to search for those libraries. The |
| 577 | \code{libraries} option is a list of libraries to link against, |
| 578 | \code{library\_dirs} is a list of directories to search for libraries at |
| 579 | link-time, and \code{runtime\_library\_dirs} is a list of directories to |
| 580 | search for shared (dynamically loaded) libraries at run-time. |
| 581 | |
| 582 | For example, if you need to link against libraries known to be in the |
| 583 | standard library search path on target systems |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 584 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 585 | \begin{verbatim} |
| 586 | Extension(..., |
| 587 | libraries=["gdbm", "readline"]) |
| 588 | \end{verbatim} |
| 589 | |
| 590 | If you need to link with libraries in a non-standard location, you'll |
| 591 | have to include the location in \code{library\_dirs}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 592 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 593 | \begin{verbatim} |
| 594 | Extension(..., |
| 595 | library_dirs=["/usr/X11R6/lib"], |
| 596 | libraries=["X11", "Xt"]) |
| 597 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 598 | |
Greg Ward | 2afffd4 | 2000-08-06 20:37:24 +0000 | [diff] [blame] | 599 | (Again, this sort of non-portable construct should be avoided if you |
| 600 | intend to distribute your code.) |
| 601 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 602 | \XXX{Should mention clib libraries here or somewhere else!} |
| 603 | |
| 604 | \subsubsection{Other options} |
| 605 | |
| 606 | There are still some other options which can be used to handle special |
| 607 | cases. |
| 608 | |
| 609 | The \option{extra\_objects} option is a list of object files to be passed |
| 610 | to the linker. These files must not have extensions, as the default |
| 611 | extension for the compiler is used. |
| 612 | |
| 613 | \option{extra\_compile\_args} and \option{extra\_link\_args} can be used |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 614 | to specify additional command line options for the respective compiler and |
| 615 | linker command lines. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 616 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 617 | \option{export\_symbols} is only useful on Windows. It can contain a list |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 618 | of symbols (functions or variables) to be exported. This option |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 619 | is not needed when building compiled extensions: Distutils |
| 620 | will automatically add \code{initmodule} |
| 621 | to the list of exported symbols. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 622 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 623 | \subsection{Installing Scripts} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 624 | So far we have been dealing with pure and non-pure Python modules, |
| 625 | which are usually not run by themselves but imported by scripts. |
| 626 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 627 | Scripts are files containing Python source code, intended to be |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 628 | started from the command line. Scripts don't require Distutils to do |
| 629 | anything very complicated. The only clever feature is that if the |
| 630 | first line of the script starts with \code{\#!} and contains the word |
| 631 | ``python'', the Distutils will adjust the first line to refer to the |
| 632 | current interpreter location. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 633 | |
| 634 | The \option{scripts} option simply is a list of files to be handled |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 635 | in this way. From the PyXML setup script: |
| 636 | |
| 637 | \begin{verbatim} |
| 638 | setup (... |
| 639 | scripts = ['scripts/xmlproc_parse', 'scripts/xmlproc_val'] |
| 640 | ) |
| 641 | \end{verbatim} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 642 | |
| 643 | |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 644 | \subsection{Installing Additional Files} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 645 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 646 | The \option{data\_files} option can be used to specify additional |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 647 | files needed by the module distribution: configuration files, message |
| 648 | catalogs, data files, anything which doesn't fit in the previous |
| 649 | categories. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 650 | |
Fred Drake | 632bda3 | 2002-03-08 22:02:06 +0000 | [diff] [blame] | 651 | \option{data\_files} specifies a sequence of (\var{directory}, |
| 652 | \var{files}) pairs in the following way: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 653 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 654 | \begin{verbatim} |
| 655 | setup(... |
| 656 | data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']), |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 657 | ('config', ['cfg/data.cfg']), |
| 658 | ('/etc/init.d', ['init-script'])] |
| 659 | ) |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 660 | \end{verbatim} |
| 661 | |
| 662 | Note that you can specify the directory names where the data files |
| 663 | will be installed, but you cannot rename the data files themselves. |
| 664 | |
Fred Drake | 632bda3 | 2002-03-08 22:02:06 +0000 | [diff] [blame] | 665 | Each (\var{directory}, \var{files}) pair in the sequence specifies the |
| 666 | installation directory and the files to install there. If |
| 667 | \var{directory} is a relative path, it is interpreted relative to the |
| 668 | installation prefix (Python's \code{sys.prefix} for pure-Python |
| 669 | packages, \code{sys.exec_prefix} for packages that contain extension |
| 670 | modules). Each file name in \var{files} is interpreted relative to |
| 671 | the \file{setup.py} script at the top of the package source |
| 672 | distribution. No directory information from \var{files} is used to |
| 673 | determine the final location of the installed file; only the name of |
| 674 | the file is used. |
| 675 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 676 | You can specify the \option{data\_files} options as a simple sequence |
| 677 | of files without specifying a target directory, but this is not recommended, |
| 678 | and the \command{install} command will print a warning in this case. |
| 679 | To install data files directly in the target directory, an empty |
| 680 | string should be given as the directory. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 681 | |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 682 | \subsection{Additional meta-data} |
| 683 | \label{meta-data} |
| 684 | |
| 685 | The setup script may include additional meta-data beyond the name and |
| 686 | version. This information includes: |
| 687 | |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 688 | \begin{tableiv}{l|l|l|c}{code}% |
| 689 | {Meta-Data}{Description}{Value}{Notes} |
| 690 | \lineiv{name}{name of the package} |
| 691 | {short string}{(1)} |
| 692 | \lineiv{version}{version of this release} |
| 693 | {short string}{(1)(2)} |
| 694 | \lineiv{author}{package author's name} |
| 695 | {short string}{(3)} |
| 696 | \lineiv{author_email}{email address of the package author} |
| 697 | {email address}{(3)} |
| 698 | \lineiv{maintainer}{package maintainer's name} |
| 699 | {short string}{(3)} |
| 700 | \lineiv{maintainer_email}{email address of the package maintainer} |
| 701 | {email address}{(3)} |
| 702 | \lineiv{url}{home page for the package} |
| 703 | {URL}{(1)} |
| 704 | \lineiv{description}{short, summary description of the package} |
| 705 | {short string}{} |
| 706 | \lineiv{long_description}{longer description of the package} |
| 707 | {long string}{} |
| 708 | \lineiv{download_url}{location where the package may be downloaded} |
| 709 | {URL}{(4)} |
| 710 | \lineiv{classifiers}{a list of Trove classifiers} |
| 711 | {list of strings}{(4)} |
| 712 | \end{tableiv} |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 713 | |
| 714 | \noindent Notes: |
| 715 | \begin{description} |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 716 | \item[(1)] These fields are required. |
| 717 | \item[(2)] It is recommended that versions take the form |
| 718 | \emph{major.minor\optional{.patch\optional{.sub}}}. |
| 719 | \item[(3)] Either the author or the maintainer must be identified. |
| 720 | \item[(4)] These fields should not be used if your package is to be |
| 721 | compatible with Python versions prior to 2.2.3 or 2.3. The list is |
| 722 | available from the \ulink{PyPI website}{http://www.python.org/pypi}. |
| 723 | |
| 724 | \item["short string"] A single line of text, not more than 200 characters. |
| 725 | \item["long string"] Multiple lines of plain text in ReStructuredText |
| 726 | format (see \url{http://docutils.sf.net/}). |
| 727 | \item["list of strings"] See below. |
| 728 | \end{description} |
| 729 | |
| 730 | None of the string values may be Unicode. |
| 731 | |
| 732 | Encoding the version information is an art in itself. Python packages |
| 733 | generally adhere to the version format |
| 734 | \emph{major.minor\optional{.patch}\optional{sub}}. The major number is |
| 735 | 0 for |
| 736 | initial, experimental releases of software. It is incremented for |
| 737 | releases that represent major milestones in a package. The minor |
| 738 | number is incremented when important new features are added to the |
| 739 | package. The patch number increments when bug-fix releases are |
| 740 | made. Additional trailing version information is sometimes used to |
| 741 | indicate sub-releases. These are "a1,a2,...,aN" (for alpha releases, |
| 742 | where functionality and API may change), "b1,b2,...,bN" (for beta |
| 743 | releases, which only fix bugs) and "pr1,pr2,...,prN" (for final |
| 744 | pre-release release testing). Some examples: |
| 745 | |
| 746 | \begin{description} |
| 747 | \item[0.1.0] the first, experimental release of a package |
| 748 | \item[1.0.1a2] the second alpha release of the first patch version of 1.0 |
| 749 | \end{description} |
| 750 | |
| 751 | \option{classifiers} are specified in a python list: |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 752 | |
| 753 | \begin{verbatim} |
| 754 | setup(... |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 755 | classifiers = [ |
Fred Drake | 2a04623 | 2003-03-31 16:23:09 +0000 | [diff] [blame] | 756 | 'Development Status :: 4 - Beta', |
| 757 | 'Environment :: Console', |
| 758 | 'Environment :: Web Environment', |
| 759 | 'Intended Audience :: End Users/Desktop', |
| 760 | 'Intended Audience :: Developers', |
| 761 | 'Intended Audience :: System Administrators', |
| 762 | 'License :: OSI Approved :: Python Software Foundation License', |
| 763 | 'Operating System :: MacOS :: MacOS X', |
| 764 | 'Operating System :: Microsoft :: Windows', |
| 765 | 'Operating System :: POSIX', |
| 766 | 'Programming Language :: Python', |
| 767 | 'Topic :: Communications :: Email', |
| 768 | 'Topic :: Office/Business', |
| 769 | 'Topic :: Software Development :: Bug Tracking', |
| 770 | ], |
Fred Drake | 2a04623 | 2003-03-31 16:23:09 +0000 | [diff] [blame] | 771 | ) |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 772 | \end{verbatim} |
| 773 | |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 774 | If you wish to include classifiers in your \file{setup.py} file and also |
| 775 | wish to remain backwards-compatible with Python releases prior to 2.2.3, |
| 776 | then you can include the following code fragment in your \file{setup.py} |
| 777 | before the \code{setup()} call. |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 778 | |
| 779 | \begin{verbatim} |
Fred Drake | c440af5 | 2003-04-25 16:43:28 +0000 | [diff] [blame] | 780 | # patch distutils if it can't cope with the "classifiers" or |
| 781 | # "download_url" keywords |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 782 | if sys.version < '2.2.3': |
| 783 | from distutils.dist import DistributionMetadata |
| 784 | DistributionMetadata.classifiers = None |
Fred Drake | 2a04623 | 2003-03-31 16:23:09 +0000 | [diff] [blame] | 785 | DistributionMetadata.download_url = None |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 786 | \end{verbatim} |
| 787 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 788 | |
Thomas Heller | 675580f | 2003-06-30 19:33:29 +0000 | [diff] [blame] | 789 | \subsection{Debugging the setup script} |
| 790 | \label{meta-data} |
| 791 | |
| 792 | Sometimes things go wrong, and the setup script doesn't do what the |
| 793 | developer wants. |
| 794 | |
| 795 | Distutils catches any exceptions when running the setup script, and |
| 796 | print a simple error message before the script is terminated. The |
| 797 | motivation for this behaviour is to not confuse administrators who |
| 798 | don't know much about Python and are trying to install a package. If |
| 799 | they get a big long traceback from deep inside the guts of Distutils, |
| 800 | they may think the package or the Python installation is broken |
| 801 | because they don't read all the way down to the bottom and see that |
| 802 | it's a permission problem. |
| 803 | |
| 804 | On the other hand, this doesn't help the developer to find the cause |
| 805 | of the failure. For this purpose, the DISTUTILS_DEBUG environment |
| 806 | variable can be set to anything except an empty string, and distutils |
| 807 | will now print detailed information what it is doing, and prints the |
Martin v. Löwis | 95cf84a | 2003-10-19 07:32:24 +0000 | [diff] [blame] | 808 | full traceback in case an exception occurs. |
Thomas Heller | 675580f | 2003-06-30 19:33:29 +0000 | [diff] [blame] | 809 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 810 | \section{Writing the Setup Configuration File} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 811 | \label{setup-config} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 812 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 813 | 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] | 814 | distribution \emph{a priori}: you may need to get some information from |
| 815 | the user, or from the user's system, in order to proceed. As long as |
| 816 | that information is fairly simple---a list of directories to search for |
| 817 | C header files or libraries, for example---then providing a |
| 818 | configuration file, \file{setup.cfg}, for users to edit is a cheap and |
| 819 | easy way to solicit it. Configuration files also let you provide |
| 820 | default values for any command option, which the installer can then |
| 821 | override either on the command-line or by editing the config file. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 822 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 823 | % (If you have more advanced needs, such as determining which extensions |
| 824 | % to build based on what capabilities are present on the target system, |
| 825 | % then you need the Distutils ``auto-configuration'' facility. This |
| 826 | % started to appear in Distutils 0.9 but, as of this writing, isn't mature |
| 827 | % or stable enough yet for real-world use.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 828 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 829 | The setup configuration file is a useful middle-ground between the setup |
| 830 | script---which, ideally, would be opaque to installers\footnote{This |
| 831 | ideal probably won't be achieved until auto-configuration is fully |
| 832 | supported by the Distutils.}---and the command-line to the setup |
| 833 | script, which is outside of your control and entirely up to the |
| 834 | installer. In fact, \file{setup.cfg} (and any other Distutils |
| 835 | configuration files present on the target system) are processed after |
| 836 | the contents of the setup script, but before the command-line. This has |
| 837 | several useful consequences: |
| 838 | \begin{itemize} |
| 839 | \item installers can override some of what you put in \file{setup.py} by |
| 840 | editing \file{setup.cfg} |
| 841 | \item you can provide non-standard defaults for options that are not |
| 842 | easily set in \file{setup.py} |
| 843 | \item installers can override anything in \file{setup.cfg} using the |
| 844 | command-line options to \file{setup.py} |
| 845 | \end{itemize} |
| 846 | |
| 847 | The basic syntax of the configuration file is simple: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 848 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 849 | \begin{verbatim} |
| 850 | [command] |
| 851 | option=value |
| 852 | ... |
| 853 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 854 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 855 | where \var{command} is one of the Distutils commands (e.g. |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 856 | \command{build\_py}, \command{install}), and \var{option} is one of |
| 857 | the options that command supports. Any number of options can be |
| 858 | supplied for each command, and any number of command sections can be |
| 859 | included in the file. Blank lines are ignored, as are comments, which |
| 860 | run from a \character{\#} character until the end of the line. Long |
| 861 | option values can be split across multiple lines simply by indenting |
| 862 | the continuation lines. |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 863 | |
| 864 | You can find out the list of options supported by a particular command |
| 865 | with the universal \longprogramopt{help} option, e.g. |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 866 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 867 | \begin{verbatim} |
| 868 | > python setup.py --help build_ext |
| 869 | [...] |
| 870 | Options for 'build_ext' command: |
| 871 | --build-lib (-b) directory for compiled extension modules |
| 872 | --build-temp (-t) directory for temporary files (build by-products) |
| 873 | --inplace (-i) ignore build-lib and put compiled extensions into the |
| 874 | source directory alongside your pure Python modules |
| 875 | --include-dirs (-I) list of directories to search for header files |
| 876 | --define (-D) C preprocessor macros to define |
| 877 | --undef (-U) C preprocessor macros to undefine |
| 878 | [...] |
| 879 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 880 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 881 | Note that an option spelled \longprogramopt{foo-bar} on the command-line |
| 882 | is spelled \option{foo\_bar} in configuration files. |
| 883 | |
| 884 | For example, say you want your extensions to be built |
| 885 | ``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] | 886 | 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] | 887 | in the same source directory as your pure Python modules |
| 888 | \module{pkg.mod1} and \module{pkg.mod2}. You can always use the |
| 889 | \longprogramopt{inplace} option on the command-line to ensure this: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 890 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 891 | \begin{verbatim} |
| 892 | python setup.py build_ext --inplace |
| 893 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 894 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 895 | But this requires that you always specify the \command{build\_ext} |
| 896 | command explicitly, and remember to provide \longprogramopt{inplace}. |
| 897 | An easier way is to ``set and forget'' this option, by encoding it in |
| 898 | \file{setup.cfg}, the configuration file for this distribution: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 899 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 900 | \begin{verbatim} |
| 901 | [build_ext] |
| 902 | inplace=1 |
| 903 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 904 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 905 | This will affect all builds of this module distribution, whether or not |
| 906 | you explcitly specify \command{build\_ext}. If you include |
| 907 | \file{setup.cfg} in your source distribution, it will also affect |
| 908 | end-user builds---which is probably a bad idea for this option, since |
| 909 | always building extensions in-place would break installation of the |
| 910 | module distribution. In certain peculiar cases, though, modules are |
| 911 | built right in their installation directory, so this is conceivably a |
| 912 | useful ability. (Distributing extensions that expect to be built in |
| 913 | their installation directory is almost always a bad idea, though.) |
| 914 | |
| 915 | Another example: certain commands take a lot of options that don't |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 916 | change from run to run; for example, \command{bdist\_rpm} needs to know |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 917 | everything required to generate a ``spec'' file for creating an RPM |
| 918 | distribution. Some of this information comes from the setup script, and |
| 919 | some is automatically generated by the Distutils (such as the list of |
| 920 | files installed). But some of it has to be supplied as options to |
| 921 | \command{bdist\_rpm}, which would be very tedious to do on the |
| 922 | command-line for every run. Hence, here is a snippet from the |
| 923 | Distutils' own \file{setup.cfg}: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 924 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 925 | \begin{verbatim} |
| 926 | [bdist_rpm] |
| 927 | release = 1 |
| 928 | packager = Greg Ward <gward@python.net> |
| 929 | doc_files = CHANGES.txt |
| 930 | README.txt |
| 931 | USAGE.txt |
| 932 | doc/ |
| 933 | examples/ |
| 934 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 935 | |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 936 | Note that the \option{doc\_files} option is simply a |
| 937 | whitespace-separated string split across multiple lines for readability. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 938 | |
| 939 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 940 | \begin{seealso} |
| 941 | \seetitle[../inst/config-syntax.html]{Installing Python |
| 942 | Modules}{More information on the configuration files is |
| 943 | available in the manual for system administrators.} |
| 944 | \end{seealso} |
| 945 | |
| 946 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 947 | \section{Creating a Source Distribution} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 948 | \label{source-dist} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 949 | |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 950 | As shown in section~\ref{simple-example}, you use the |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 951 | \command{sdist} command to create a source distribution. In the |
| 952 | simplest case, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 953 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 954 | \begin{verbatim} |
| 955 | python setup.py sdist |
| 956 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 957 | |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 958 | (assuming you haven't specified any \command{sdist} options in the setup |
| 959 | script or config file), \command{sdist} creates the archive of the |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 960 | default format for the current platform. The default format is a gzip'ed |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 961 | tar file (\file{.tar.gz}) on \UNIX, and ZIP file on Windows. |
| 962 | \XXX{no MacOS support here} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 963 | |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 964 | You can specify as many formats as you like using the |
| 965 | \longprogramopt{formats} option, for example: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 966 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 967 | \begin{verbatim} |
| 968 | python setup.py sdist --formats=gztar,zip |
| 969 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 970 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 971 | 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] | 972 | \begin{tableiii}{l|l|c}{code}% |
| 973 | {Format}{Description}{Notes} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 974 | \lineiii{zip}{zip file (\file{.zip})}{(1),(3)} |
| 975 | \lineiii{gztar}{gzip'ed tar file (\file{.tar.gz})}{(2),(4)} |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 976 | \lineiii{bztar}{bzip2'ed tar file (\file{.tar.bz2})}{(4)} |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 977 | \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(4)} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 978 | \lineiii{tar}{tar file (\file{.tar})}{(4)} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 979 | \end{tableiii} |
| 980 | |
| 981 | \noindent Notes: |
| 982 | \begin{description} |
| 983 | \item[(1)] default on Windows |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 984 | \item[(2)] default on \UNIX |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 985 | \item[(3)] requires either external \program{zip} utility or |
Greg Ward | 954ce8b | 2002-05-10 14:42:10 +0000 | [diff] [blame] | 986 | \module{zipfile} module (part of the standard Python library since |
| 987 | Python~1.6) |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 988 | \item[(4)] requires external utilities: \program{tar} and possibly one |
| 989 | of \program{gzip}, \program{bzip2}, or \program{compress} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 990 | \end{description} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 991 | |
| 992 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 993 | |
| 994 | \subsection{Specifying the files to distribute} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 995 | \label{manifest} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 996 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 997 | If you don't supply an explicit list of files (or instructions on how to |
| 998 | generate one), the \command{sdist} command puts a minimal default set |
| 999 | into the source distribution: |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1000 | \begin{itemize} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1001 | \item all Python source files implied by the \option{py\_modules} and |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1002 | \option{packages} options |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1003 | \item all C source files mentioned in the \option{ext\_modules} or |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1004 | \option{libraries} options (\XXX{getting C library sources currently |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1005 | broken -- no get\_source\_files() method in build\_clib.py!}) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1006 | \item anything that looks like a test script: \file{test/test*.py} |
| 1007 | (currently, the Distutils don't do anything with test scripts except |
| 1008 | include them in source distributions, but in the future there will be |
| 1009 | a standard for testing Python module distributions) |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1010 | \item \file{README.txt} (or \file{README}), \file{setup.py} (or whatever |
| 1011 | you called your setup script), and \file{setup.cfg} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1012 | \end{itemize} |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1013 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1014 | Sometimes this is enough, but usually you will want to specify |
| 1015 | additional files to distribute. The typical way to do this is to write |
| 1016 | a \emph{manifest template}, called \file{MANIFEST.in} by default. The |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1017 | manifest template is just a list of instructions for how to generate |
| 1018 | your manifest file, \file{MANIFEST}, which is the exact list of files to |
| 1019 | include in your source distribution. The \command{sdist} command |
| 1020 | processes this template and generates a manifest based on its |
| 1021 | instructions and what it finds in the filesystem. |
| 1022 | |
| 1023 | If you prefer to roll your own manifest file, the format is simple: one |
| 1024 | filename per line, regular files (or symlinks to them) only. If you do |
| 1025 | supply your own \file{MANIFEST}, you must specify everything: the |
| 1026 | default set of files described above does not apply in this case. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1027 | |
| 1028 | The manifest template has one command per line, where each command |
| 1029 | specifies a set of files to include or exclude from the source |
| 1030 | distribution. For an example, again we turn to the Distutils' own |
| 1031 | manifest template: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1032 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1033 | \begin{verbatim} |
| 1034 | include *.txt |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1035 | recursive-include examples *.txt *.py |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1036 | prune examples/sample?/build |
| 1037 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1038 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1039 | The meanings should be fairly clear: include all files in the |
| 1040 | distribution root matching \code{*.txt}, all files anywhere under the |
| 1041 | \file{examples} directory matching \code{*.txt} or \code{*.py}, and |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1042 | exclude all directories matching \code{examples/sample?/build}. All of |
| 1043 | this is done \emph{after} the standard include set, so you can exclude |
| 1044 | files from the standard set with explicit instructions in the manifest |
| 1045 | template. (Or, you can use the \longprogramopt{no-defaults} option to |
| 1046 | disable the standard set entirely.) There are several other commands |
| 1047 | available in the manifest template mini-language; see |
| 1048 | section~\ref{sdist-cmd}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1049 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1050 | The order of commands in the manifest template matters: initially, we |
| 1051 | have the list of default files as described above, and each command in |
| 1052 | the template adds to or removes from that list of files. Once we have |
| 1053 | fully processed the manifest template, we remove files that should not |
| 1054 | be included in the source distribution: |
| 1055 | \begin{itemize} |
| 1056 | \item all files in the Distutils ``build'' tree (default \file{build/}) |
| 1057 | \item all files in directories named \file{RCS} or \file{CVS} |
| 1058 | \end{itemize} |
| 1059 | Now we have our complete list of files, which is written to the manifest |
| 1060 | for future reference, and then used to build the source distribution |
| 1061 | archive(s). |
| 1062 | |
| 1063 | You can disable the default set of included files with the |
| 1064 | \longprogramopt{no-defaults} option, and you can disable the standard |
| 1065 | exclude set with \longprogramopt{no-prune}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1066 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1067 | Following the Distutils' own manifest template, let's trace how the |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 1068 | \command{sdist} command builds the list of files to include in the |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1069 | Distutils source distribution: |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1070 | \begin{enumerate} |
| 1071 | \item include all Python source files in the \file{distutils} and |
| 1072 | \file{distutils/command} subdirectories (because packages |
| 1073 | corresponding to those two directories were mentioned in the |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1074 | \option{packages} option in the setup script---see |
| 1075 | section~\ref{setup-script}) |
| 1076 | \item include \file{README.txt}, \file{setup.py}, and \file{setup.cfg} |
| 1077 | (standard files) |
| 1078 | \item include \file{test/test*.py} (standard files) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1079 | \item include \file{*.txt} in the distribution root (this will find |
| 1080 | \file{README.txt} a second time, but such redundancies are weeded out |
| 1081 | later) |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1082 | \item include anything matching \file{*.txt} or \file{*.py} in the |
| 1083 | sub-tree under \file{examples}, |
| 1084 | \item exclude all files in the sub-trees starting at directories |
| 1085 | matching \file{examples/sample?/build}---this may exclude files |
| 1086 | included by the previous two steps, so it's important that the |
| 1087 | \code{prune} command in the manifest template comes after the |
| 1088 | \code{recursive-include} command |
| 1089 | \item exclude the entire \file{build} tree, and any \file{RCS} or |
| 1090 | \file{CVS} directories |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1091 | \end{enumerate} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1092 | Just like in the setup script, file and directory names in the manifest |
| 1093 | template should always be slash-separated; the Distutils will take care |
| 1094 | of converting them to the standard representation on your platform. |
| 1095 | That way, the manifest template is portable across operating systems. |
| 1096 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1097 | |
| 1098 | \subsection{Manifest-related options} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1099 | \label{manifest-options} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1100 | |
| 1101 | The normal course of operations for the \command{sdist} command is as |
| 1102 | follows: |
| 1103 | \begin{itemize} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1104 | \item if the manifest file, \file{MANIFEST} doesn't exist, read |
| 1105 | \file{MANIFEST.in} and create the manifest |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1106 | \item if neither \file{MANIFEST} nor \file{MANIFEST.in} exist, create a |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1107 | manifest with just the default file set |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1108 | \item if either \file{MANIFEST.in} or the setup script (\file{setup.py}) |
| 1109 | are more recent than \file{MANIFEST}, recreate \file{MANIFEST} by |
| 1110 | reading \file{MANIFEST.in} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1111 | \item use the list of files now in \file{MANIFEST} (either just |
| 1112 | generated or read in) to create the source distribution archive(s) |
| 1113 | \end{itemize} |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1114 | There are a couple of options that modify this behaviour. First, use |
| 1115 | the \longprogramopt{no-defaults} and \longprogramopt{no-prune} to |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1116 | disable the standard ``include'' and ``exclude'' sets. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1117 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1118 | Second, you might want to force the manifest to be regenerated---for |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1119 | example, if you have added or removed files or directories that match an |
| 1120 | existing pattern in the manifest template, you should regenerate the |
| 1121 | manifest: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1122 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1123 | \begin{verbatim} |
| 1124 | python setup.py sdist --force-manifest |
| 1125 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1126 | |
| 1127 | Or, you might just want to (re)generate the manifest, but not create a |
| 1128 | source distribution: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1129 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1130 | \begin{verbatim} |
| 1131 | python setup.py sdist --manifest-only |
| 1132 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1133 | |
Greg Ward | 54589d4 | 2000-09-06 01:37:35 +0000 | [diff] [blame] | 1134 | \longprogramopt{manifest-only} implies \longprogramopt{force-manifest}. |
| 1135 | \programopt{-o} is a shortcut for \longprogramopt{manifest-only}, and |
| 1136 | \programopt{-f} for \longprogramopt{force-manifest}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1137 | |
| 1138 | |
| 1139 | \section{Creating Built Distributions} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1140 | \label{built-dist} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1141 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1142 | A ``built distribution'' is what you're probably used to thinking of |
| 1143 | either as a ``binary package'' or an ``installer'' (depending on your |
| 1144 | background). It's not necessarily binary, though, because it might |
| 1145 | contain only Python source code and/or byte-code; and we don't call it a |
| 1146 | package, because that word is already spoken for in Python. (And |
| 1147 | ``installer'' is a term specific to the Windows world. \XXX{do Mac |
| 1148 | people use it?}) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1149 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1150 | A built distribution is how you make life as easy as possible for |
| 1151 | installers of your module distribution: for users of RPM-based Linux |
| 1152 | systems, it's a binary RPM; for Windows users, it's an executable |
| 1153 | installer; for Debian-based Linux users, it's a Debian package; and so |
| 1154 | forth. Obviously, no one person will be able to create built |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1155 | distributions for every platform under the sun, so the Distutils are |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1156 | designed to enable module developers to concentrate on their |
| 1157 | specialty---writing code and creating source distributions---while an |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1158 | intermediary species called \emph{packagers} springs up to turn source |
Greg Ward | 19c67f8 | 2000-06-24 01:33:16 +0000 | [diff] [blame] | 1159 | distributions into built distributions for as many platforms as there |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1160 | are packagers. |
| 1161 | |
| 1162 | Of course, the module developer could be his own packager; or the |
| 1163 | packager could be a volunteer ``out there'' somewhere who has access to |
| 1164 | a platform which the original developer does not; or it could be |
| 1165 | software periodically grabbing new source distributions and turning them |
| 1166 | into built distributions for as many platforms as the software has |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1167 | access to. Regardless of who they are, a packager uses the |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1168 | setup script and the \command{bdist} command family to generate built |
| 1169 | distributions. |
| 1170 | |
| 1171 | As a simple example, if I run the following command in the Distutils |
| 1172 | source tree: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1173 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1174 | \begin{verbatim} |
| 1175 | python setup.py bdist |
| 1176 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1177 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1178 | then the Distutils builds my module distribution (the Distutils itself |
| 1179 | in this case), does a ``fake'' installation (also in the \file{build} |
| 1180 | directory), and creates the default type of built distribution for my |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1181 | platform. The default format for built distributions is a ``dumb'' tar |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1182 | file on \UNIX, and a simple executable installer on Windows. (That tar |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1183 | file is considered ``dumb'' because it has to be unpacked in a specific |
| 1184 | location to work.) |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1185 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1186 | Thus, the above command on a \UNIX{} system creates |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1187 | \file{Distutils-1.0.\filevar{plat}.tar.gz}; unpacking this tarball |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1188 | from the right place installs the Distutils just as though you had |
| 1189 | downloaded the source distribution and run \code{python setup.py |
| 1190 | install}. (The ``right place'' is either the root of the filesystem or |
| 1191 | Python's \filevar{prefix} directory, depending on the options given to |
| 1192 | the \command{bdist\_dumb} command; the default is to make dumb |
| 1193 | distributions relative to \filevar{prefix}.) |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1194 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1195 | Obviously, for pure Python distributions, this isn't any simpler than |
| 1196 | just running \code{python setup.py install}---but for non-pure |
| 1197 | distributions, which include extensions that would need to be |
| 1198 | compiled, it can mean the difference between someone being able to use |
| 1199 | your extensions or not. And creating ``smart'' built distributions, |
| 1200 | such as an RPM package or an executable installer for Windows, is far |
| 1201 | more convenient for users even if your distribution doesn't include |
| 1202 | any extensions. |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1203 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1204 | The \command{bdist} command has a \longprogramopt{formats} option, |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1205 | similar to the \command{sdist} command, which you can use to select the |
| 1206 | types of built distribution to generate: for example, |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1207 | |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1208 | \begin{verbatim} |
| 1209 | python setup.py bdist --format=zip |
| 1210 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1211 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1212 | would, when run on a \UNIX{} system, create |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1213 | \file{Distutils-1.0.\filevar{plat}.zip}---again, this archive would be |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1214 | unpacked from the root directory to install the Distutils. |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1215 | |
| 1216 | The available formats for built distributions are: |
| 1217 | \begin{tableiii}{l|l|c}{code}% |
| 1218 | {Format}{Description}{Notes} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1219 | \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1),(3)} |
| 1220 | \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(3)} |
| 1221 | \lineiii{tar}{tar file (\file{.tar})}{(3)} |
| 1222 | \lineiii{zip}{zip file (\file{.zip})}{(4)} |
| 1223 | \lineiii{rpm}{RPM}{(5)} |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1224 | \lineiii{pkgtool}{Solaris \program{pkgtool}}{} |
| 1225 | \lineiii{sdux}{HP-UX \program{swinstall}}{} |
| 1226 | \lineiii{rpm}{RPM}{(5)} |
| 1227 | % \lineiii{srpm}{source RPM}{(5) \XXX{to do!}} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1228 | \lineiii{wininst}{self-extracting ZIP file for Windows}{(2),(4)} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1229 | \end{tableiii} |
| 1230 | |
| 1231 | \noindent Notes: |
| 1232 | \begin{description} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1233 | \item[(1)] default on \UNIX |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1234 | \item[(2)] default on Windows \XXX{to-do!} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1235 | \item[(3)] requires external utilities: \program{tar} and possibly one |
| 1236 | of \program{gzip}, \program{bzip2}, or \program{compress} |
| 1237 | \item[(4)] requires either external \program{zip} utility or |
Greg Ward | 954ce8b | 2002-05-10 14:42:10 +0000 | [diff] [blame] | 1238 | \module{zipfile} module (part of the standard Python library since |
| 1239 | Python~1.6) |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1240 | \item[(5)] requires external \program{rpm} utility, version 3.0.4 or |
| 1241 | better (use \code{rpm --version} to find out which version you have) |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1242 | \end{description} |
| 1243 | |
| 1244 | You don't have to use the \command{bdist} command with the |
Greg Ward | d5767a5 | 2000-04-19 22:48:09 +0000 | [diff] [blame] | 1245 | \longprogramopt{formats} option; you can also use the command that |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1246 | directly implements the format you're interested in. Some of these |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1247 | \command{bdist} ``sub-commands'' actually generate several similar |
| 1248 | formats; for instance, the \command{bdist\_dumb} command generates all |
| 1249 | the ``dumb'' archive formats (\code{tar}, \code{ztar}, \code{gztar}, and |
| 1250 | \code{zip}), and \command{bdist\_rpm} generates both binary and source |
| 1251 | RPMs. The \command{bdist} sub-commands, and the formats generated by |
| 1252 | each, are: |
| 1253 | \begin{tableii}{l|l}{command}% |
| 1254 | {Command}{Formats} |
| 1255 | \lineii{bdist\_dumb}{tar, ztar, gztar, zip} |
| 1256 | \lineii{bdist\_rpm}{rpm, srpm} |
Greg Ward | 1d8f57a | 2000-08-05 00:43:11 +0000 | [diff] [blame] | 1257 | \lineii{bdist\_wininst}{wininst} |
Greg Ward | 46b98e3 | 2000-04-14 01:53:36 +0000 | [diff] [blame] | 1258 | \end{tableii} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1259 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1260 | The following sections give details on the individual \command{bdist\_*} |
| 1261 | commands. |
| 1262 | |
| 1263 | |
| 1264 | \subsection{Creating dumb built distributions} |
| 1265 | \label{creating-dumb} |
| 1266 | |
| 1267 | \XXX{Need to document absolute vs. prefix-relative packages here, but |
| 1268 | first I have to implement it!} |
| 1269 | |
| 1270 | |
| 1271 | \subsection{Creating RPM packages} |
| 1272 | \label{creating-rpms} |
| 1273 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1274 | The RPM format is used by many popular Linux distributions, including |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1275 | Red Hat, SuSE, and Mandrake. If one of these (or any of the other |
| 1276 | RPM-based Linux distributions) is your usual environment, creating RPM |
| 1277 | packages for other users of that same distribution is trivial. |
| 1278 | Depending on the complexity of your module distribution and differences |
| 1279 | between Linux distributions, you may also be able to create RPMs that |
| 1280 | work on different RPM-based distributions. |
| 1281 | |
| 1282 | The usual way to create an RPM of your module distribution is to run the |
| 1283 | \command{bdist\_rpm} command: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1284 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1285 | \begin{verbatim} |
| 1286 | python setup.py bdist_rpm |
| 1287 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1288 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1289 | or the \command{bdist} command with the \longprogramopt{format} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1290 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1291 | \begin{verbatim} |
| 1292 | python setup.py bdist --formats=rpm |
| 1293 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1294 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1295 | The former allows you to specify RPM-specific options; the latter allows |
| 1296 | you to easily specify multiple formats in one run. If you need to do |
| 1297 | both, you can explicitly specify multiple \command{bdist\_*} commands |
| 1298 | and their options: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1299 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1300 | \begin{verbatim} |
| 1301 | python setup.py bdist_rpm --packager="John Doe <jdoe@python.net>" \ |
| 1302 | bdist_wininst --target_version="2.0" |
| 1303 | \end{verbatim} |
| 1304 | |
| 1305 | Creating RPM packages is driven by a \file{.spec} file, much as using |
| 1306 | the Distutils is driven by the setup script. To make your life easier, |
| 1307 | the \command{bdist\_rpm} command normally creates a \file{.spec} file |
| 1308 | based on the information you supply in the setup script, on the command |
| 1309 | line, and in any Distutils configuration files. Various options and |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 1310 | 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] | 1311 | script as follows: |
| 1312 | \begin{tableii}{l|l}{textrm}% |
| 1313 | {RPM \file{.spec} file option or section}{Distutils setup script option} |
| 1314 | \lineii{Name}{\option{name}} |
| 1315 | \lineii{Summary (in preamble)}{\option{description}} |
| 1316 | \lineii{Version}{\option{version}} |
| 1317 | \lineii{Vendor}{\option{author} and \option{author\_email}, or \\& |
| 1318 | \option{maintainer} and \option{maintainer\_email}} |
| 1319 | \lineii{Copyright}{\option{licence}} |
| 1320 | \lineii{Url}{\option{url}} |
| 1321 | \lineii{\%description (section)}{\option{long\_description}} |
| 1322 | \end{tableii} |
| 1323 | |
| 1324 | Additionally, there many options in \file{.spec} files that don't have |
| 1325 | corresponding options in the setup script. Most of these are handled |
| 1326 | through options to the \command{bdist\_rpm} command as follows: |
| 1327 | \begin{tableiii}{l|l|l}{textrm}% |
| 1328 | {RPM \file{.spec} file option or section}% |
| 1329 | {\command{bdist\_rpm} option}% |
| 1330 | {default value} |
| 1331 | \lineiii{Release}{\option{release}}{``1''} |
| 1332 | \lineiii{Group}{\option{group}}{``Development/Libraries''} |
| 1333 | \lineiii{Vendor}{\option{vendor}}{(see above)} |
Andrew M. Kuchling | da23c4f | 2001-02-17 00:38:48 +0000 | [diff] [blame] | 1334 | \lineiii{Packager}{\option{packager}}{(none)} |
| 1335 | \lineiii{Provides}{\option{provides}}{(none)} |
| 1336 | \lineiii{Requires}{\option{requires}}{(none)} |
| 1337 | \lineiii{Conflicts}{\option{conflicts}}{(none)} |
| 1338 | \lineiii{Obsoletes}{\option{obsoletes}}{(none)} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1339 | \lineiii{Distribution}{\option{distribution\_name}}{(none)} |
| 1340 | \lineiii{BuildRequires}{\option{build\_requires}}{(none)} |
| 1341 | \lineiii{Icon}{\option{icon}}{(none)} |
| 1342 | \end{tableiii} |
| 1343 | Obviously, supplying even a few of these options on the command-line |
| 1344 | would be tedious and error-prone, so it's usually best to put them in |
| 1345 | the setup configuration file, \file{setup.cfg}---see |
| 1346 | section~\ref{setup-config}. If you distribute or package many Python |
| 1347 | module distributions, you might want to put options that apply to all of |
| 1348 | them in your personal Distutils configuration file |
| 1349 | (\file{\textasciitilde/.pydistutils.cfg}). |
| 1350 | |
| 1351 | There are three steps to building a binary RPM package, all of which are |
| 1352 | handled automatically by the Distutils: |
| 1353 | \begin{enumerate} |
| 1354 | \item create a \file{.spec} file, which describes the package (analogous |
| 1355 | to the Distutils setup script; in fact, much of the information in the |
| 1356 | setup script winds up in the \file{.spec} file) |
| 1357 | \item create the source RPM |
| 1358 | \item create the ``binary'' RPM (which may or may not contain binary |
| 1359 | code, depending on whether your module distribution contains Python |
| 1360 | extensions) |
| 1361 | \end{enumerate} |
| 1362 | Normally, RPM bundles the last two steps together; when you use the |
| 1363 | Distutils, all three steps are typically bundled together. |
| 1364 | |
| 1365 | If you wish, you can separate these three steps. You can use the |
| 1366 | \longprogramopt{spec-only} option to make \command{bdist\_rpm} just |
| 1367 | create the \file{.spec} file and exit; in this case, the \file{.spec} |
| 1368 | file will be written to the ``distribution directory''---normally |
| 1369 | \file{dist/}, but customizable with the \longprogramopt{dist-dir} |
| 1370 | option. (Normally, the \file{.spec} file winds up deep in the ``build |
| 1371 | tree,'' in a temporary directory created by \command{bdist\_rpm}.) |
| 1372 | |
| 1373 | \XXX{this isn't implemented yet---is it needed?!} |
| 1374 | You can also specify a custom \file{.spec} file with the |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1375 | \longprogramopt{spec-file} option; used in conjunction with |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1376 | \longprogramopt{spec-only}, this gives you an opportunity to customize |
| 1377 | the \file{.spec} file manually: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1378 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1379 | \begin{verbatim} |
| 1380 | > python setup.py bdist_rpm --spec-only |
| 1381 | # ...edit dist/FooBar-1.0.spec |
| 1382 | > python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec |
| 1383 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1384 | |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1385 | (Although a better way to do this is probably to override the standard |
| 1386 | \command{bdist\_rpm} command with one that writes whatever else you want |
Andrew M. Kuchling | e9a54a3 | 2003-05-13 15:02:06 +0000 | [diff] [blame] | 1387 | to the \file{.spec} file.) |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1388 | |
| 1389 | |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1390 | \subsection{Creating Windows Installers} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1391 | \label{creating-wininst} |
| 1392 | |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1393 | Executable installers are the natural format for binary distributions |
| 1394 | on Windows. They display a nice graphical user interface, display |
| 1395 | some information about the module distribution to be installed taken |
Andrew M. Kuchling | d7abe2a | 2002-05-29 17:33:48 +0000 | [diff] [blame] | 1396 | from the metadata in the setup script, let the user select a few |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1397 | options, and start or cancel the installation. |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1398 | |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1399 | Since the metadata is taken from the setup script, creating Windows |
| 1400 | installers is usually as easy as running: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1401 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1402 | \begin{verbatim} |
| 1403 | python setup.py bdist_wininst |
| 1404 | \end{verbatim} |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1405 | |
Thomas Heller | 36343f6 | 2002-11-15 19:20:56 +0000 | [diff] [blame] | 1406 | or the \command{bdist} command with the \longprogramopt{formats} option: |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1407 | |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1408 | \begin{verbatim} |
| 1409 | python setup.py bdist --formats=wininst |
| 1410 | \end{verbatim} |
| 1411 | |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1412 | If you have a pure module distribution (only containing pure Python |
| 1413 | modules and packages), the resulting installer will be version |
| 1414 | independent and have a name like \file{foo-1.0.win32.exe}. These |
| 1415 | installers can even be created on \UNIX{} or MacOS platforms. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1416 | |
| 1417 | If you have a non-pure distribution, the extensions can only be |
Andrew M. Kuchling | 40df710 | 2002-05-08 13:39:03 +0000 | [diff] [blame] | 1418 | created on a Windows platform, and will be Python version dependent. |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1419 | The installer filename will reflect this and now has the form |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1420 | \file{foo-1.0.win32-py2.0.exe}. You have to create a separate installer |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1421 | for every Python version you want to support. |
| 1422 | |
| 1423 | The installer will try to compile pure modules into bytecode after |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1424 | installation on the target system in normal and optimizing mode. If |
| 1425 | you don't want this to happen for some reason, you can run the |
Fred Drake | 0e9bfa3 | 2002-11-15 20:34:52 +0000 | [diff] [blame] | 1426 | \command{bdist_wininst} command with the |
| 1427 | \longprogramopt{no-target-compile} and/or the |
| 1428 | \longprogramopt{no-target-optimize} option. |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1429 | |
Fred Drake | 0e9bfa3 | 2002-11-15 20:34:52 +0000 | [diff] [blame] | 1430 | By default the installer will display the cool ``Python Powered'' logo |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1431 | when it is run, but you can also supply your own bitmap which must be |
Fred Drake | 0e9bfa3 | 2002-11-15 20:34:52 +0000 | [diff] [blame] | 1432 | a Windows \file{.bmp} file with the \longprogramopt{bitmap} option. |
Thomas Heller | e61f365 | 2002-11-15 20:13:26 +0000 | [diff] [blame] | 1433 | |
| 1434 | The installer will also display a large title on the desktop |
| 1435 | background window when it is run, which is constructed from the name |
| 1436 | of your distribution and the version number. This can be changed to |
| 1437 | another text by using the \longprogramopt{title} option. |
| 1438 | |
| 1439 | The installer file will be written to the ``distribution directory'' |
| 1440 | --- normally \file{dist/}, but customizable with the |
| 1441 | \longprogramopt{dist-dir} option. |
| 1442 | |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1443 | \subsubsection{The Postinstallation script} |
| 1444 | \label{postinstallation-script} |
| 1445 | |
| 1446 | Starting with Python 2.3, a postinstallation script can be specified |
| 1447 | which the \longprogramopt{install-script} option. The basename of the |
| 1448 | script must be specified, and the script filename must also be listed |
| 1449 | in the scripts argument to the setup function. |
| 1450 | |
| 1451 | This script will be run at installation time on the target system |
| 1452 | after all the files have been copied, with argv[1] set to '-install', |
| 1453 | and again at uninstallation time before the files are removed with argv[1] |
| 1454 | set to '-remove'. |
| 1455 | |
| 1456 | The installation script runs embedded in the windows installer, every |
| 1457 | output (sys.stdout, sys.stderr) is redirected into a buffer and will |
| 1458 | be displayed in the GUI after the script has finished. |
| 1459 | |
| 1460 | Some functions especially useful in this context are available in the |
| 1461 | installation script. |
| 1462 | |
| 1463 | \begin{verbatim} |
Thomas Heller | 41e2809 | 2003-10-16 19:40:48 +0000 | [diff] [blame] | 1464 | directory_created(pathname) |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1465 | file_created(pathname) |
| 1466 | \end{verbatim} |
| 1467 | |
| 1468 | These functions should be called when a directory or file is created |
| 1469 | by the postinstall script at installation time. It will register the |
| 1470 | pathname with the uninstaller, so that it will be removed when the |
| 1471 | distribution is uninstalled. To be safe, directories are only removed |
| 1472 | if they are empty. |
| 1473 | |
| 1474 | \begin{verbatim} |
| 1475 | get_special_folder_path(csidl_string) |
| 1476 | \end{verbatim} |
| 1477 | |
| 1478 | This function can be used to retrieve special folder locations on |
| 1479 | Windows like the Start Menu or the Desktop. It returns the full path |
Thomas Heller | a425dbc | 2003-09-17 17:11:01 +0000 | [diff] [blame] | 1480 | to the folder. 'csidl_string' must be one of the following strings: |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1481 | |
| 1482 | \begin{verbatim} |
| 1483 | "CSIDL_APPDATA" |
| 1484 | |
| 1485 | "CSIDL_COMMON_STARTMENU" |
| 1486 | "CSIDL_STARTMENU" |
| 1487 | |
| 1488 | "CSIDL_COMMON_DESKTOPDIRECTORY" |
| 1489 | "CSIDL_DESKTOPDIRECTORY" |
| 1490 | |
| 1491 | "CSIDL_COMMON_STARTUP" |
| 1492 | "CSIDL_STARTUP" |
| 1493 | |
| 1494 | "CSIDL_COMMON_PROGRAMS" |
| 1495 | "CSIDL_PROGRAMS" |
| 1496 | |
| 1497 | "CSIDL_FONTS" |
| 1498 | \end{verbatim} |
| 1499 | |
| 1500 | If the folder cannot be retrieved, OSError is raised. |
| 1501 | |
| 1502 | Which folders are available depends on the exact Windows version, and probably |
| 1503 | also the configuration. For details refer to Microsoft's documentation of the |
Thomas Heller | 63b4dd3 | 2002-12-12 19:35:00 +0000 | [diff] [blame] | 1504 | \code{SHGetSpecialFolderPath} function. |
Thomas Heller | 2c3bfc2 | 2002-12-12 18:54:19 +0000 | [diff] [blame] | 1505 | |
| 1506 | \begin{verbatim} |
| 1507 | create_shortcut(target, description, filename[, arguments[, |
| 1508 | workdir[, iconpath[, iconindex]]]]) |
| 1509 | \end{verbatim} |
| 1510 | |
| 1511 | This function creates a shortcut. |
Thomas Heller | 63b4dd3 | 2002-12-12 19:35:00 +0000 | [diff] [blame] | 1512 | \var{target} is the path to the program to be started by the shortcut. |
| 1513 | \var{description} is the description of the sortcut. |
| 1514 | \var{filename} is the title of the shortcut that the user will see. |
| 1515 | \var{arguments} specifies the command line arguments, if any. |
| 1516 | \var{workdir} is the working directory for the program. |
| 1517 | \var{iconpath} is the file containing the icon for the shortcut, |
| 1518 | and \var{iconindex} is the index of the icon in the file |
| 1519 | \var{iconpath}. Again, for details consult the Microsoft |
| 1520 | documentation for the \code{IShellLink} interface. |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1521 | |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 1522 | \section{Registering with the Package Index} |
| 1523 | \label{package-index} |
| 1524 | |
| 1525 | The Python Package Index (PyPI) holds meta-data describing distributions |
| 1526 | packaged with distutils. The distutils command \command{register} is |
| 1527 | used to submit your distribution's meta-data to the index. It is invoked |
| 1528 | as follows: |
| 1529 | |
| 1530 | \begin{verbatim} |
| 1531 | python setup.py register |
| 1532 | \end{verbatim} |
| 1533 | |
| 1534 | Distutils will respond with the following prompt: |
| 1535 | |
| 1536 | \begin{verbatim} |
| 1537 | running register |
| 1538 | We need to know who you are, so please choose either: |
| 1539 | 1. use your existing login, |
| 1540 | 2. register as a new user, |
| 1541 | 3. have the server generate a new password for you (and email it to you), or |
| 1542 | 4. quit |
| 1543 | Your selection [default 1]: |
| 1544 | \end{verbatim} |
| 1545 | |
| 1546 | \noindent Note: if your username and password are saved locally, you will |
| 1547 | not see this menu. |
| 1548 | |
| 1549 | If you have not registered with PyPI, then you will need to do so now. You |
| 1550 | should choose option 2, and enter your details as required. Soon after |
| 1551 | submitting your details, you will receive an email which will be used to |
| 1552 | confirm your registration. |
| 1553 | |
| 1554 | Once you are registered, you may choose option 1 from the menu. You will |
| 1555 | be prompted for your PyPI username and password, and \command{register} |
| 1556 | will then submit your meta-data to the index. |
| 1557 | |
| 1558 | You may submit any number of versions of your distribution to the index. If |
| 1559 | you alter the meta-data for a particular version, you may submit it again |
| 1560 | and the index will be updated. |
| 1561 | |
| 1562 | PyPI holds a record for each (name, version) combination submitted. The |
| 1563 | first user to submit information for a given name is designated the Owner |
| 1564 | of that name. They may submit changes through the \command{register} |
| 1565 | command or through the web interface. They may also designate other users |
| 1566 | as Owners or Maintainers. Maintainers may edit the package information, but |
| 1567 | not designate other Owners or Maintainers. |
| 1568 | |
| 1569 | By default PyPI will list all versions of a given package. To hide certain |
| 1570 | versions, the Hidden property should be set to yes. This must be edited |
| 1571 | through the web interface. |
| 1572 | |
| 1573 | |
| 1574 | |
Greg Ward | 007c04a | 2002-05-10 14:45:59 +0000 | [diff] [blame] | 1575 | \section{Examples} |
| 1576 | \label{examples} |
Andrew M. Kuchling | d15f4e3 | 2003-01-03 15:42:14 +0000 | [diff] [blame] | 1577 | |
Greg Ward | 007c04a | 2002-05-10 14:45:59 +0000 | [diff] [blame] | 1578 | \subsection{Pure Python distribution (by module)} |
| 1579 | \label{pure-mod} |
| 1580 | |
| 1581 | If you're just distributing a couple of modules, especially if they |
| 1582 | don't live in a particular package, you can specify them individually |
| 1583 | using the \option{py\_modules} option in the setup script. |
| 1584 | |
| 1585 | In the simplest case, you'll have two files to worry about: a setup |
| 1586 | script and the single module you're distributing, \file{foo.py} in this |
| 1587 | example: |
| 1588 | \begin{verbatim} |
| 1589 | <root>/ |
| 1590 | setup.py |
| 1591 | foo.py |
| 1592 | \end{verbatim} |
| 1593 | (In all diagrams in this section, \verb|<root>| will refer to the |
| 1594 | distribution root directory.) A minimal setup script to describe this |
| 1595 | situation would be: |
| 1596 | \begin{verbatim} |
| 1597 | from distutils.core import setup |
| 1598 | setup(name = "foo", version = "1.0", |
| 1599 | py_modules = ["foo"]) |
| 1600 | \end{verbatim} |
| 1601 | Note that the name of the distribution is specified independently with |
| 1602 | the \option{name} option, and there's no rule that says it has to be the |
| 1603 | same as the name of the sole module in the distribution (although that's |
| 1604 | probably a good convention to follow). However, the distribution name |
| 1605 | is used to generate filenames, so you should stick to letters, digits, |
| 1606 | underscores, and hyphens. |
| 1607 | |
| 1608 | Since \option{py\_modules} is a list, you can of course specify multiple |
| 1609 | modules, eg. if you're distributing modules \module{foo} and |
| 1610 | \module{bar}, your setup might look like this: |
| 1611 | \begin{verbatim} |
| 1612 | <root>/ |
| 1613 | setup.py |
| 1614 | foo.py |
| 1615 | bar.py |
| 1616 | \end{verbatim} |
| 1617 | and the setup script might be |
| 1618 | \begin{verbatim} |
| 1619 | from distutils.core import setup |
| 1620 | setup(name = "foobar", version = "1.0", |
| 1621 | py_modules = ["foo", "bar"]) |
| 1622 | \end{verbatim} |
| 1623 | |
| 1624 | You can put module source files into another directory, but if you have |
| 1625 | enough modules to do that, it's probably easier to specify modules by |
| 1626 | package rather than listing them individually. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1627 | |
| 1628 | |
Greg Ward | 007c04a | 2002-05-10 14:45:59 +0000 | [diff] [blame] | 1629 | \subsection{Pure Python distribution (by package)} |
| 1630 | \label{pure-pkg} |
| 1631 | |
| 1632 | If you have more than a couple of modules to distribute, especially if |
| 1633 | they are in multiple packages, it's probably easier to specify whole |
| 1634 | packages rather than individual modules. This works even if your |
| 1635 | modules are not in a package; you can just tell the Distutils to process |
| 1636 | modules from the root package, and that works the same as any other |
| 1637 | package (except that you don't have to have an \file{\_\_init\_\_.py} |
| 1638 | file). |
| 1639 | |
| 1640 | The setup script from the last example could also be written as |
| 1641 | \begin{verbatim} |
| 1642 | from distutils.core import setup |
| 1643 | setup(name = "foobar", version = "1.0", |
| 1644 | packages = [""]) |
| 1645 | \end{verbatim} |
| 1646 | (The empty string stands for the root package.) |
| 1647 | |
| 1648 | If those two files are moved into a subdirectory, but remain in the root |
| 1649 | package, e.g.: |
| 1650 | \begin{verbatim} |
| 1651 | <root>/ |
| 1652 | setup.py |
| 1653 | src/ foo.py |
| 1654 | bar.py |
| 1655 | \end{verbatim} |
| 1656 | then you would still specify the root package, but you have to tell the |
| 1657 | Distutils where source files in the root package live: |
| 1658 | \begin{verbatim} |
| 1659 | from distutils.core import setup |
| 1660 | setup(name = "foobar", version = "1.0", |
| 1661 | package_dir = {"": "src"}, |
| 1662 | packages = [""]) |
| 1663 | \end{verbatim} |
| 1664 | |
| 1665 | More typically, though, you will want to distribute multiple modules in |
| 1666 | the same package (or in sub-packages). For example, if the \module{foo} |
| 1667 | and \module{bar} modules belong in package \module{foobar}, one way to |
| 1668 | layout your source tree is |
| 1669 | \begin{verbatim} |
| 1670 | <root>/ |
| 1671 | setup.py |
| 1672 | foobar/ |
| 1673 | __init__.py |
| 1674 | foo.py |
| 1675 | bar.py |
| 1676 | \end{verbatim} |
| 1677 | This is in fact the default layout expected by the Distutils, and the |
| 1678 | one that requires the least work to describe in your setup script: |
| 1679 | \begin{verbatim} |
| 1680 | from distutils.core import setup |
| 1681 | setup(name = "foobar", version = "1.0", |
| 1682 | packages = ["foobar"]) |
| 1683 | \end{verbatim} |
| 1684 | |
| 1685 | If you want to put modules in directories not named for their package, |
| 1686 | then you need to use the \option{package\_dir} option again. For |
| 1687 | example, if the \file{src} directory holds modules in the |
| 1688 | \module{foobar} package: |
| 1689 | \begin{verbatim} |
| 1690 | <root>/ |
| 1691 | setup.py |
| 1692 | src/ |
| 1693 | __init__.py |
| 1694 | foo.py |
| 1695 | bar.py |
| 1696 | \end{verbatim} |
| 1697 | an appropriate setup script would be |
| 1698 | \begin{verbatim} |
| 1699 | from distutils.core import setup |
| 1700 | setup(name = "foobar", version = "1.0", |
| 1701 | package_dir = {"foobar" : "src"}, |
| 1702 | packages = ["foobar"]) |
| 1703 | \end{verbatim} |
| 1704 | |
| 1705 | Or, you might put modules from your main package right in the |
| 1706 | distribution root: |
| 1707 | \begin{verbatim} |
| 1708 | <root>/ |
| 1709 | setup.py |
| 1710 | __init__.py |
| 1711 | foo.py |
| 1712 | bar.py |
| 1713 | \end{verbatim} |
| 1714 | in which case your setup script would be |
| 1715 | \begin{verbatim} |
| 1716 | from distutils.core import setup |
| 1717 | setup(name = "foobar", version = "1.0", |
| 1718 | package_dir = {"foobar" : ""}, |
| 1719 | packages = ["foobar"]) |
| 1720 | \end{verbatim} |
| 1721 | (The empty string also stands for the current directory.) |
| 1722 | |
| 1723 | If you have sub-packages, they must be explicitly listed in |
| 1724 | \option{packages}, but any entries in \option{package\_dir} |
| 1725 | automatically extend to sub-packages. (In other words, the Distutils |
| 1726 | does \emph{not} scan your source tree, trying to figure out which |
| 1727 | directories correspond to Python packages by looking for |
| 1728 | \file{\_\_init\_\_.py} files.) Thus, if the default layout grows a |
| 1729 | sub-package: |
| 1730 | \begin{verbatim} |
| 1731 | <root>/ |
| 1732 | setup.py |
| 1733 | foobar/ |
| 1734 | __init__.py |
| 1735 | foo.py |
| 1736 | bar.py |
| 1737 | subfoo/ |
| 1738 | __init__.py |
| 1739 | blah.py |
| 1740 | \end{verbatim} |
| 1741 | then the corresponding setup script would be |
| 1742 | \begin{verbatim} |
| 1743 | from distutils.core import setup |
| 1744 | setup(name = "foobar", version = "1.0", |
| 1745 | packages = ["foobar", "foobar.subfoo"]) |
| 1746 | \end{verbatim} |
| 1747 | (Again, the empty string in \option{package\_dir} stands for the current |
| 1748 | directory.) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1749 | |
| 1750 | |
Greg Ward | 007c04a | 2002-05-10 14:45:59 +0000 | [diff] [blame] | 1751 | \subsection{Single extension module} |
| 1752 | \label{single-ext} |
| 1753 | |
| 1754 | Extension modules are specified using the \option{ext\_modules} option. |
| 1755 | \option{package\_dir} has no effect on where extension source files are |
| 1756 | found; it only affects the source for pure Python modules. The simplest |
| 1757 | case, a single extension module in a single C source file, is: |
| 1758 | \begin{verbatim} |
| 1759 | <root>/ |
| 1760 | setup.py |
| 1761 | foo.c |
| 1762 | \end{verbatim} |
| 1763 | If the \module{foo} extension belongs in the root package, the setup |
| 1764 | script for this could be |
| 1765 | \begin{verbatim} |
| 1766 | from distutils.core import setup |
| 1767 | setup(name = "foobar", version = "1.0", |
| 1768 | ext_modules = [Extension("foo", ["foo.c"])]) |
| 1769 | \end{verbatim} |
| 1770 | |
| 1771 | If the extension actually belongs in a package, say \module{foopkg}, |
| 1772 | then |
| 1773 | |
| 1774 | With exactly the same source tree layout, this extension can be put in |
| 1775 | the \module{foopkg} package simply by changing the name of the |
| 1776 | extension: |
| 1777 | \begin{verbatim} |
| 1778 | from distutils.core import setup |
| 1779 | setup(name = "foobar", version = "1.0", |
| 1780 | ext_modules = [Extension("foopkg.foo", ["foo.c"])]) |
| 1781 | \end{verbatim} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1782 | |
| 1783 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1784 | %\subsection{Multiple extension modules} |
| 1785 | %\label{multiple-ext} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1786 | |
| 1787 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1788 | %\subsection{Putting it all together} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1789 | |
| 1790 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1791 | %\section{Extending the Distutils} |
| 1792 | %\label{extending} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1793 | |
| 1794 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1795 | %\subsection{Extending existing commands} |
| 1796 | %\label{extend-existing} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1797 | |
| 1798 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1799 | %\subsection{Writing new commands} |
| 1800 | %\label{new-commands} |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1801 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1802 | %\XXX{Would an uninstall command be a good example here?} |
Thomas Heller | 5f52f72 | 2001-02-19 17:48:03 +0000 | [diff] [blame] | 1803 | |
Greg Ward | 4a9e722 | 2000-04-25 02:57:36 +0000 | [diff] [blame] | 1804 | |
| 1805 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1806 | \section{Reference} |
Greg Ward | 47f99a6 | 2000-09-04 20:07:15 +0000 | [diff] [blame] | 1807 | \label{reference} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1808 | |
| 1809 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1810 | %\subsection{Building modules: the \protect\command{build} command family} |
| 1811 | %\label{build-cmds} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1812 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1813 | %\subsubsection{\protect\command{build}} |
| 1814 | %\label{build-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1815 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1816 | %\subsubsection{\protect\command{build\_py}} |
| 1817 | %\label{build-py-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1818 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1819 | %\subsubsection{\protect\command{build\_ext}} |
| 1820 | %\label{build-ext-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1821 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1822 | %\subsubsection{\protect\command{build\_clib}} |
| 1823 | %\label{build-clib-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1824 | |
| 1825 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame] | 1826 | \subsection{Installing modules: the \protect\command{install} command family} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1827 | \label{install-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1828 | |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1829 | The install command ensures that the build commands have been run and then |
| 1830 | runs the subcommands \command{install\_lib}, |
| 1831 | \command{install\_data} and |
| 1832 | \command{install\_scripts}. |
| 1833 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1834 | %\subsubsection{\protect\command{install\_lib}} |
| 1835 | %\label{install-lib-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1836 | |
| 1837 | \subsubsection{\protect\command{install\_data}} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 1838 | \label{install-data-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1839 | This command installs all data files provided with the distribution. |
| 1840 | |
| 1841 | \subsubsection{\protect\command{install\_scripts}} |
Greg Ward | 1365a30 | 2000-08-31 14:47:05 +0000 | [diff] [blame] | 1842 | \label{install-scripts-cmd} |
Gregory P. Smith | 147e5f3 | 2000-05-12 00:58:18 +0000 | [diff] [blame] | 1843 | This command installs all (Python) scripts in the distribution. |
| 1844 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1845 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1846 | %\subsection{Cleaning up: the \protect\command{clean} command} |
| 1847 | %\label{clean-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1848 | |
| 1849 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1850 | \subsection{Creating a source distribution: the |
| 1851 | \protect\command{sdist} command} |
Greg Ward | e78298a | 2000-04-28 17:12:24 +0000 | [diff] [blame] | 1852 | \label{sdist-cmd} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1853 | |
| 1854 | |
| 1855 | \XXX{fragment moved down from above: needs context!} |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1856 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1857 | The manifest template commands are: |
| 1858 | \begin{tableii}{ll}{command}{Command}{Description} |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1859 | \lineii{include \var{pat1} \var{pat2} ... } |
| 1860 | {include all files matching any of the listed patterns} |
| 1861 | \lineii{exclude \var{pat1} \var{pat2} ... } |
| 1862 | {exclude all files matching any of the listed patterns} |
| 1863 | \lineii{recursive-include \var{dir} \var{pat1} \var{pat2} ... } |
| 1864 | {include all files under \var{dir} matching any of the listed patterns} |
| 1865 | \lineii{recursive-exclude \var{dir} \var{pat1} \var{pat2} ...} |
| 1866 | {exclude all files under \var{dir} matching any of the listed patterns} |
| 1867 | \lineii{global-include \var{pat1} \var{pat2} ...} |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 1868 | {include all files anywhere in the source tree matching\\& |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1869 | any of the listed patterns} |
| 1870 | \lineii{global-exclude \var{pat1} \var{pat2} ...} |
Greg Ward | 1bbe329 | 2000-06-25 03:14:13 +0000 | [diff] [blame] | 1871 | {exclude all files anywhere in the source tree matching\\& |
Greg Ward | 87da1ea | 2000-04-21 04:35:25 +0000 | [diff] [blame] | 1872 | any of the listed patterns} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1873 | \lineii{prune \var{dir}}{exclude all files under \var{dir}} |
| 1874 | \lineii{graft \var{dir}}{include all files under \var{dir}} |
| 1875 | \end{tableii} |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1876 | The patterns here are \UNIX-style ``glob'' patterns: \code{*} matches any |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1877 | sequence of regular filename characters, \code{?} matches any single |
| 1878 | regular filename character, and \code{[\var{range}]} matches any of the |
| 1879 | 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] | 1880 | \code{a-f0-9\_.}). The definition of ``regular filename character'' is |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1881 | platform-specific: on \UNIX{} it is anything except slash; on Windows |
| 1882 | anything except backslash or colon; on MacOS anything except colon. |
Greg Ward | b652897 | 2000-09-07 02:40:37 +0000 | [diff] [blame] | 1883 | |
Fred Drake | eff9a87 | 2000-10-26 16:41:03 +0000 | [diff] [blame] | 1884 | \XXX{Windows and MacOS support not there yet} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1885 | |
| 1886 | |
Fred Drake | a09262e | 2001-03-01 18:35:43 +0000 | [diff] [blame] | 1887 | %\subsection{Creating a built distribution: the |
| 1888 | % \protect\command{bdist} command family} |
| 1889 | %\label{bdist-cmds} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1890 | |
| 1891 | |
Fred Drake | ab70b38 | 2001-08-02 15:13:15 +0000 | [diff] [blame] | 1892 | %\subsubsection{\protect\command{bdist}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1893 | |
Fred Drake | ab70b38 | 2001-08-02 15:13:15 +0000 | [diff] [blame] | 1894 | %\subsubsection{\protect\command{bdist\_dumb}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1895 | |
Fred Drake | ab70b38 | 2001-08-02 15:13:15 +0000 | [diff] [blame] | 1896 | %\subsubsection{\protect\command{bdist\_rpm}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1897 | |
Fred Drake | ab70b38 | 2001-08-02 15:13:15 +0000 | [diff] [blame] | 1898 | %\subsubsection{\protect\command{bdist\_wininst}} |
| 1899 | |
| 1900 | |
| 1901 | \input{sysconfig} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 1902 | |
| 1903 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 1904 | \end{document} |