blob: c363320b188e0039e819d0b2428b899450850918 [file] [log] [blame]
Greg Wardabc52162000-02-26 00:52:48 +00001\documentclass{howto}
Greg Ward16aafcd2000-04-09 04:06:44 +00002\usepackage{distutils}
Greg Wardabc52162000-02-26 00:52:48 +00003
Greg Wardb6528972000-09-07 02:40:37 +00004% $Id$
5
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00006% TODO
7% Document extension.read_setup_file
8% Document build_clib command
9%
10
Greg Ward16aafcd2000-04-09 04:06:44 +000011\title{Distributing Python Modules}
Greg Wardabc52162000-02-26 00:52:48 +000012
Greg Wardabc52162000-02-26 00:52:48 +000013\author{Greg Ward}
Fred Drake17f690f2001-07-14 02:14:42 +000014\authoraddress{Email: \email{gward@python.net}}
Greg Wardabc52162000-02-26 00:52:48 +000015
Greg Warde3cca262000-08-31 16:36:31 +000016\makeindex
Greg Ward16aafcd2000-04-09 04:06:44 +000017
Greg Wardabc52162000-02-26 00:52:48 +000018\begin{document}
19
Greg Wardfacb8db2000-04-09 04:32:40 +000020\maketitle
Greg Warde3cca262000-08-31 16:36:31 +000021\begin{abstract}
22 \noindent
23 This document describes the Python Distribution Utilities
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +000024 (``Distutils'') from the module developer's point of view, describing
Greg Warde3cca262000-08-31 16:36:31 +000025 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 Drakea09262e2001-03-01 18:35:43 +000030% The ugly "%begin{latexonly}" pseudo-environment supresses the table
31% of contents for HTML generation.
32%
33%begin{latexonly}
Greg Wardfacb8db2000-04-09 04:32:40 +000034\tableofcontents
Fred Drakea09262e2001-03-01 18:35:43 +000035%end{latexonly}
36
Greg Ward16aafcd2000-04-09 04:06:44 +000037
38\section{Introduction}
Greg Warde78298a2000-04-28 17:12:24 +000039\label{intro}
Greg Ward16aafcd2000-04-09 04:06:44 +000040
Andrew M. Kuchling40df7102002-05-08 13:39:03 +000041This document covers using the Distutils to distribute your Python
42modules, concentrating on the role of developer/distributor: if
Fred Drake01df4532000-06-30 03:36:41 +000043you're looking for information on installing Python modules, you
44should refer to the \citetitle[../inst/inst.html]{Installing Python
45Modules} manual.
Greg Ward16aafcd2000-04-09 04:06:44 +000046
47
Greg Wardfacb8db2000-04-09 04:32:40 +000048\section{Concepts \& Terminology}
Greg Warde78298a2000-04-28 17:12:24 +000049\label{concepts}
Greg Ward16aafcd2000-04-09 04:06:44 +000050
51Using the Distutils is quite simple, both for module developers and for
52users/administrators installing third-party modules. As a developer,
Thomas Heller5f52f722001-02-19 17:48:03 +000053your responsibilities (apart from writing solid, well-documented and
Greg Ward16aafcd2000-04-09 04:06:44 +000054well-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}
61Each of these tasks is covered in this document.
62
63Not all module developers have access to a multitude of platforms, so
64it's not always feasible to expect them to create a multitude of built
65distributions. It is hoped that a class of intermediaries, called
Greg Ward19c67f82000-06-24 01:33:16 +000066\emph{packagers}, will arise to address this need. Packagers will take
67source distributions released by module developers, build them on one or
68more platforms, and release the resulting built distributions. Thus,
69users on the most popular platforms will be able to install most popular
70Python module distributions in the most natural way for their platform,
71without having to run a single setup script or compile a line of code.
Greg Ward16aafcd2000-04-09 04:06:44 +000072
73
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +000074\subsection{A Simple Example}
Greg Warde78298a2000-04-28 17:12:24 +000075\label{simple-example}
Greg Ward16aafcd2000-04-09 04:06:44 +000076
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +000077The setup script is usually quite simple, although since it's written
78in Python, there are no arbitrary limits to what you can do with it,
79though you should be careful about putting arbitrarily expensive
80operations in your setup script. Unlike, say, Autoconf-style configure
81scripts, the setup script may be run multiple times in the course of
82building and installing your module distribution. If you need to
83insert potentially expensive processing steps into the Distutils
84chain, see section~\ref{extending} on extending the Distutils.
Andrew M. Kuchling40df7102002-05-08 13:39:03 +000085
86If all you want to do is distribute a module called \module{foo},
87contained in a file \file{foo.py}, then your setup script can be as
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +000088simple as this:
Fred Drakea09262e2001-03-01 18:35:43 +000089
Greg Ward16aafcd2000-04-09 04:06:44 +000090\begin{verbatim}
91from distutils.core import setup
Fred Drakea09262e2001-03-01 18:35:43 +000092setup(name="foo",
93 version="1.0",
94 py_modules=["foo"])
Greg Ward16aafcd2000-04-09 04:06:44 +000095\end{verbatim}
Greg Ward370248d2000-06-24 01:45:47 +000096
Greg Ward16aafcd2000-04-09 04:06:44 +000097Some observations:
98\begin{itemize}
Greg Ward370248d2000-06-24 01:45:47 +000099\item most information that you supply to the Distutils is supplied as
Greg Wardfacb8db2000-04-09 04:32:40 +0000100 keyword arguments to the \function{setup()} function
Greg Ward16aafcd2000-04-09 04:06:44 +0000101\item those keyword arguments fall into two categories: package
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000102 metadata (name, version number) and information about what's in the
Greg Ward370248d2000-06-24 01:45:47 +0000103 package (a list of pure Python modules, in this case)
Greg Ward16aafcd2000-04-09 04:06:44 +0000104\item modules are specified by module name, not filename (the same will
105 hold true for packages and extensions)
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000106\item it's recommended that you supply a little more metadata, in
Greg Ward16aafcd2000-04-09 04:06:44 +0000107 particular your name, email address and a URL for the project
Greg Ward47f99a62000-09-04 20:07:15 +0000108 (see section~\ref{setup-script} for an example)
Greg Ward16aafcd2000-04-09 04:06:44 +0000109\end{itemize}
110
Greg Ward370248d2000-06-24 01:45:47 +0000111To create a source distribution for this module, you would create a
112setup script, \file{setup.py}, containing the above code, and run:
Fred Drakea09262e2001-03-01 18:35:43 +0000113
Greg Ward16aafcd2000-04-09 04:06:44 +0000114\begin{verbatim}
115python setup.py sdist
116\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000117
Fred Drakeeff9a872000-10-26 16:41:03 +0000118which will create an archive file (e.g., tarball on \UNIX, ZIP file on
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000119Windows) containing your setup script \file{setup.py}, and your module
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000120\file{foo.py}. The archive file will be named \file{foo-1.0.tar.gz} (or
121\file{.zip}), and will unpack into a directory \file{foo-1.0}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000122
123If an end-user wishes to install your \module{foo} module, all she has
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000124to do is download \file{foo-1.0.tar.gz} (or \file{.zip}), unpack it,
125and---from the \file{foo-1.0} directory---run
Fred Drakea09262e2001-03-01 18:35:43 +0000126
Greg Ward16aafcd2000-04-09 04:06:44 +0000127\begin{verbatim}
128python setup.py install
129\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000130
Greg Ward16aafcd2000-04-09 04:06:44 +0000131which will ultimately copy \file{foo.py} to the appropriate directory
132for third-party modules in their Python installation.
133
134This simple example demonstrates some fundamental concepts of the
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000135Distutils. First, both developers and installers have the same basic
Greg Ward16aafcd2000-04-09 04:06:44 +0000136user interface, i.e. the setup script. The difference is which
137Distutils \emph{commands} they use: the \command{sdist} command is
138almost exclusively for module developers, while \command{install} is
139more often for installers (although most developers will want to install
140their own code occasionally).
141
Greg Ward16aafcd2000-04-09 04:06:44 +0000142If you want to make things really easy for your users, you can create
143one or more built distributions for them. For instance, if you are
144running on a Windows machine, and want to make things easy for other
145Windows users, you can create an executable installer (the most
146appropriate type of built distribution for this platform) with the
Greg Ward59d382e2000-05-26 01:04:47 +0000147\command{bdist\_wininst} command. For example:
Fred Drakea09262e2001-03-01 18:35:43 +0000148
Greg Ward16aafcd2000-04-09 04:06:44 +0000149\begin{verbatim}
Greg Ward59d382e2000-05-26 01:04:47 +0000150python setup.py bdist_wininst
Greg Ward16aafcd2000-04-09 04:06:44 +0000151\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000152
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000153will create an executable installer, \file{foo-1.0.win32.exe}, in the
Greg Ward1d8f57a2000-08-05 00:43:11 +0000154current directory.
Greg Ward16aafcd2000-04-09 04:06:44 +0000155
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000156Other useful built distribution formats are RPM, implemented by the
157\command{bdist\_rpm} command, Solaris \program{pkgtool}
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000158(\command{bdist\_pkgtool}), and HP-UX \program{swinstall}
159(\command{bdist_sdux}). For example, the following command will
160create an RPM file called \file{foo-1.0.noarch.rpm}:
Fred Drakea09262e2001-03-01 18:35:43 +0000161
Greg Ward1d8f57a2000-08-05 00:43:11 +0000162\begin{verbatim}
163python setup.py bdist_rpm
164\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000165
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000166(The \command{bdist\_rpm} command uses the \command{rpm} executable,
167therefore this has to be run on an RPM-based system such as Red Hat
168Linux, SuSE Linux, or Mandrake Linux.)
Greg Ward1d8f57a2000-08-05 00:43:11 +0000169
170You can find out what distribution formats are available at any time by
171running
Fred Drakea09262e2001-03-01 18:35:43 +0000172
Greg Ward1d8f57a2000-08-05 00:43:11 +0000173\begin{verbatim}
174python setup.py bdist --help-formats
175\end{verbatim}
Greg Ward16aafcd2000-04-09 04:06:44 +0000176
177
178\subsection{General Python terminology}
Greg Warde78298a2000-04-28 17:12:24 +0000179\label{python-terms}
Greg Ward16aafcd2000-04-09 04:06:44 +0000180
181If you're reading this document, you probably have a good idea of what
182modules, extensions, and so forth are. Nevertheless, just to be sure
183that everyone is operating from a common starting point, we offer the
184following glossary of common Python terms:
185\begin{description}
186\item[module] the basic unit of code reusability in Python: a block of
Greg Ward1d8f57a2000-08-05 00:43:11 +0000187 code imported by some other code. Three types of modules concern us
188 here: pure Python modules, extension modules, and packages.
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000189
Greg Ward16aafcd2000-04-09 04:06:44 +0000190\item[pure Python module] a module written in Python and contained in a
191 single \file{.py} file (and possibly associated \file{.pyc} and/or
192 \file{.pyo} files). Sometimes referred to as a ``pure module.''
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000193
Greg Ward16aafcd2000-04-09 04:06:44 +0000194\item[extension module] a module written in the low-level language of
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000195 the Python implementation: C/C++ for Python, Java for Jython.
Greg Ward16aafcd2000-04-09 04:06:44 +0000196 Typically contained in a single dynamically loadable pre-compiled
Fred Drakeeff9a872000-10-26 16:41:03 +0000197 file, e.g. a shared object (\file{.so}) file for Python extensions on
198 \UNIX, a DLL (given the \file{.pyd} extension) for Python extensions
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000199 on Windows, or a Java class file for Jython extensions. (Note that
Fred Drakeeff9a872000-10-26 16:41:03 +0000200 currently, the Distutils only handles C/C++ extensions for Python.)
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000201
Greg Ward16aafcd2000-04-09 04:06:44 +0000202\item[package] a module that contains other modules; typically contained
203 in a directory in the filesystem and distinguished from other
204 directories by the presence of a file \file{\_\_init\_\_.py}.
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000205
Greg Ward6153fa12000-05-26 02:24:28 +0000206\item[root package] the root of the hierarchy of packages. (This isn't
207 really a package, since it doesn't have an \file{\_\_init\_\_.py}
208 file. But we have to call it something.) The vast majority of the
209 standard library is in the root package, as are many small, standalone
210 third-party modules that don't belong to a larger module collection.
211 Unlike regular packages, modules in the root package can be found in
212 many directories: in fact, every directory listed in \code{sys.path}
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000213 contributes modules to the root package.
Greg Ward16aafcd2000-04-09 04:06:44 +0000214\end{description}
215
216
217\subsection{Distutils-specific terminology}
Greg Warde78298a2000-04-28 17:12:24 +0000218\label{distutils-term}
Greg Ward16aafcd2000-04-09 04:06:44 +0000219
220The following terms apply more specifically to the domain of
221distributing Python modules using the Distutils:
222\begin{description}
223\item[module distribution] a collection of Python modules distributed
224 together as a single downloadable resource and meant to be installed
225 \emph{en masse}. Examples of some well-known module distributions are
226 Numeric Python, PyXML, PIL (the Python Imaging Library), or
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000227 mxBase. (This would be called a \emph{package}, except that term
Greg Ward59d382e2000-05-26 01:04:47 +0000228 is already taken in the Python context: a single module distribution
229 may contain zero, one, or many Python packages.)
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000230
Greg Ward16aafcd2000-04-09 04:06:44 +0000231\item[pure module distribution] a module distribution that contains only
232 pure Python modules and packages. Sometimes referred to as a ``pure
233 distribution.''
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000234
Greg Ward16aafcd2000-04-09 04:06:44 +0000235\item[non-pure module distribution] a module distribution that contains
236 at least one extension module. Sometimes referred to as a ``non-pure
237 distribution.''
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000238
Greg Ward16aafcd2000-04-09 04:06:44 +0000239\item[distribution root] the top-level directory of your source tree (or
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000240 source distribution); the directory where \file{setup.py} exists. Generally
241 \file{setup.py} will be run from this directory.
Greg Ward16aafcd2000-04-09 04:06:44 +0000242\end{description}
243
244
245\section{Writing the Setup Script}
Greg Warde78298a2000-04-28 17:12:24 +0000246\label{setup-script}
Greg Ward16aafcd2000-04-09 04:06:44 +0000247
248The setup script is the centre of all activity in building,
249distributing, and installing modules using the Distutils. The main
250purpose of the setup script is to describe your module distribution to
Greg Wardd5767a52000-04-19 22:48:09 +0000251the Distutils, so that the various commands that operate on your modules
Greg Ward59d382e2000-05-26 01:04:47 +0000252do the right thing. As we saw in section~\ref{simple-example} above,
253the setup script consists mainly of a call to \function{setup()}, and
Greg Ward1bbe3292000-06-25 03:14:13 +0000254most information supplied to the Distutils by the module developer is
255supplied as keyword arguments to \function{setup()}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000256
257Here's a slightly more involved example, which we'll follow for the next
258couple of sections: the Distutils' own setup script. (Keep in mind that
Greg Ward1d8f57a2000-08-05 00:43:11 +0000259although the Distutils are included with Python 1.6 and later, they also
260have an independent existence so that Python 1.5.2 users can use them to
261install other module distributions. The Distutils' own setup script,
262shown here, is used to install the package into Python 1.5.2.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000263
264\begin{verbatim}
265#!/usr/bin/env python
266
267from distutils.core import setup
268
Fred Drakea09262e2001-03-01 18:35:43 +0000269setup(name="Distutils",
270 version="1.0",
271 description="Python Distribution Utilities",
272 author="Greg Ward",
273 author_email="gward@python.net",
274 url="http://www.python.org/sigs/distutils-sig/",
275 packages=['distutils', 'distutils.command'],
276 )
Greg Ward16aafcd2000-04-09 04:06:44 +0000277\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000278
Greg Ward16aafcd2000-04-09 04:06:44 +0000279There are only two differences between this and the trivial one-file
Greg Warde78298a2000-04-28 17:12:24 +0000280distribution presented in section~\ref{simple-example}: more
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000281metadata, and the specification of pure Python modules by package,
Greg Ward16aafcd2000-04-09 04:06:44 +0000282rather than by module. This is important since the Distutils consist of
283a couple of dozen modules split into (so far) two packages; an explicit
284list of every module would be tedious to generate and difficult to
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +0000285maintain. For more information on the additional meta-data, see
286section~\ref{meta-data}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000287
Greg Ward46b98e32000-04-14 01:53:36 +0000288Note that any pathnames (files or directories) supplied in the setup
Fred Drakeeff9a872000-10-26 16:41:03 +0000289script should be written using the \UNIX{} convention, i.e.
Greg Ward46b98e32000-04-14 01:53:36 +0000290slash-separated. The Distutils will take care of converting this
Greg Ward59d382e2000-05-26 01:04:47 +0000291platform-neutral representation into whatever is appropriate on your
Greg Ward46b98e32000-04-14 01:53:36 +0000292current platform before actually using the pathname. This makes your
293setup script portable across operating systems, which of course is one
294of the major goals of the Distutils. In this spirit, all pathnames in
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000295this document are slash-separated. (MacOS programmers should keep in
Greg Ward59d382e2000-05-26 01:04:47 +0000296mind that the \emph{absence} of a leading slash indicates a relative
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000297path, the opposite of the MacOS convention with colons.)
Greg Ward46b98e32000-04-14 01:53:36 +0000298
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000299This, of course, only applies to pathnames given to Distutils
300functions. If you, for example, use standard python functions such as
301\function{glob.glob} or \function{os.listdir} to specify files, you
302should be careful to write portable code instead of hardcoding path
303separators:
Fred Drakea09262e2001-03-01 18:35:43 +0000304
Thomas Heller5f52f722001-02-19 17:48:03 +0000305\begin{verbatim}
306 glob.glob(os.path.join('mydir', 'subdir', '*.html'))
307 os.listdir(os.path.join('mydir', 'subdir'))
308\end{verbatim}
Greg Ward16aafcd2000-04-09 04:06:44 +0000309
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000310
Greg Ward2afffd42000-08-06 20:37:24 +0000311\subsection{Listing whole packages}
312\label{listing-packages}
Greg Ward16aafcd2000-04-09 04:06:44 +0000313
314The \option{packages} option tells the Distutils to process (build,
315distribute, install, etc.) all pure Python modules found in each package
316mentioned in the \option{packages} list. In order to do this, of
317course, there has to be a correspondence between package names and
318directories in the filesystem. The default correspondence is the most
Greg Ward1ecc2512000-04-19 22:36:24 +0000319obvious one, i.e. package \module{distutils} is found in the directory
Greg Ward16aafcd2000-04-09 04:06:44 +0000320\file{distutils} relative to the distribution root. Thus, when you say
321\code{packages = ['foo']} in your setup script, you are promising that
322the Distutils will find a file \file{foo/\_\_init\_\_.py} (which might
323be spelled differently on your system, but you get the idea) relative to
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000324the directory where your setup script lives. If you break this
325promise, the Distutils will issue a warning but still process the broken
326package anyways.
Greg Ward16aafcd2000-04-09 04:06:44 +0000327
328If you use a different convention to lay out your source directory,
329that's no problem: you just have to supply the \option{package\_dir}
330option to tell the Distutils about your convention. For example, say
Greg Ward1d8f57a2000-08-05 00:43:11 +0000331you keep all Python source under \file{lib}, so that modules in the
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000332``root package'' (i.e., not in any package at all) are in
Greg Ward1d8f57a2000-08-05 00:43:11 +0000333\file{lib}, modules in the \module{foo} package are in \file{lib/foo},
334and so forth. Then you would put
Fred Drakea09262e2001-03-01 18:35:43 +0000335
Greg Ward16aafcd2000-04-09 04:06:44 +0000336\begin{verbatim}
337package_dir = {'': 'lib'}
338\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000339
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000340in your setup script. The keys to this dictionary are package names,
Greg Ward1d8f57a2000-08-05 00:43:11 +0000341and an empty package name stands for the root package. The values are
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000342directory names relative to your distribution root. In this case, when
Greg Ward1d8f57a2000-08-05 00:43:11 +0000343you say \code{packages = ['foo']}, you are promising that the file
Greg Ward16aafcd2000-04-09 04:06:44 +0000344\file{lib/foo/\_\_init\_\_.py} exists.
345
Greg Ward1ecc2512000-04-19 22:36:24 +0000346Another possible convention is to put the \module{foo} package right in
347\file{lib}, the \module{foo.bar} package in \file{lib/bar}, etc. This
Greg Ward16aafcd2000-04-09 04:06:44 +0000348would be written in the setup script as
Fred Drakea09262e2001-03-01 18:35:43 +0000349
Greg Ward16aafcd2000-04-09 04:06:44 +0000350\begin{verbatim}
351package_dir = {'foo': 'lib'}
352\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000353
Greg Ward59d382e2000-05-26 01:04:47 +0000354A \code{\var{package}: \var{dir}} entry in the \option{package\_dir}
355dictionary implicitly applies to all packages below \var{package}, so
356the \module{foo.bar} case is automatically handled here. In this
357example, having \code{packages = ['foo', 'foo.bar']} tells the Distutils
358to look for \file{lib/\_\_init\_\_.py} and
359\file{lib/bar/\_\_init\_\_.py}. (Keep in mind that although
360\option{package\_dir} applies recursively, you must explicitly list all
361packages in \option{packages}: the Distutils will \emph{not} recursively
362scan your source tree looking for any directory with an
363\file{\_\_init\_\_.py} file.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000364
365
366\subsection{Listing individual modules}
Greg Warde78298a2000-04-28 17:12:24 +0000367\label{listing-modules}
Greg Ward16aafcd2000-04-09 04:06:44 +0000368
369For a small module distribution, you might prefer to list all modules
370rather than listing packages---especially the case of a single module
371that goes in the ``root package'' (i.e., no package at all). This
Greg Warde78298a2000-04-28 17:12:24 +0000372simplest case was shown in section~\ref{simple-example}; here is a
Greg Ward16aafcd2000-04-09 04:06:44 +0000373slightly more involved example:
Fred Drakea09262e2001-03-01 18:35:43 +0000374
Greg Ward16aafcd2000-04-09 04:06:44 +0000375\begin{verbatim}
376py_modules = ['mod1', 'pkg.mod2']
377\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000378
Greg Ward16aafcd2000-04-09 04:06:44 +0000379This describes two modules, one of them in the ``root'' package, the
Greg Wardd5767a52000-04-19 22:48:09 +0000380other in the \module{pkg} package. Again, the default package/directory
381layout implies that these two modules can be found in \file{mod1.py} and
382\file{pkg/mod2.py}, and that \file{pkg/\_\_init\_\_.py} exists as well.
Greg Ward2afffd42000-08-06 20:37:24 +0000383And again, you can override the package/directory correspondence using
384the \option{package\_dir} option.
Greg Ward59d382e2000-05-26 01:04:47 +0000385
386
387\subsection{Describing extension modules}
Greg Ward1365a302000-08-31 14:47:05 +0000388\label{describing-extensions}
Greg Ward59d382e2000-05-26 01:04:47 +0000389
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000390% XXX read over this section
Greg Ward2afffd42000-08-06 20:37:24 +0000391Just as writing Python extension modules is a bit more complicated than
392writing pure Python modules, describing them to the Distutils is a bit
393more complicated. Unlike pure modules, it's not enough just to list
394modules or packages and expect the Distutils to go out and find the
395right files; you have to specify the extension name, source file(s), and
396any compile/link requirements (include directories, libraries to link
397with, etc.).
398
399All of this is done through another keyword argument to
400\function{setup()}, the \option{extensions} option. \option{extensions}
401is just a list of \class{Extension} instances, each of which describes a
402single extension module. Suppose your distribution includes a single
403extension, called \module{foo} and implemented by \file{foo.c}. If no
404additional instructions to the compiler/linker are needed, describing
405this extension is quite simple:
Fred Drakea09262e2001-03-01 18:35:43 +0000406
Greg Ward2afffd42000-08-06 20:37:24 +0000407\begin{verbatim}
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000408uExtension("foo", ["foo.c"])
Greg Ward2afffd42000-08-06 20:37:24 +0000409\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000410
Greg Ward2afffd42000-08-06 20:37:24 +0000411The \class{Extension} class can be imported from
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000412\module{distutils.core} along with \function{setup()}. Thus, the setup
Greg Ward2afffd42000-08-06 20:37:24 +0000413script for a module distribution that contains only this one extension
414and nothing else might be:
Fred Drakea09262e2001-03-01 18:35:43 +0000415
Greg Ward2afffd42000-08-06 20:37:24 +0000416\begin{verbatim}
417from distutils.core import setup, Extension
Fred Drakea09262e2001-03-01 18:35:43 +0000418setup(name="foo", version="1.0",
419 ext_modules=[Extension("foo", ["foo.c"])])
Greg Ward2afffd42000-08-06 20:37:24 +0000420\end{verbatim}
421
422The \class{Extension} class (actually, the underlying extension-building
Andrew M. Kuchlingda23c4f2001-02-17 00:38:48 +0000423machinery implemented by the \command{build\_ext} command) supports a
Greg Ward2afffd42000-08-06 20:37:24 +0000424great deal of flexibility in describing Python extensions, which is
425explained in the following sections.
426
427
428\subsubsection{Extension names and packages}
429
430The first argument to the \class{Extension} constructor is always the
431name of the extension, including any package names. For example,
Fred Drakea09262e2001-03-01 18:35:43 +0000432
Greg Ward2afffd42000-08-06 20:37:24 +0000433\begin{verbatim}
434Extension("foo", ["src/foo1.c", "src/foo2.c"])
435\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000436
Greg Ward2afffd42000-08-06 20:37:24 +0000437describes an extension that lives in the root package, while
Fred Drakea09262e2001-03-01 18:35:43 +0000438
Greg Ward2afffd42000-08-06 20:37:24 +0000439\begin{verbatim}
440Extension("pkg.foo", ["src/foo1.c", "src/foo2.c"])
441\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000442
Greg Ward2afffd42000-08-06 20:37:24 +0000443describes the same extension in the \module{pkg} package. The source
444files and resulting object code are identical in both cases; the only
445difference is where in the filesystem (and therefore where in Python's
446namespace hierarchy) the resulting extension lives.
447
448If you have a number of extensions all in the same package (or all under
449the same base package), use the \option{ext\_package} keyword argument
450to \function{setup()}. For example,
Fred Drakea09262e2001-03-01 18:35:43 +0000451
Greg Ward2afffd42000-08-06 20:37:24 +0000452\begin{verbatim}
453setup(...
Fred Drakea09262e2001-03-01 18:35:43 +0000454 ext_package="pkg",
455 ext_modules=[Extension("foo", ["foo.c"]),
456 Extension("subpkg.bar", ["bar.c"])]
Greg Ward2afffd42000-08-06 20:37:24 +0000457 )
458\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000459
Greg Ward2afffd42000-08-06 20:37:24 +0000460will compile \file{foo.c} to the extension \module{pkg.foo}, and
461\file{bar.c} to \module{pkg.subpkg.bar}.
462
463
464\subsubsection{Extension source files}
465
466The second argument to the \class{Extension} constructor is a list of
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000467source files. Since the Distutils currently only support C, \Cpp, and
468Objective-C extensions, these are normally C/\Cpp/Objective-C source
469files. (Be sure to use appropriate extensions to distinguish \Cpp\
470source files: \file{.cc} and \file{.cpp} seem to be recognized by both
471\UNIX{} and Windows compilers.)
Greg Ward2afffd42000-08-06 20:37:24 +0000472
473However, you can also include SWIG interface (\file{.i}) files in the
474list; the \command{build\_ext} command knows how to deal with SWIG
475extensions: it will run SWIG on the interface file and compile the
476resulting C/C++ file into your extension.
477
478\XXX{SWIG support is rough around the edges and largely untested;
479 especially SWIG support of C++ extensions! Explain in more detail
480 here when the interface firms up.}
481
482On some platforms, you can include non-source files that are processed
483by the compiler and included in your extension. Currently, this just
Thomas Heller5f52f722001-02-19 17:48:03 +0000484means Windows message text (\file{.mc}) files and resource definition
485(\file{.rc}) files for Visual C++. These will be compiled to binary resource
486(\file{.res}) files and linked into the executable.
Greg Ward2afffd42000-08-06 20:37:24 +0000487
488
489\subsubsection{Preprocessor options}
490
491Three optional arguments to \class{Extension} will help if you need to
492specify include directories to search or preprocessor macros to
493define/undefine: \code{include\_dirs}, \code{define\_macros}, and
494\code{undef\_macros}.
495
496For example, if your extension requires header files in the
497\file{include} directory under your distribution root, use the
498\code{include\_dirs} option:
Fred Drakea09262e2001-03-01 18:35:43 +0000499
Greg Ward2afffd42000-08-06 20:37:24 +0000500\begin{verbatim}
501Extension("foo", ["foo.c"], include_dirs=["include"])
502\end{verbatim}
503
504You can specify absolute directories there; if you know that your
Fred Drakeeff9a872000-10-26 16:41:03 +0000505extension will only be built on \UNIX{} systems with X11R6 installed to
Greg Ward2afffd42000-08-06 20:37:24 +0000506\file{/usr}, you can get away with
Fred Drakea09262e2001-03-01 18:35:43 +0000507
Greg Ward2afffd42000-08-06 20:37:24 +0000508\begin{verbatim}
509Extension("foo", ["foo.c"], include_dirs=["/usr/include/X11"])
510\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000511
Greg Ward2afffd42000-08-06 20:37:24 +0000512You should avoid this sort of non-portable usage if you plan to
Greg Ward58437f22002-05-10 14:40:22 +0000513distribute your code: it's probably better to write C code like
514\begin{verbatim}
515#include <X11/Xlib.h>
516\end{verbatim}
Greg Ward2afffd42000-08-06 20:37:24 +0000517
518If you need to include header files from some other Python extension,
Greg Ward58437f22002-05-10 14:40:22 +0000519you can take advantage of the fact that header files are installed in a
520consistent way by the Distutils \command{install\_header} command. For
521example, the Numerical Python header files are installed (on a standard
522Unix installation) to \file{/usr/local/include/python1.5/Numerical}.
523(The exact location will differ according to your platform and Python
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000524installation.) Since the Python include
Greg Ward58437f22002-05-10 14:40:22 +0000525directory---\file{/usr/local/include/python1.5} in this case---is always
526included in the search path when building Python extensions, the best
527approach is to write C code like
528\begin{verbatim}
529#include <Numerical/arrayobject.h>
530\end{verbatim}
531If you must put the \file{Numerical} include directory right into your
532header search path, though, you can find that directory using the
533Distutils \module{sysconfig} module:
Fred Drakea09262e2001-03-01 18:35:43 +0000534
Greg Ward2afffd42000-08-06 20:37:24 +0000535\begin{verbatim}
536from distutils.sysconfig import get_python_inc
537incdir = os.path.join(get_python_inc(plat_specific=1), "Numerical")
538setup(...,
539 Extension(..., include_dirs=[incdir]))
540\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000541
Greg Ward2afffd42000-08-06 20:37:24 +0000542Even though this is quite portable---it will work on any Python
543installation, regardless of platform---it's probably easier to just
544write your C code in the sensible way.
545
546You can define and undefine pre-processor macros with the
547\code{define\_macros} and \code{undef\_macros} options.
548\code{define\_macros} takes a list of \code{(name, value)} tuples, where
549\code{name} is the name of the macro to define (a string) and
550\code{value} is its value: either a string or \code{None}. (Defining a
551macro \code{FOO} to \code{None} is the equivalent of a bare
552\code{\#define FOO} in your C source: with most compilers, this sets
553\code{FOO} to the string \code{1}.) \code{undef\_macros} is just
554a list of macros to undefine.
555
556For example:
Fred Drakea09262e2001-03-01 18:35:43 +0000557
Greg Ward2afffd42000-08-06 20:37:24 +0000558\begin{verbatim}
559Extension(...,
560 define_macros=[('NDEBUG', '1')],
561 ('HAVE_STRFTIME', None),
562 undef_macros=['HAVE_FOO', 'HAVE_BAR'])
563\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000564
Greg Ward2afffd42000-08-06 20:37:24 +0000565is the equivalent of having this at the top of every C source file:
Fred Drakea09262e2001-03-01 18:35:43 +0000566
Greg Ward2afffd42000-08-06 20:37:24 +0000567\begin{verbatim}
568#define NDEBUG 1
569#define HAVE_STRFTIME
570#undef HAVE_FOO
571#undef HAVE_BAR
572\end{verbatim}
573
574
575\subsubsection{Library options}
576
577You can also specify the libraries to link against when building your
578extension, and the directories to search for those libraries. The
579\code{libraries} option is a list of libraries to link against,
580\code{library\_dirs} is a list of directories to search for libraries at
581link-time, and \code{runtime\_library\_dirs} is a list of directories to
582search for shared (dynamically loaded) libraries at run-time.
583
584For example, if you need to link against libraries known to be in the
585standard library search path on target systems
Fred Drakea09262e2001-03-01 18:35:43 +0000586
Greg Ward2afffd42000-08-06 20:37:24 +0000587\begin{verbatim}
588Extension(...,
589 libraries=["gdbm", "readline"])
590\end{verbatim}
591
592If you need to link with libraries in a non-standard location, you'll
593have to include the location in \code{library\_dirs}:
Fred Drakea09262e2001-03-01 18:35:43 +0000594
Greg Ward2afffd42000-08-06 20:37:24 +0000595\begin{verbatim}
596Extension(...,
597 library_dirs=["/usr/X11R6/lib"],
598 libraries=["X11", "Xt"])
599\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000600
Greg Ward2afffd42000-08-06 20:37:24 +0000601(Again, this sort of non-portable construct should be avoided if you
602intend to distribute your code.)
603
Thomas Heller5f52f722001-02-19 17:48:03 +0000604\XXX{Should mention clib libraries here or somewhere else!}
605
606\subsubsection{Other options}
607
608There are still some other options which can be used to handle special
609cases.
610
611The \option{extra\_objects} option is a list of object files to be passed
612to the linker. These files must not have extensions, as the default
613extension for the compiler is used.
614
615\option{extra\_compile\_args} and \option{extra\_link\_args} can be used
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000616to specify additional command line options for the respective compiler and
617linker command lines.
Thomas Heller5f52f722001-02-19 17:48:03 +0000618
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000619\option{export\_symbols} is only useful on Windows. It can contain a list
Thomas Heller5f52f722001-02-19 17:48:03 +0000620of symbols (functions or variables) to be exported. This option
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000621is not needed when building compiled extensions: Distutils
622will automatically add \code{initmodule}
623to the list of exported symbols.
Thomas Heller5f52f722001-02-19 17:48:03 +0000624
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000625\subsection{Installing Scripts}
Thomas Heller5f52f722001-02-19 17:48:03 +0000626So far we have been dealing with pure and non-pure Python modules,
627which are usually not run by themselves but imported by scripts.
628
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000629Scripts are files containing Python source code, intended to be
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000630started from the command line. Scripts don't require Distutils to do
631anything very complicated. The only clever feature is that if the
632first line of the script starts with \code{\#!} and contains the word
633``python'', the Distutils will adjust the first line to refer to the
634current interpreter location.
Thomas Heller5f52f722001-02-19 17:48:03 +0000635
636The \option{scripts} option simply is a list of files to be handled
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000637in this way. From the PyXML setup script:
638
639\begin{verbatim}
640setup (...
641 scripts = ['scripts/xmlproc_parse', 'scripts/xmlproc_val']
642 )
643\end{verbatim}
Thomas Heller5f52f722001-02-19 17:48:03 +0000644
645
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000646\subsection{Installing Additional Files}
Fred Drakea09262e2001-03-01 18:35:43 +0000647
Thomas Heller5f52f722001-02-19 17:48:03 +0000648The \option{data\_files} option can be used to specify additional
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000649files needed by the module distribution: configuration files, message
650catalogs, data files, anything which doesn't fit in the previous
651categories.
Thomas Heller5f52f722001-02-19 17:48:03 +0000652
Fred Drake632bda32002-03-08 22:02:06 +0000653\option{data\_files} specifies a sequence of (\var{directory},
654\var{files}) pairs in the following way:
Fred Drakea09262e2001-03-01 18:35:43 +0000655
Thomas Heller5f52f722001-02-19 17:48:03 +0000656\begin{verbatim}
657setup(...
658 data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +0000659 ('config', ['cfg/data.cfg']),
660 ('/etc/init.d', ['init-script'])]
661 )
Thomas Heller5f52f722001-02-19 17:48:03 +0000662\end{verbatim}
663
664Note that you can specify the directory names where the data files
665will be installed, but you cannot rename the data files themselves.
666
Fred Drake632bda32002-03-08 22:02:06 +0000667Each (\var{directory}, \var{files}) pair in the sequence specifies the
668installation directory and the files to install there. If
669\var{directory} is a relative path, it is interpreted relative to the
670installation prefix (Python's \code{sys.prefix} for pure-Python
671packages, \code{sys.exec_prefix} for packages that contain extension
672modules). Each file name in \var{files} is interpreted relative to
673the \file{setup.py} script at the top of the package source
674distribution. No directory information from \var{files} is used to
675determine the final location of the installed file; only the name of
676the file is used.
677
Thomas Heller5f52f722001-02-19 17:48:03 +0000678You can specify the \option{data\_files} options as a simple sequence
679of files without specifying a target directory, but this is not recommended,
680and the \command{install} command will print a warning in this case.
681To install data files directly in the target directory, an empty
682string should be given as the directory.
Greg Ward16aafcd2000-04-09 04:06:44 +0000683
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +0000684\subsection{Additional meta-data}
685\label{meta-data}
686
687The setup script may include additional meta-data beyond the name and
688version. This information includes:
689
690\begin{tableiii}{l|l|c}{code}%
691 {Meta-Data}{Description}{Notes}
692 \lineiii{name}{the name of the package}{(1)}
693 \lineiii{version}{the version of this release}{(1)}
694 \lineiii{author}{package author's name}{(2)}
695 \lineiii{author_email}{email address of the package author}{(2)}
696 \lineiii{maintainer}{package maintainer's name}{(2)}
697 \lineiii{maintainer_email}{email address of the package maintainer}{(2)}
698 \lineiii{home_page}{a URL}{(1)}
699 \lineiii{license}{the terms the package is released under}{}
700 \lineiii{description}{a short, summary description of the package}{}
701 \lineiii{long_description}{a longer description of the package}{}
702 \lineiii{keywords}{some keywords appropriate to the package}{}
703 \lineiii{platform}{a list of the target platforms}{}
704 \lineiii{classifiers}{a list of Trove classifiers}{(2)}
705\end{tableiii}
706
707\noindent Notes:
708\begin{description}
709\item[(1)] these fields are required
710\item[(2)] either the author or the maintainer must be nominated
711\item[(3)] should not be used if your package is to be compatible with
712 Python versions prior to 2.2.3 or 2.3. The list is available from the
713 PyPI website.
714\end{description}
715
716\option{classifiers} are specified in a python list:
717
718\begin{verbatim}
719setup(...
720 classifiers = [
721 'Development Status :: 4 - Beta',
722 'Environment :: Console',
723 'Environment :: Web Environment',
724 'Intended Audience :: End Users/Desktop',
725 'Intended Audience :: Developers',
726 'Intended Audience :: System Administrators',
727 'License :: OSI Approved :: Python Software Foundation License',
728 'Operating System :: MacOS :: MacOS X',
729 'Operating System :: Microsoft :: Windows',
730 'Operating System :: POSIX',
731 'Programming Language :: Python',
732 'Topic :: Communications :: Email',
733 'Topic :: Office/Business',
734 'Topic :: Software Development :: Bug Tracking',
735 ],
736 ...
737)
738\end{verbatim}
739
740If you wish to include classifiers in your \file{setup.py} file and also
741wish to remain backwards-compatible with Python releases prior to 2.2.3,
742then you can include the following code fragment in your \file{setup.py}
743before the \code{setup()} call.
744
745\begin{verbatim}
746# patch distutils if it can't cope with the "classifiers" keyword
747if sys.version < '2.2.3':
748 from distutils.dist import DistributionMetadata
749 DistributionMetadata.classifiers = None
750\end{verbatim}
751
Greg Ward16aafcd2000-04-09 04:06:44 +0000752
753\section{Writing the Setup Configuration File}
Greg Warde78298a2000-04-28 17:12:24 +0000754\label{setup-config}
Greg Ward16aafcd2000-04-09 04:06:44 +0000755
Greg Ward16aafcd2000-04-09 04:06:44 +0000756Often, it's not possible to write down everything needed to build a
Greg Ward47f99a62000-09-04 20:07:15 +0000757distribution \emph{a priori}: you may need to get some information from
758the user, or from the user's system, in order to proceed. As long as
759that information is fairly simple---a list of directories to search for
760C header files or libraries, for example---then providing a
761configuration file, \file{setup.cfg}, for users to edit is a cheap and
762easy way to solicit it. Configuration files also let you provide
763default values for any command option, which the installer can then
764override either on the command-line or by editing the config file.
Greg Ward16aafcd2000-04-09 04:06:44 +0000765
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000766% (If you have more advanced needs, such as determining which extensions
767% to build based on what capabilities are present on the target system,
768% then you need the Distutils ``auto-configuration'' facility. This
769% started to appear in Distutils 0.9 but, as of this writing, isn't mature
770% or stable enough yet for real-world use.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000771
Greg Ward47f99a62000-09-04 20:07:15 +0000772The setup configuration file is a useful middle-ground between the setup
773script---which, ideally, would be opaque to installers\footnote{This
774 ideal probably won't be achieved until auto-configuration is fully
775 supported by the Distutils.}---and the command-line to the setup
776script, which is outside of your control and entirely up to the
777installer. In fact, \file{setup.cfg} (and any other Distutils
778configuration files present on the target system) are processed after
779the contents of the setup script, but before the command-line. This has
780several useful consequences:
781\begin{itemize}
782\item installers can override some of what you put in \file{setup.py} by
783 editing \file{setup.cfg}
784\item you can provide non-standard defaults for options that are not
785 easily set in \file{setup.py}
786\item installers can override anything in \file{setup.cfg} using the
787 command-line options to \file{setup.py}
788\end{itemize}
789
790The basic syntax of the configuration file is simple:
Fred Drakea09262e2001-03-01 18:35:43 +0000791
Greg Ward47f99a62000-09-04 20:07:15 +0000792\begin{verbatim}
793[command]
794option=value
795...
796\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000797
Greg Ward47f99a62000-09-04 20:07:15 +0000798where \var{command} is one of the Distutils commands (e.g.
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000799\command{build\_py}, \command{install}), and \var{option} is one of
800the options that command supports. Any number of options can be
801supplied for each command, and any number of command sections can be
802included in the file. Blank lines are ignored, as are comments, which
803run from a \character{\#} character until the end of the line. Long
804option values can be split across multiple lines simply by indenting
805the continuation lines.
Greg Ward47f99a62000-09-04 20:07:15 +0000806
807You can find out the list of options supported by a particular command
808with the universal \longprogramopt{help} option, e.g.
Fred Drakea09262e2001-03-01 18:35:43 +0000809
Greg Ward47f99a62000-09-04 20:07:15 +0000810\begin{verbatim}
811> python setup.py --help build_ext
812[...]
813Options for 'build_ext' command:
814 --build-lib (-b) directory for compiled extension modules
815 --build-temp (-t) directory for temporary files (build by-products)
816 --inplace (-i) ignore build-lib and put compiled extensions into the
817 source directory alongside your pure Python modules
818 --include-dirs (-I) list of directories to search for header files
819 --define (-D) C preprocessor macros to define
820 --undef (-U) C preprocessor macros to undefine
821[...]
822\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000823
Greg Ward47f99a62000-09-04 20:07:15 +0000824Note that an option spelled \longprogramopt{foo-bar} on the command-line
825is spelled \option{foo\_bar} in configuration files.
826
827For example, say you want your extensions to be built
828``in-place''---that is, you have an extension \module{pkg.ext}, and you
Fred Drakeeff9a872000-10-26 16:41:03 +0000829want the compiled extension file (\file{ext.so} on \UNIX, say) to be put
Greg Ward47f99a62000-09-04 20:07:15 +0000830in the same source directory as your pure Python modules
831\module{pkg.mod1} and \module{pkg.mod2}. You can always use the
832\longprogramopt{inplace} option on the command-line to ensure this:
Fred Drakea09262e2001-03-01 18:35:43 +0000833
Greg Ward47f99a62000-09-04 20:07:15 +0000834\begin{verbatim}
835python setup.py build_ext --inplace
836\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000837
Greg Ward47f99a62000-09-04 20:07:15 +0000838But this requires that you always specify the \command{build\_ext}
839command explicitly, and remember to provide \longprogramopt{inplace}.
840An easier way is to ``set and forget'' this option, by encoding it in
841\file{setup.cfg}, the configuration file for this distribution:
Fred Drakea09262e2001-03-01 18:35:43 +0000842
Greg Ward47f99a62000-09-04 20:07:15 +0000843\begin{verbatim}
844[build_ext]
845inplace=1
846\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000847
Greg Ward47f99a62000-09-04 20:07:15 +0000848This will affect all builds of this module distribution, whether or not
849you explcitly specify \command{build\_ext}. If you include
850\file{setup.cfg} in your source distribution, it will also affect
851end-user builds---which is probably a bad idea for this option, since
852always building extensions in-place would break installation of the
853module distribution. In certain peculiar cases, though, modules are
854built right in their installation directory, so this is conceivably a
855useful ability. (Distributing extensions that expect to be built in
856their installation directory is almost always a bad idea, though.)
857
858Another example: certain commands take a lot of options that don't
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000859change from run to run; for example, \command{bdist\_rpm} needs to know
Greg Ward47f99a62000-09-04 20:07:15 +0000860everything required to generate a ``spec'' file for creating an RPM
861distribution. Some of this information comes from the setup script, and
862some is automatically generated by the Distutils (such as the list of
863files installed). But some of it has to be supplied as options to
864\command{bdist\_rpm}, which would be very tedious to do on the
865command-line for every run. Hence, here is a snippet from the
866Distutils' own \file{setup.cfg}:
Fred Drakea09262e2001-03-01 18:35:43 +0000867
Greg Ward47f99a62000-09-04 20:07:15 +0000868\begin{verbatim}
869[bdist_rpm]
870release = 1
871packager = Greg Ward <gward@python.net>
872doc_files = CHANGES.txt
873 README.txt
874 USAGE.txt
875 doc/
876 examples/
877\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000878
Greg Ward47f99a62000-09-04 20:07:15 +0000879Note that the \option{doc\_files} option is simply a
880whitespace-separated string split across multiple lines for readability.
Greg Ward16aafcd2000-04-09 04:06:44 +0000881
882
Fred Drakea09262e2001-03-01 18:35:43 +0000883\begin{seealso}
884 \seetitle[../inst/config-syntax.html]{Installing Python
885 Modules}{More information on the configuration files is
886 available in the manual for system administrators.}
887\end{seealso}
888
889
Greg Ward16aafcd2000-04-09 04:06:44 +0000890\section{Creating a Source Distribution}
Greg Warde78298a2000-04-28 17:12:24 +0000891\label{source-dist}
Greg Ward16aafcd2000-04-09 04:06:44 +0000892
Greg Warde78298a2000-04-28 17:12:24 +0000893As shown in section~\ref{simple-example}, you use the
Greg Ward16aafcd2000-04-09 04:06:44 +0000894\command{sdist} command to create a source distribution. In the
895simplest case,
Fred Drakea09262e2001-03-01 18:35:43 +0000896
Greg Ward16aafcd2000-04-09 04:06:44 +0000897\begin{verbatim}
898python setup.py sdist
899\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000900
Greg Ward19c67f82000-06-24 01:33:16 +0000901(assuming you haven't specified any \command{sdist} options in the setup
902script or config file), \command{sdist} creates the archive of the
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000903default format for the current platform. The default format is a gzip'ed
Fred Drakeeff9a872000-10-26 16:41:03 +0000904tar file (\file{.tar.gz}) on \UNIX, and ZIP file on Windows.
905\XXX{no MacOS support here}
Greg Ward54589d42000-09-06 01:37:35 +0000906
Greg Wardd5767a52000-04-19 22:48:09 +0000907You can specify as many formats as you like using the
908\longprogramopt{formats} option, for example:
Fred Drakea09262e2001-03-01 18:35:43 +0000909
Greg Ward16aafcd2000-04-09 04:06:44 +0000910\begin{verbatim}
911python setup.py sdist --formats=gztar,zip
912\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000913
Greg Ward16aafcd2000-04-09 04:06:44 +0000914to create a gzipped tarball and a zip file. The available formats are:
Greg Ward46b98e32000-04-14 01:53:36 +0000915\begin{tableiii}{l|l|c}{code}%
916 {Format}{Description}{Notes}
Greg Ward54589d42000-09-06 01:37:35 +0000917 \lineiii{zip}{zip file (\file{.zip})}{(1),(3)}
918 \lineiii{gztar}{gzip'ed tar file (\file{.tar.gz})}{(2),(4)}
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000919 \lineiii{bztar}{bzip2'ed tar file (\file{.tar.bz2})}{(4)}
Greg Ward47f99a62000-09-04 20:07:15 +0000920 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(4)}
Greg Ward54589d42000-09-06 01:37:35 +0000921 \lineiii{tar}{tar file (\file{.tar})}{(4)}
Greg Ward46b98e32000-04-14 01:53:36 +0000922\end{tableiii}
923
924\noindent Notes:
925\begin{description}
926\item[(1)] default on Windows
Fred Drakeeff9a872000-10-26 16:41:03 +0000927\item[(2)] default on \UNIX
Greg Wardb6528972000-09-07 02:40:37 +0000928\item[(3)] requires either external \program{zip} utility or
Greg Ward954ce8b2002-05-10 14:42:10 +0000929 \module{zipfile} module (part of the standard Python library since
930 Python~1.6)
Greg Ward47f99a62000-09-04 20:07:15 +0000931\item[(4)] requires external utilities: \program{tar} and possibly one
932 of \program{gzip}, \program{bzip2}, or \program{compress}
Greg Ward46b98e32000-04-14 01:53:36 +0000933\end{description}
Greg Ward16aafcd2000-04-09 04:06:44 +0000934
935
Greg Ward54589d42000-09-06 01:37:35 +0000936
937\subsection{Specifying the files to distribute}
Greg Warde78298a2000-04-28 17:12:24 +0000938\label{manifest}
Greg Ward16aafcd2000-04-09 04:06:44 +0000939
Greg Ward54589d42000-09-06 01:37:35 +0000940If you don't supply an explicit list of files (or instructions on how to
941generate one), the \command{sdist} command puts a minimal default set
942into the source distribution:
Greg Ward16aafcd2000-04-09 04:06:44 +0000943\begin{itemize}
Greg Wardfacb8db2000-04-09 04:32:40 +0000944\item all Python source files implied by the \option{py\_modules} and
Greg Ward16aafcd2000-04-09 04:06:44 +0000945 \option{packages} options
Greg Wardfacb8db2000-04-09 04:32:40 +0000946\item all C source files mentioned in the \option{ext\_modules} or
Greg Ward16aafcd2000-04-09 04:06:44 +0000947 \option{libraries} options (\XXX{getting C library sources currently
Greg Wardfacb8db2000-04-09 04:32:40 +0000948 broken -- no get\_source\_files() method in build\_clib.py!})
Greg Ward16aafcd2000-04-09 04:06:44 +0000949\item anything that looks like a test script: \file{test/test*.py}
950 (currently, the Distutils don't do anything with test scripts except
951 include them in source distributions, but in the future there will be
952 a standard for testing Python module distributions)
Greg Ward54589d42000-09-06 01:37:35 +0000953\item \file{README.txt} (or \file{README}), \file{setup.py} (or whatever
954 you called your setup script), and \file{setup.cfg}
Greg Ward16aafcd2000-04-09 04:06:44 +0000955\end{itemize}
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000956
Greg Ward16aafcd2000-04-09 04:06:44 +0000957Sometimes this is enough, but usually you will want to specify
958additional files to distribute. The typical way to do this is to write
959a \emph{manifest template}, called \file{MANIFEST.in} by default. The
Greg Ward54589d42000-09-06 01:37:35 +0000960manifest template is just a list of instructions for how to generate
961your manifest file, \file{MANIFEST}, which is the exact list of files to
962include in your source distribution. The \command{sdist} command
963processes this template and generates a manifest based on its
964instructions and what it finds in the filesystem.
965
966If you prefer to roll your own manifest file, the format is simple: one
967filename per line, regular files (or symlinks to them) only. If you do
968supply your own \file{MANIFEST}, you must specify everything: the
969default set of files described above does not apply in this case.
Greg Ward16aafcd2000-04-09 04:06:44 +0000970
971The manifest template has one command per line, where each command
972specifies a set of files to include or exclude from the source
973distribution. For an example, again we turn to the Distutils' own
974manifest template:
Fred Drakea09262e2001-03-01 18:35:43 +0000975
Greg Ward16aafcd2000-04-09 04:06:44 +0000976\begin{verbatim}
977include *.txt
Greg Ward87da1ea2000-04-21 04:35:25 +0000978recursive-include examples *.txt *.py
Greg Ward16aafcd2000-04-09 04:06:44 +0000979prune examples/sample?/build
980\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000981
Greg Ward16aafcd2000-04-09 04:06:44 +0000982The meanings should be fairly clear: include all files in the
983distribution root matching \code{*.txt}, all files anywhere under the
984\file{examples} directory matching \code{*.txt} or \code{*.py}, and
Greg Ward54589d42000-09-06 01:37:35 +0000985exclude all directories matching \code{examples/sample?/build}. All of
986this is done \emph{after} the standard include set, so you can exclude
987files from the standard set with explicit instructions in the manifest
988template. (Or, you can use the \longprogramopt{no-defaults} option to
989disable the standard set entirely.) There are several other commands
990available in the manifest template mini-language; see
991section~\ref{sdist-cmd}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000992
Greg Ward54589d42000-09-06 01:37:35 +0000993The order of commands in the manifest template matters: initially, we
994have the list of default files as described above, and each command in
995the template adds to or removes from that list of files. Once we have
996fully processed the manifest template, we remove files that should not
997be included in the source distribution:
998\begin{itemize}
999\item all files in the Distutils ``build'' tree (default \file{build/})
1000\item all files in directories named \file{RCS} or \file{CVS}
1001\end{itemize}
1002Now we have our complete list of files, which is written to the manifest
1003for future reference, and then used to build the source distribution
1004archive(s).
1005
1006You can disable the default set of included files with the
1007\longprogramopt{no-defaults} option, and you can disable the standard
1008exclude set with \longprogramopt{no-prune}.
Greg Ward16aafcd2000-04-09 04:06:44 +00001009
Greg Ward46b98e32000-04-14 01:53:36 +00001010Following the Distutils' own manifest template, let's trace how the
Greg Ward47f99a62000-09-04 20:07:15 +00001011\command{sdist} command builds the list of files to include in the
Greg Ward46b98e32000-04-14 01:53:36 +00001012Distutils source distribution:
Greg Ward16aafcd2000-04-09 04:06:44 +00001013\begin{enumerate}
1014\item include all Python source files in the \file{distutils} and
1015 \file{distutils/command} subdirectories (because packages
1016 corresponding to those two directories were mentioned in the
Greg Ward54589d42000-09-06 01:37:35 +00001017 \option{packages} option in the setup script---see
1018 section~\ref{setup-script})
1019\item include \file{README.txt}, \file{setup.py}, and \file{setup.cfg}
1020 (standard files)
1021\item include \file{test/test*.py} (standard files)
Greg Ward16aafcd2000-04-09 04:06:44 +00001022\item include \file{*.txt} in the distribution root (this will find
1023 \file{README.txt} a second time, but such redundancies are weeded out
1024 later)
Greg Ward54589d42000-09-06 01:37:35 +00001025\item include anything matching \file{*.txt} or \file{*.py} in the
1026 sub-tree under \file{examples},
1027\item exclude all files in the sub-trees starting at directories
1028 matching \file{examples/sample?/build}---this may exclude files
1029 included by the previous two steps, so it's important that the
1030 \code{prune} command in the manifest template comes after the
1031 \code{recursive-include} command
1032\item exclude the entire \file{build} tree, and any \file{RCS} or
1033 \file{CVS} directories
Greg Wardfacb8db2000-04-09 04:32:40 +00001034\end{enumerate}
Greg Ward46b98e32000-04-14 01:53:36 +00001035Just like in the setup script, file and directory names in the manifest
1036template should always be slash-separated; the Distutils will take care
1037of converting them to the standard representation on your platform.
1038That way, the manifest template is portable across operating systems.
1039
Greg Ward16aafcd2000-04-09 04:06:44 +00001040
1041\subsection{Manifest-related options}
Greg Warde78298a2000-04-28 17:12:24 +00001042\label{manifest-options}
Greg Ward16aafcd2000-04-09 04:06:44 +00001043
1044The normal course of operations for the \command{sdist} command is as
1045follows:
1046\begin{itemize}
Greg Ward46b98e32000-04-14 01:53:36 +00001047\item if the manifest file, \file{MANIFEST} doesn't exist, read
1048 \file{MANIFEST.in} and create the manifest
Greg Ward54589d42000-09-06 01:37:35 +00001049\item if neither \file{MANIFEST} nor \file{MANIFEST.in} exist, create a
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001050 manifest with just the default file set
Greg Ward1d8f57a2000-08-05 00:43:11 +00001051\item if either \file{MANIFEST.in} or the setup script (\file{setup.py})
1052 are more recent than \file{MANIFEST}, recreate \file{MANIFEST} by
1053 reading \file{MANIFEST.in}
Greg Ward16aafcd2000-04-09 04:06:44 +00001054\item use the list of files now in \file{MANIFEST} (either just
1055 generated or read in) to create the source distribution archive(s)
1056\end{itemize}
Greg Ward54589d42000-09-06 01:37:35 +00001057There are a couple of options that modify this behaviour. First, use
1058the \longprogramopt{no-defaults} and \longprogramopt{no-prune} to
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001059disable the standard ``include'' and ``exclude'' sets.
Greg Ward16aafcd2000-04-09 04:06:44 +00001060
Greg Ward54589d42000-09-06 01:37:35 +00001061Second, you might want to force the manifest to be regenerated---for
Greg Ward16aafcd2000-04-09 04:06:44 +00001062example, if you have added or removed files or directories that match an
1063existing pattern in the manifest template, you should regenerate the
1064manifest:
Fred Drakea09262e2001-03-01 18:35:43 +00001065
Greg Ward16aafcd2000-04-09 04:06:44 +00001066\begin{verbatim}
1067python setup.py sdist --force-manifest
1068\end{verbatim}
Greg Ward16aafcd2000-04-09 04:06:44 +00001069
1070Or, you might just want to (re)generate the manifest, but not create a
1071source distribution:
Fred Drakea09262e2001-03-01 18:35:43 +00001072
Greg Ward16aafcd2000-04-09 04:06:44 +00001073\begin{verbatim}
1074python setup.py sdist --manifest-only
1075\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001076
Greg Ward54589d42000-09-06 01:37:35 +00001077\longprogramopt{manifest-only} implies \longprogramopt{force-manifest}.
1078\programopt{-o} is a shortcut for \longprogramopt{manifest-only}, and
1079\programopt{-f} for \longprogramopt{force-manifest}.
Greg Ward16aafcd2000-04-09 04:06:44 +00001080
1081
1082\section{Creating Built Distributions}
Greg Warde78298a2000-04-28 17:12:24 +00001083\label{built-dist}
Greg Ward16aafcd2000-04-09 04:06:44 +00001084
Greg Ward46b98e32000-04-14 01:53:36 +00001085A ``built distribution'' is what you're probably used to thinking of
1086either as a ``binary package'' or an ``installer'' (depending on your
1087background). It's not necessarily binary, though, because it might
1088contain only Python source code and/or byte-code; and we don't call it a
1089package, because that word is already spoken for in Python. (And
1090``installer'' is a term specific to the Windows world. \XXX{do Mac
1091 people use it?})
Greg Ward16aafcd2000-04-09 04:06:44 +00001092
Greg Ward46b98e32000-04-14 01:53:36 +00001093A built distribution is how you make life as easy as possible for
1094installers of your module distribution: for users of RPM-based Linux
1095systems, it's a binary RPM; for Windows users, it's an executable
1096installer; for Debian-based Linux users, it's a Debian package; and so
1097forth. Obviously, no one person will be able to create built
Greg Wardb6528972000-09-07 02:40:37 +00001098distributions for every platform under the sun, so the Distutils are
Greg Ward46b98e32000-04-14 01:53:36 +00001099designed to enable module developers to concentrate on their
1100specialty---writing code and creating source distributions---while an
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001101intermediary species called \emph{packagers} springs up to turn source
Greg Ward19c67f82000-06-24 01:33:16 +00001102distributions into built distributions for as many platforms as there
Greg Ward46b98e32000-04-14 01:53:36 +00001103are packagers.
1104
1105Of course, the module developer could be his own packager; or the
1106packager could be a volunteer ``out there'' somewhere who has access to
1107a platform which the original developer does not; or it could be
1108software periodically grabbing new source distributions and turning them
1109into built distributions for as many platforms as the software has
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001110access to. Regardless of who they are, a packager uses the
Greg Ward46b98e32000-04-14 01:53:36 +00001111setup script and the \command{bdist} command family to generate built
1112distributions.
1113
1114As a simple example, if I run the following command in the Distutils
1115source tree:
Fred Drakea09262e2001-03-01 18:35:43 +00001116
Greg Ward46b98e32000-04-14 01:53:36 +00001117\begin{verbatim}
1118python setup.py bdist
1119\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001120
Greg Ward46b98e32000-04-14 01:53:36 +00001121then the Distutils builds my module distribution (the Distutils itself
1122in this case), does a ``fake'' installation (also in the \file{build}
1123directory), and creates the default type of built distribution for my
Greg Wardb6528972000-09-07 02:40:37 +00001124platform. The default format for built distributions is a ``dumb'' tar
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001125file on \UNIX, and a simple executable installer on Windows. (That tar
Greg Wardb6528972000-09-07 02:40:37 +00001126file is considered ``dumb'' because it has to be unpacked in a specific
1127location to work.)
Greg Ward1d8f57a2000-08-05 00:43:11 +00001128
Fred Drakeeff9a872000-10-26 16:41:03 +00001129Thus, the above command on a \UNIX{} system creates
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001130\file{Distutils-1.0.\filevar{plat}.tar.gz}; unpacking this tarball
Greg Wardb6528972000-09-07 02:40:37 +00001131from the right place installs the Distutils just as though you had
1132downloaded the source distribution and run \code{python setup.py
1133 install}. (The ``right place'' is either the root of the filesystem or
1134Python's \filevar{prefix} directory, depending on the options given to
1135the \command{bdist\_dumb} command; the default is to make dumb
1136distributions relative to \filevar{prefix}.)
Greg Ward46b98e32000-04-14 01:53:36 +00001137
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001138Obviously, for pure Python distributions, this isn't any simpler than
1139just running \code{python setup.py install}---but for non-pure
1140distributions, which include extensions that would need to be
1141compiled, it can mean the difference between someone being able to use
1142your extensions or not. And creating ``smart'' built distributions,
1143such as an RPM package or an executable installer for Windows, is far
1144more convenient for users even if your distribution doesn't include
1145any extensions.
Greg Ward46b98e32000-04-14 01:53:36 +00001146
Greg Wardb6528972000-09-07 02:40:37 +00001147The \command{bdist} command has a \longprogramopt{formats} option,
Greg Ward1d8f57a2000-08-05 00:43:11 +00001148similar to the \command{sdist} command, which you can use to select the
1149types of built distribution to generate: for example,
Fred Drakea09262e2001-03-01 18:35:43 +00001150
Greg Ward46b98e32000-04-14 01:53:36 +00001151\begin{verbatim}
1152python setup.py bdist --format=zip
1153\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001154
Fred Drakeeff9a872000-10-26 16:41:03 +00001155would, when run on a \UNIX{} system, create
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001156\file{Distutils-1.0.\filevar{plat}.zip}---again, this archive would be
Greg Ward1d8f57a2000-08-05 00:43:11 +00001157unpacked from the root directory to install the Distutils.
Greg Ward46b98e32000-04-14 01:53:36 +00001158
1159The available formats for built distributions are:
1160\begin{tableiii}{l|l|c}{code}%
1161 {Format}{Description}{Notes}
Greg Wardb6528972000-09-07 02:40:37 +00001162 \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1),(3)}
1163 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(3)}
1164 \lineiii{tar}{tar file (\file{.tar})}{(3)}
1165 \lineiii{zip}{zip file (\file{.zip})}{(4)}
1166 \lineiii{rpm}{RPM}{(5)}
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001167 \lineiii{pkgtool}{Solaris \program{pkgtool}}{}
1168 \lineiii{sdux}{HP-UX \program{swinstall}}{}
1169 \lineiii{rpm}{RPM}{(5)}
1170% \lineiii{srpm}{source RPM}{(5) \XXX{to do!}}
Thomas Heller5f52f722001-02-19 17:48:03 +00001171 \lineiii{wininst}{self-extracting ZIP file for Windows}{(2),(4)}
Greg Ward46b98e32000-04-14 01:53:36 +00001172\end{tableiii}
1173
1174\noindent Notes:
1175\begin{description}
Fred Drakeeff9a872000-10-26 16:41:03 +00001176\item[(1)] default on \UNIX
Greg Ward1d8f57a2000-08-05 00:43:11 +00001177\item[(2)] default on Windows \XXX{to-do!}
Greg Wardb6528972000-09-07 02:40:37 +00001178\item[(3)] requires external utilities: \program{tar} and possibly one
1179 of \program{gzip}, \program{bzip2}, or \program{compress}
1180\item[(4)] requires either external \program{zip} utility or
Greg Ward954ce8b2002-05-10 14:42:10 +00001181 \module{zipfile} module (part of the standard Python library since
1182 Python~1.6)
Greg Wardb6528972000-09-07 02:40:37 +00001183\item[(5)] requires external \program{rpm} utility, version 3.0.4 or
1184 better (use \code{rpm --version} to find out which version you have)
Greg Ward46b98e32000-04-14 01:53:36 +00001185\end{description}
1186
1187You don't have to use the \command{bdist} command with the
Greg Wardd5767a52000-04-19 22:48:09 +00001188\longprogramopt{formats} option; you can also use the command that
Greg Ward1d8f57a2000-08-05 00:43:11 +00001189directly implements the format you're interested in. Some of these
Greg Ward46b98e32000-04-14 01:53:36 +00001190\command{bdist} ``sub-commands'' actually generate several similar
1191formats; for instance, the \command{bdist\_dumb} command generates all
1192the ``dumb'' archive formats (\code{tar}, \code{ztar}, \code{gztar}, and
1193\code{zip}), and \command{bdist\_rpm} generates both binary and source
1194RPMs. The \command{bdist} sub-commands, and the formats generated by
1195each, are:
1196\begin{tableii}{l|l}{command}%
1197 {Command}{Formats}
1198 \lineii{bdist\_dumb}{tar, ztar, gztar, zip}
1199 \lineii{bdist\_rpm}{rpm, srpm}
Greg Ward1d8f57a2000-08-05 00:43:11 +00001200 \lineii{bdist\_wininst}{wininst}
Greg Ward46b98e32000-04-14 01:53:36 +00001201\end{tableii}
Greg Ward16aafcd2000-04-09 04:06:44 +00001202
Greg Wardb6528972000-09-07 02:40:37 +00001203The following sections give details on the individual \command{bdist\_*}
1204commands.
1205
1206
1207\subsection{Creating dumb built distributions}
1208\label{creating-dumb}
1209
1210\XXX{Need to document absolute vs. prefix-relative packages here, but
1211 first I have to implement it!}
1212
1213
1214\subsection{Creating RPM packages}
1215\label{creating-rpms}
1216
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001217The RPM format is used by many popular Linux distributions, including
Greg Wardb6528972000-09-07 02:40:37 +00001218Red Hat, SuSE, and Mandrake. If one of these (or any of the other
1219RPM-based Linux distributions) is your usual environment, creating RPM
1220packages for other users of that same distribution is trivial.
1221Depending on the complexity of your module distribution and differences
1222between Linux distributions, you may also be able to create RPMs that
1223work on different RPM-based distributions.
1224
1225The usual way to create an RPM of your module distribution is to run the
1226\command{bdist\_rpm} command:
Fred Drakea09262e2001-03-01 18:35:43 +00001227
Greg Wardb6528972000-09-07 02:40:37 +00001228\begin{verbatim}
1229python setup.py bdist_rpm
1230\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001231
Greg Wardb6528972000-09-07 02:40:37 +00001232or the \command{bdist} command with the \longprogramopt{format} option:
Fred Drakea09262e2001-03-01 18:35:43 +00001233
Greg Wardb6528972000-09-07 02:40:37 +00001234\begin{verbatim}
1235python setup.py bdist --formats=rpm
1236\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001237
Greg Wardb6528972000-09-07 02:40:37 +00001238The former allows you to specify RPM-specific options; the latter allows
1239you to easily specify multiple formats in one run. If you need to do
1240both, you can explicitly specify multiple \command{bdist\_*} commands
1241and their options:
Fred Drakea09262e2001-03-01 18:35:43 +00001242
Greg Wardb6528972000-09-07 02:40:37 +00001243\begin{verbatim}
1244python setup.py bdist_rpm --packager="John Doe <jdoe@python.net>" \
1245 bdist_wininst --target_version="2.0"
1246\end{verbatim}
1247
1248Creating RPM packages is driven by a \file{.spec} file, much as using
1249the Distutils is driven by the setup script. To make your life easier,
1250the \command{bdist\_rpm} command normally creates a \file{.spec} file
1251based on the information you supply in the setup script, on the command
1252line, and in any Distutils configuration files. Various options and
Andrew M. Kuchlingda23c4f2001-02-17 00:38:48 +00001253sections in the \file{.spec} file are derived from options in the setup
Greg Wardb6528972000-09-07 02:40:37 +00001254script as follows:
1255\begin{tableii}{l|l}{textrm}%
1256 {RPM \file{.spec} file option or section}{Distutils setup script option}
1257 \lineii{Name}{\option{name}}
1258 \lineii{Summary (in preamble)}{\option{description}}
1259 \lineii{Version}{\option{version}}
1260 \lineii{Vendor}{\option{author} and \option{author\_email}, or \\&
1261 \option{maintainer} and \option{maintainer\_email}}
1262 \lineii{Copyright}{\option{licence}}
1263 \lineii{Url}{\option{url}}
1264 \lineii{\%description (section)}{\option{long\_description}}
1265\end{tableii}
1266
1267Additionally, there many options in \file{.spec} files that don't have
1268corresponding options in the setup script. Most of these are handled
1269through options to the \command{bdist\_rpm} command as follows:
1270\begin{tableiii}{l|l|l}{textrm}%
1271 {RPM \file{.spec} file option or section}%
1272 {\command{bdist\_rpm} option}%
1273 {default value}
1274 \lineiii{Release}{\option{release}}{``1''}
1275 \lineiii{Group}{\option{group}}{``Development/Libraries''}
1276 \lineiii{Vendor}{\option{vendor}}{(see above)}
Andrew M. Kuchlingda23c4f2001-02-17 00:38:48 +00001277 \lineiii{Packager}{\option{packager}}{(none)}
1278 \lineiii{Provides}{\option{provides}}{(none)}
1279 \lineiii{Requires}{\option{requires}}{(none)}
1280 \lineiii{Conflicts}{\option{conflicts}}{(none)}
1281 \lineiii{Obsoletes}{\option{obsoletes}}{(none)}
Greg Wardb6528972000-09-07 02:40:37 +00001282 \lineiii{Distribution}{\option{distribution\_name}}{(none)}
1283 \lineiii{BuildRequires}{\option{build\_requires}}{(none)}
1284 \lineiii{Icon}{\option{icon}}{(none)}
1285\end{tableiii}
1286Obviously, supplying even a few of these options on the command-line
1287would be tedious and error-prone, so it's usually best to put them in
1288the setup configuration file, \file{setup.cfg}---see
1289section~\ref{setup-config}. If you distribute or package many Python
1290module distributions, you might want to put options that apply to all of
1291them in your personal Distutils configuration file
1292(\file{\textasciitilde/.pydistutils.cfg}).
1293
1294There are three steps to building a binary RPM package, all of which are
1295handled automatically by the Distutils:
1296\begin{enumerate}
1297\item create a \file{.spec} file, which describes the package (analogous
1298 to the Distutils setup script; in fact, much of the information in the
1299 setup script winds up in the \file{.spec} file)
1300\item create the source RPM
1301\item create the ``binary'' RPM (which may or may not contain binary
1302 code, depending on whether your module distribution contains Python
1303 extensions)
1304\end{enumerate}
1305Normally, RPM bundles the last two steps together; when you use the
1306Distutils, all three steps are typically bundled together.
1307
1308If you wish, you can separate these three steps. You can use the
1309\longprogramopt{spec-only} option to make \command{bdist\_rpm} just
1310create the \file{.spec} file and exit; in this case, the \file{.spec}
1311file will be written to the ``distribution directory''---normally
1312\file{dist/}, but customizable with the \longprogramopt{dist-dir}
1313option. (Normally, the \file{.spec} file winds up deep in the ``build
1314tree,'' in a temporary directory created by \command{bdist\_rpm}.)
1315
1316\XXX{this isn't implemented yet---is it needed?!}
1317You can also specify a custom \file{.spec} file with the
Thomas Heller5f52f722001-02-19 17:48:03 +00001318\longprogramopt{spec-file} option; used in conjunction with
Greg Wardb6528972000-09-07 02:40:37 +00001319\longprogramopt{spec-only}, this gives you an opportunity to customize
1320the \file{.spec} file manually:
Fred Drakea09262e2001-03-01 18:35:43 +00001321
Greg Wardb6528972000-09-07 02:40:37 +00001322\begin{verbatim}
1323> python setup.py bdist_rpm --spec-only
1324# ...edit dist/FooBar-1.0.spec
1325> python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec
1326\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001327
Greg Wardb6528972000-09-07 02:40:37 +00001328(Although a better way to do this is probably to override the standard
1329\command{bdist\_rpm} command with one that writes whatever else you want
1330to the \file{.spec} file; see section~\ref{extending} for information on
1331extending the Distutils.)
1332
1333
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001334\subsection{Creating Windows Installers}
Greg Wardb6528972000-09-07 02:40:37 +00001335\label{creating-wininst}
1336
Thomas Hellere61f3652002-11-15 20:13:26 +00001337Executable installers are the natural format for binary distributions
1338on Windows. They display a nice graphical user interface, display
1339some information about the module distribution to be installed taken
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +00001340from the metadata in the setup script, let the user select a few
Thomas Hellere61f3652002-11-15 20:13:26 +00001341options, and start or cancel the installation.
Greg Wardb6528972000-09-07 02:40:37 +00001342
Thomas Hellere61f3652002-11-15 20:13:26 +00001343Since the metadata is taken from the setup script, creating Windows
1344installers is usually as easy as running:
Fred Drakea09262e2001-03-01 18:35:43 +00001345
Thomas Heller5f52f722001-02-19 17:48:03 +00001346\begin{verbatim}
1347python setup.py bdist_wininst
1348\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001349
Thomas Heller36343f62002-11-15 19:20:56 +00001350or the \command{bdist} command with the \longprogramopt{formats} option:
Fred Drakea09262e2001-03-01 18:35:43 +00001351
Thomas Heller5f52f722001-02-19 17:48:03 +00001352\begin{verbatim}
1353python setup.py bdist --formats=wininst
1354\end{verbatim}
1355
Thomas Hellere61f3652002-11-15 20:13:26 +00001356If you have a pure module distribution (only containing pure Python
1357modules and packages), the resulting installer will be version
1358independent and have a name like \file{foo-1.0.win32.exe}. These
1359installers can even be created on \UNIX{} or MacOS platforms.
Thomas Heller5f52f722001-02-19 17:48:03 +00001360
1361If you have a non-pure distribution, the extensions can only be
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001362created on a Windows platform, and will be Python version dependent.
Thomas Heller5f52f722001-02-19 17:48:03 +00001363The installer filename will reflect this and now has the form
Thomas Hellere61f3652002-11-15 20:13:26 +00001364\file{foo-1.0.win32-py2.0.exe}. You have to create a separate installer
Thomas Heller5f52f722001-02-19 17:48:03 +00001365for every Python version you want to support.
1366
1367The installer will try to compile pure modules into bytecode after
Thomas Hellere61f3652002-11-15 20:13:26 +00001368installation on the target system in normal and optimizing mode. If
1369you don't want this to happen for some reason, you can run the
Fred Drake0e9bfa32002-11-15 20:34:52 +00001370\command{bdist_wininst} command with the
1371\longprogramopt{no-target-compile} and/or the
1372\longprogramopt{no-target-optimize} option.
Thomas Hellere61f3652002-11-15 20:13:26 +00001373
Fred Drake0e9bfa32002-11-15 20:34:52 +00001374By default the installer will display the cool ``Python Powered'' logo
Thomas Hellere61f3652002-11-15 20:13:26 +00001375when it is run, but you can also supply your own bitmap which must be
Fred Drake0e9bfa32002-11-15 20:34:52 +00001376a Windows \file{.bmp} file with the \longprogramopt{bitmap} option.
Thomas Hellere61f3652002-11-15 20:13:26 +00001377
1378The installer will also display a large title on the desktop
1379background window when it is run, which is constructed from the name
1380of your distribution and the version number. This can be changed to
1381another text by using the \longprogramopt{title} option.
1382
1383The installer file will be written to the ``distribution directory''
1384--- normally \file{dist/}, but customizable with the
1385\longprogramopt{dist-dir} option.
1386
Thomas Heller2c3bfc22002-12-12 18:54:19 +00001387\subsubsection{The Postinstallation script}
1388\label{postinstallation-script}
1389
1390Starting with Python 2.3, a postinstallation script can be specified
1391which the \longprogramopt{install-script} option. The basename of the
1392script must be specified, and the script filename must also be listed
1393in the scripts argument to the setup function.
1394
1395This script will be run at installation time on the target system
1396after all the files have been copied, with argv[1] set to '-install',
1397and again at uninstallation time before the files are removed with argv[1]
1398set to '-remove'.
1399
1400The installation script runs embedded in the windows installer, every
1401output (sys.stdout, sys.stderr) is redirected into a buffer and will
1402be displayed in the GUI after the script has finished.
1403
1404Some functions especially useful in this context are available in the
1405installation script.
1406
1407\begin{verbatim}
1408dir_created(pathname)
1409file_created(pathname)
1410\end{verbatim}
1411
1412These functions should be called when a directory or file is created
1413by the postinstall script at installation time. It will register the
1414pathname with the uninstaller, so that it will be removed when the
1415distribution is uninstalled. To be safe, directories are only removed
1416if they are empty.
1417
1418\begin{verbatim}
1419get_special_folder_path(csidl_string)
1420\end{verbatim}
1421
1422This function can be used to retrieve special folder locations on
1423Windows like the Start Menu or the Desktop. It returns the full path
1424to the folder. 'csidl_string' must be on of the following strings:
1425
1426\begin{verbatim}
1427"CSIDL_APPDATA"
1428
1429"CSIDL_COMMON_STARTMENU"
1430"CSIDL_STARTMENU"
1431
1432"CSIDL_COMMON_DESKTOPDIRECTORY"
1433"CSIDL_DESKTOPDIRECTORY"
1434
1435"CSIDL_COMMON_STARTUP"
1436"CSIDL_STARTUP"
1437
1438"CSIDL_COMMON_PROGRAMS"
1439"CSIDL_PROGRAMS"
1440
1441"CSIDL_FONTS"
1442\end{verbatim}
1443
1444If the folder cannot be retrieved, OSError is raised.
1445
1446Which folders are available depends on the exact Windows version, and probably
1447also the configuration. For details refer to Microsoft's documentation of the
Thomas Heller63b4dd32002-12-12 19:35:00 +00001448\code{SHGetSpecialFolderPath} function.
Thomas Heller2c3bfc22002-12-12 18:54:19 +00001449
1450\begin{verbatim}
1451create_shortcut(target, description, filename[, arguments[,
1452 workdir[, iconpath[, iconindex]]]])
1453\end{verbatim}
1454
1455This function creates a shortcut.
Thomas Heller63b4dd32002-12-12 19:35:00 +00001456\var{target} is the path to the program to be started by the shortcut.
1457\var{description} is the description of the sortcut.
1458\var{filename} is the title of the shortcut that the user will see.
1459\var{arguments} specifies the command line arguments, if any.
1460\var{workdir} is the working directory for the program.
1461\var{iconpath} is the file containing the icon for the shortcut,
1462and \var{iconindex} is the index of the icon in the file
1463\var{iconpath}. Again, for details consult the Microsoft
1464documentation for the \code{IShellLink} interface.
Greg Wardb6528972000-09-07 02:40:37 +00001465
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +00001466\section{Registering with the Package Index}
1467\label{package-index}
1468
1469The Python Package Index (PyPI) holds meta-data describing distributions
1470packaged with distutils. The distutils command \command{register} is
1471used to submit your distribution's meta-data to the index. It is invoked
1472as follows:
1473
1474\begin{verbatim}
1475python setup.py register
1476\end{verbatim}
1477
1478Distutils will respond with the following prompt:
1479
1480\begin{verbatim}
1481running register
1482We need to know who you are, so please choose either:
1483 1. use your existing login,
1484 2. register as a new user,
1485 3. have the server generate a new password for you (and email it to you), or
1486 4. quit
1487Your selection [default 1]:
1488\end{verbatim}
1489
1490\noindent Note: if your username and password are saved locally, you will
1491not see this menu.
1492
1493If you have not registered with PyPI, then you will need to do so now. You
1494should choose option 2, and enter your details as required. Soon after
1495submitting your details, you will receive an email which will be used to
1496confirm your registration.
1497
1498Once you are registered, you may choose option 1 from the menu. You will
1499be prompted for your PyPI username and password, and \command{register}
1500will then submit your meta-data to the index.
1501
1502You may submit any number of versions of your distribution to the index. If
1503you alter the meta-data for a particular version, you may submit it again
1504and the index will be updated.
1505
1506PyPI holds a record for each (name, version) combination submitted. The
1507first user to submit information for a given name is designated the Owner
1508of that name. They may submit changes through the \command{register}
1509command or through the web interface. They may also designate other users
1510as Owners or Maintainers. Maintainers may edit the package information, but
1511not designate other Owners or Maintainers.
1512
1513By default PyPI will list all versions of a given package. To hide certain
1514versions, the Hidden property should be set to yes. This must be edited
1515through the web interface.
1516
1517
1518
Greg Ward007c04a2002-05-10 14:45:59 +00001519\section{Examples}
1520\label{examples}
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +00001521
Greg Ward007c04a2002-05-10 14:45:59 +00001522\subsection{Pure Python distribution (by module)}
1523\label{pure-mod}
1524
1525If you're just distributing a couple of modules, especially if they
1526don't live in a particular package, you can specify them individually
1527using the \option{py\_modules} option in the setup script.
1528
1529In the simplest case, you'll have two files to worry about: a setup
1530script and the single module you're distributing, \file{foo.py} in this
1531example:
1532\begin{verbatim}
1533<root>/
1534 setup.py
1535 foo.py
1536\end{verbatim}
1537(In all diagrams in this section, \verb|<root>| will refer to the
1538distribution root directory.) A minimal setup script to describe this
1539situation would be:
1540\begin{verbatim}
1541from distutils.core import setup
1542setup(name = "foo", version = "1.0",
1543 py_modules = ["foo"])
1544\end{verbatim}
1545Note that the name of the distribution is specified independently with
1546the \option{name} option, and there's no rule that says it has to be the
1547same as the name of the sole module in the distribution (although that's
1548probably a good convention to follow). However, the distribution name
1549is used to generate filenames, so you should stick to letters, digits,
1550underscores, and hyphens.
1551
1552Since \option{py\_modules} is a list, you can of course specify multiple
1553modules, eg. if you're distributing modules \module{foo} and
1554\module{bar}, your setup might look like this:
1555\begin{verbatim}
1556<root>/
1557 setup.py
1558 foo.py
1559 bar.py
1560\end{verbatim}
1561and the setup script might be
1562\begin{verbatim}
1563from distutils.core import setup
1564setup(name = "foobar", version = "1.0",
1565 py_modules = ["foo", "bar"])
1566\end{verbatim}
1567
1568You can put module source files into another directory, but if you have
1569enough modules to do that, it's probably easier to specify modules by
1570package rather than listing them individually.
Greg Ward16aafcd2000-04-09 04:06:44 +00001571
1572
Greg Ward007c04a2002-05-10 14:45:59 +00001573\subsection{Pure Python distribution (by package)}
1574\label{pure-pkg}
1575
1576If you have more than a couple of modules to distribute, especially if
1577they are in multiple packages, it's probably easier to specify whole
1578packages rather than individual modules. This works even if your
1579modules are not in a package; you can just tell the Distutils to process
1580modules from the root package, and that works the same as any other
1581package (except that you don't have to have an \file{\_\_init\_\_.py}
1582file).
1583
1584The setup script from the last example could also be written as
1585\begin{verbatim}
1586from distutils.core import setup
1587setup(name = "foobar", version = "1.0",
1588 packages = [""])
1589\end{verbatim}
1590(The empty string stands for the root package.)
1591
1592If those two files are moved into a subdirectory, but remain in the root
1593package, e.g.:
1594\begin{verbatim}
1595<root>/
1596 setup.py
1597 src/ foo.py
1598 bar.py
1599\end{verbatim}
1600then you would still specify the root package, but you have to tell the
1601Distutils where source files in the root package live:
1602\begin{verbatim}
1603from distutils.core import setup
1604setup(name = "foobar", version = "1.0",
1605 package_dir = {"": "src"},
1606 packages = [""])
1607\end{verbatim}
1608
1609More typically, though, you will want to distribute multiple modules in
1610the same package (or in sub-packages). For example, if the \module{foo}
1611and \module{bar} modules belong in package \module{foobar}, one way to
1612layout your source tree is
1613\begin{verbatim}
1614<root>/
1615 setup.py
1616 foobar/
1617 __init__.py
1618 foo.py
1619 bar.py
1620\end{verbatim}
1621This is in fact the default layout expected by the Distutils, and the
1622one that requires the least work to describe in your setup script:
1623\begin{verbatim}
1624from distutils.core import setup
1625setup(name = "foobar", version = "1.0",
1626 packages = ["foobar"])
1627\end{verbatim}
1628
1629If you want to put modules in directories not named for their package,
1630then you need to use the \option{package\_dir} option again. For
1631example, if the \file{src} directory holds modules in the
1632\module{foobar} package:
1633\begin{verbatim}
1634<root>/
1635 setup.py
1636 src/
1637 __init__.py
1638 foo.py
1639 bar.py
1640\end{verbatim}
1641an appropriate setup script would be
1642\begin{verbatim}
1643from distutils.core import setup
1644setup(name = "foobar", version = "1.0",
1645 package_dir = {"foobar" : "src"},
1646 packages = ["foobar"])
1647\end{verbatim}
1648
1649Or, you might put modules from your main package right in the
1650distribution root:
1651\begin{verbatim}
1652<root>/
1653 setup.py
1654 __init__.py
1655 foo.py
1656 bar.py
1657\end{verbatim}
1658in which case your setup script would be
1659\begin{verbatim}
1660from distutils.core import setup
1661setup(name = "foobar", version = "1.0",
1662 package_dir = {"foobar" : ""},
1663 packages = ["foobar"])
1664\end{verbatim}
1665(The empty string also stands for the current directory.)
1666
1667If you have sub-packages, they must be explicitly listed in
1668\option{packages}, but any entries in \option{package\_dir}
1669automatically extend to sub-packages. (In other words, the Distutils
1670does \emph{not} scan your source tree, trying to figure out which
1671directories correspond to Python packages by looking for
1672\file{\_\_init\_\_.py} files.) Thus, if the default layout grows a
1673sub-package:
1674\begin{verbatim}
1675<root>/
1676 setup.py
1677 foobar/
1678 __init__.py
1679 foo.py
1680 bar.py
1681 subfoo/
1682 __init__.py
1683 blah.py
1684\end{verbatim}
1685then the corresponding setup script would be
1686\begin{verbatim}
1687from distutils.core import setup
1688setup(name = "foobar", version = "1.0",
1689 packages = ["foobar", "foobar.subfoo"])
1690\end{verbatim}
1691(Again, the empty string in \option{package\_dir} stands for the current
1692directory.)
Greg Ward16aafcd2000-04-09 04:06:44 +00001693
1694
Greg Ward007c04a2002-05-10 14:45:59 +00001695\subsection{Single extension module}
1696\label{single-ext}
1697
1698Extension modules are specified using the \option{ext\_modules} option.
1699\option{package\_dir} has no effect on where extension source files are
1700found; it only affects the source for pure Python modules. The simplest
1701case, a single extension module in a single C source file, is:
1702\begin{verbatim}
1703<root>/
1704 setup.py
1705 foo.c
1706\end{verbatim}
1707If the \module{foo} extension belongs in the root package, the setup
1708script for this could be
1709\begin{verbatim}
1710from distutils.core import setup
1711setup(name = "foobar", version = "1.0",
1712 ext_modules = [Extension("foo", ["foo.c"])])
1713\end{verbatim}
1714
1715If the extension actually belongs in a package, say \module{foopkg},
1716then
1717
1718With exactly the same source tree layout, this extension can be put in
1719the \module{foopkg} package simply by changing the name of the
1720extension:
1721\begin{verbatim}
1722from distutils.core import setup
1723setup(name = "foobar", version = "1.0",
1724 ext_modules = [Extension("foopkg.foo", ["foo.c"])])
1725\end{verbatim}
Greg Ward16aafcd2000-04-09 04:06:44 +00001726
1727
Fred Drakea09262e2001-03-01 18:35:43 +00001728%\subsection{Multiple extension modules}
1729%\label{multiple-ext}
Greg Ward16aafcd2000-04-09 04:06:44 +00001730
1731
Fred Drakea09262e2001-03-01 18:35:43 +00001732%\subsection{Putting it all together}
Greg Ward16aafcd2000-04-09 04:06:44 +00001733
1734
Fred Drakea09262e2001-03-01 18:35:43 +00001735%\section{Extending the Distutils}
1736%\label{extending}
Greg Ward4a9e7222000-04-25 02:57:36 +00001737
1738
Fred Drakea09262e2001-03-01 18:35:43 +00001739%\subsection{Extending existing commands}
1740%\label{extend-existing}
Greg Ward4a9e7222000-04-25 02:57:36 +00001741
1742
Fred Drakea09262e2001-03-01 18:35:43 +00001743%\subsection{Writing new commands}
1744%\label{new-commands}
Greg Ward4a9e7222000-04-25 02:57:36 +00001745
Fred Drakea09262e2001-03-01 18:35:43 +00001746%\XXX{Would an uninstall command be a good example here?}
Thomas Heller5f52f722001-02-19 17:48:03 +00001747
Greg Ward4a9e7222000-04-25 02:57:36 +00001748
1749
Greg Ward16aafcd2000-04-09 04:06:44 +00001750\section{Reference}
Greg Ward47f99a62000-09-04 20:07:15 +00001751\label{reference}
Greg Ward16aafcd2000-04-09 04:06:44 +00001752
1753
Fred Drakea09262e2001-03-01 18:35:43 +00001754%\subsection{Building modules: the \protect\command{build} command family}
1755%\label{build-cmds}
Greg Ward16aafcd2000-04-09 04:06:44 +00001756
Fred Drakea09262e2001-03-01 18:35:43 +00001757%\subsubsection{\protect\command{build}}
1758%\label{build-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001759
Fred Drakea09262e2001-03-01 18:35:43 +00001760%\subsubsection{\protect\command{build\_py}}
1761%\label{build-py-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001762
Fred Drakea09262e2001-03-01 18:35:43 +00001763%\subsubsection{\protect\command{build\_ext}}
1764%\label{build-ext-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001765
Fred Drakea09262e2001-03-01 18:35:43 +00001766%\subsubsection{\protect\command{build\_clib}}
1767%\label{build-clib-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001768
1769
Greg Wardfacb8db2000-04-09 04:32:40 +00001770\subsection{Installing modules: the \protect\command{install} command family}
Greg Warde78298a2000-04-28 17:12:24 +00001771\label{install-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001772
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001773The install command ensures that the build commands have been run and then
1774runs the subcommands \command{install\_lib},
1775\command{install\_data} and
1776\command{install\_scripts}.
1777
Fred Drakea09262e2001-03-01 18:35:43 +00001778%\subsubsection{\protect\command{install\_lib}}
1779%\label{install-lib-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001780
1781\subsubsection{\protect\command{install\_data}}
Greg Ward1365a302000-08-31 14:47:05 +00001782\label{install-data-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001783This command installs all data files provided with the distribution.
1784
1785\subsubsection{\protect\command{install\_scripts}}
Greg Ward1365a302000-08-31 14:47:05 +00001786\label{install-scripts-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001787This command installs all (Python) scripts in the distribution.
1788
Greg Ward16aafcd2000-04-09 04:06:44 +00001789
Fred Drakea09262e2001-03-01 18:35:43 +00001790%\subsection{Cleaning up: the \protect\command{clean} command}
1791%\label{clean-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001792
1793
Fred Drakeeff9a872000-10-26 16:41:03 +00001794\subsection{Creating a source distribution: the
1795 \protect\command{sdist} command}
Greg Warde78298a2000-04-28 17:12:24 +00001796\label{sdist-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001797
1798
1799\XXX{fragment moved down from above: needs context!}
Greg Wardb6528972000-09-07 02:40:37 +00001800
Greg Ward16aafcd2000-04-09 04:06:44 +00001801The manifest template commands are:
1802\begin{tableii}{ll}{command}{Command}{Description}
Greg Ward87da1ea2000-04-21 04:35:25 +00001803 \lineii{include \var{pat1} \var{pat2} ... }
1804 {include all files matching any of the listed patterns}
1805 \lineii{exclude \var{pat1} \var{pat2} ... }
1806 {exclude all files matching any of the listed patterns}
1807 \lineii{recursive-include \var{dir} \var{pat1} \var{pat2} ... }
1808 {include all files under \var{dir} matching any of the listed patterns}
1809 \lineii{recursive-exclude \var{dir} \var{pat1} \var{pat2} ...}
1810 {exclude all files under \var{dir} matching any of the listed patterns}
1811 \lineii{global-include \var{pat1} \var{pat2} ...}
Greg Ward1bbe3292000-06-25 03:14:13 +00001812 {include all files anywhere in the source tree matching\\&
Greg Ward87da1ea2000-04-21 04:35:25 +00001813 any of the listed patterns}
1814 \lineii{global-exclude \var{pat1} \var{pat2} ...}
Greg Ward1bbe3292000-06-25 03:14:13 +00001815 {exclude all files anywhere in the source tree matching\\&
Greg Ward87da1ea2000-04-21 04:35:25 +00001816 any of the listed patterns}
Greg Ward16aafcd2000-04-09 04:06:44 +00001817 \lineii{prune \var{dir}}{exclude all files under \var{dir}}
1818 \lineii{graft \var{dir}}{include all files under \var{dir}}
1819\end{tableii}
Fred Drakeeff9a872000-10-26 16:41:03 +00001820The patterns here are \UNIX-style ``glob'' patterns: \code{*} matches any
Greg Ward16aafcd2000-04-09 04:06:44 +00001821sequence of regular filename characters, \code{?} matches any single
1822regular filename character, and \code{[\var{range}]} matches any of the
1823characters in \var{range} (e.g., \code{a-z}, \code{a-zA-Z},
Greg Wardfacb8db2000-04-09 04:32:40 +00001824\code{a-f0-9\_.}). The definition of ``regular filename character'' is
Fred Drakeeff9a872000-10-26 16:41:03 +00001825platform-specific: on \UNIX{} it is anything except slash; on Windows
1826anything except backslash or colon; on MacOS anything except colon.
Greg Wardb6528972000-09-07 02:40:37 +00001827
Fred Drakeeff9a872000-10-26 16:41:03 +00001828\XXX{Windows and MacOS support not there yet}
Greg Ward16aafcd2000-04-09 04:06:44 +00001829
1830
Fred Drakea09262e2001-03-01 18:35:43 +00001831%\subsection{Creating a built distribution: the
1832% \protect\command{bdist} command family}
1833%\label{bdist-cmds}
Greg Ward16aafcd2000-04-09 04:06:44 +00001834
1835
Fred Drakeab70b382001-08-02 15:13:15 +00001836%\subsubsection{\protect\command{bdist}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001837
Fred Drakeab70b382001-08-02 15:13:15 +00001838%\subsubsection{\protect\command{bdist\_dumb}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001839
Fred Drakeab70b382001-08-02 15:13:15 +00001840%\subsubsection{\protect\command{bdist\_rpm}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001841
Fred Drakeab70b382001-08-02 15:13:15 +00001842%\subsubsection{\protect\command{bdist\_wininst}}
1843
1844
1845\input{sysconfig}
Greg Ward16aafcd2000-04-09 04:06:44 +00001846
1847
Greg Wardabc52162000-02-26 00:52:48 +00001848\end{document}