blob: d640f50733ce6ae05e90f38076a487717ba9a24e [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)}
Andrew M. Kuchlingb6b46132003-02-26 18:58:46 +0000698 \lineiii{url}{URL of the package's home page}{(1)}
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +0000699 \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}{}
Andrew M. Kuchlingb6b46132003-02-26 18:58:46 +0000703 \lineiii{platforms}{a list of the target platforms}{}
704 \lineiii{classifiers}{a list of Trove classifiers}{(3),(4)}
705 \lineiii{download_url}{a single URL containing the download location
706 for this version of the package}{(3)}
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +0000707\end{tableiii}
708
709\noindent Notes:
710\begin{description}
711\item[(1)] these fields are required
712\item[(2)] either the author or the maintainer must be nominated
713\item[(3)] should not be used if your package is to be compatible with
Andrew M. Kuchlingb6b46132003-02-26 18:58:46 +0000714 Python versions prior to 2.2.3 or 2.3.
715\item[(4)] The list of classifiers is available from the
716 PyPI website (\url{http://www.python.org/pypi}).
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +0000717\end{description}
718
719\option{classifiers} are specified in a python list:
720
721\begin{verbatim}
722setup(...
723 classifiers = [
724 'Development Status :: 4 - Beta',
725 'Environment :: Console',
726 'Environment :: Web Environment',
727 'Intended Audience :: End Users/Desktop',
728 'Intended Audience :: Developers',
729 'Intended Audience :: System Administrators',
730 'License :: OSI Approved :: Python Software Foundation License',
731 'Operating System :: MacOS :: MacOS X',
732 'Operating System :: Microsoft :: Windows',
733 'Operating System :: POSIX',
734 'Programming Language :: Python',
735 'Topic :: Communications :: Email',
736 'Topic :: Office/Business',
737 'Topic :: Software Development :: Bug Tracking',
738 ],
739 ...
740)
741\end{verbatim}
742
743If you wish to include classifiers in your \file{setup.py} file and also
744wish to remain backwards-compatible with Python releases prior to 2.2.3,
745then you can include the following code fragment in your \file{setup.py}
746before the \code{setup()} call.
747
748\begin{verbatim}
749# patch distutils if it can't cope with the "classifiers" keyword
750if sys.version < '2.2.3':
751 from distutils.dist import DistributionMetadata
752 DistributionMetadata.classifiers = None
753\end{verbatim}
754
Greg Ward16aafcd2000-04-09 04:06:44 +0000755
756\section{Writing the Setup Configuration File}
Greg Warde78298a2000-04-28 17:12:24 +0000757\label{setup-config}
Greg Ward16aafcd2000-04-09 04:06:44 +0000758
Greg Ward16aafcd2000-04-09 04:06:44 +0000759Often, it's not possible to write down everything needed to build a
Greg Ward47f99a62000-09-04 20:07:15 +0000760distribution \emph{a priori}: you may need to get some information from
761the user, or from the user's system, in order to proceed. As long as
762that information is fairly simple---a list of directories to search for
763C header files or libraries, for example---then providing a
764configuration file, \file{setup.cfg}, for users to edit is a cheap and
765easy way to solicit it. Configuration files also let you provide
766default values for any command option, which the installer can then
767override either on the command-line or by editing the config file.
Greg Ward16aafcd2000-04-09 04:06:44 +0000768
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000769% (If you have more advanced needs, such as determining which extensions
770% to build based on what capabilities are present on the target system,
771% then you need the Distutils ``auto-configuration'' facility. This
772% started to appear in Distutils 0.9 but, as of this writing, isn't mature
773% or stable enough yet for real-world use.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000774
Greg Ward47f99a62000-09-04 20:07:15 +0000775The setup configuration file is a useful middle-ground between the setup
776script---which, ideally, would be opaque to installers\footnote{This
777 ideal probably won't be achieved until auto-configuration is fully
778 supported by the Distutils.}---and the command-line to the setup
779script, which is outside of your control and entirely up to the
780installer. In fact, \file{setup.cfg} (and any other Distutils
781configuration files present on the target system) are processed after
782the contents of the setup script, but before the command-line. This has
783several useful consequences:
784\begin{itemize}
785\item installers can override some of what you put in \file{setup.py} by
786 editing \file{setup.cfg}
787\item you can provide non-standard defaults for options that are not
788 easily set in \file{setup.py}
789\item installers can override anything in \file{setup.cfg} using the
790 command-line options to \file{setup.py}
791\end{itemize}
792
793The basic syntax of the configuration file is simple:
Fred Drakea09262e2001-03-01 18:35:43 +0000794
Greg Ward47f99a62000-09-04 20:07:15 +0000795\begin{verbatim}
796[command]
797option=value
798...
799\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000800
Greg Ward47f99a62000-09-04 20:07:15 +0000801where \var{command} is one of the Distutils commands (e.g.
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000802\command{build\_py}, \command{install}), and \var{option} is one of
803the options that command supports. Any number of options can be
804supplied for each command, and any number of command sections can be
805included in the file. Blank lines are ignored, as are comments, which
806run from a \character{\#} character until the end of the line. Long
807option values can be split across multiple lines simply by indenting
808the continuation lines.
Greg Ward47f99a62000-09-04 20:07:15 +0000809
810You can find out the list of options supported by a particular command
811with the universal \longprogramopt{help} option, e.g.
Fred Drakea09262e2001-03-01 18:35:43 +0000812
Greg Ward47f99a62000-09-04 20:07:15 +0000813\begin{verbatim}
814> python setup.py --help build_ext
815[...]
816Options for 'build_ext' command:
817 --build-lib (-b) directory for compiled extension modules
818 --build-temp (-t) directory for temporary files (build by-products)
819 --inplace (-i) ignore build-lib and put compiled extensions into the
820 source directory alongside your pure Python modules
821 --include-dirs (-I) list of directories to search for header files
822 --define (-D) C preprocessor macros to define
823 --undef (-U) C preprocessor macros to undefine
824[...]
825\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000826
Greg Ward47f99a62000-09-04 20:07:15 +0000827Note that an option spelled \longprogramopt{foo-bar} on the command-line
828is spelled \option{foo\_bar} in configuration files.
829
830For example, say you want your extensions to be built
831``in-place''---that is, you have an extension \module{pkg.ext}, and you
Fred Drakeeff9a872000-10-26 16:41:03 +0000832want the compiled extension file (\file{ext.so} on \UNIX, say) to be put
Greg Ward47f99a62000-09-04 20:07:15 +0000833in the same source directory as your pure Python modules
834\module{pkg.mod1} and \module{pkg.mod2}. You can always use the
835\longprogramopt{inplace} option on the command-line to ensure this:
Fred Drakea09262e2001-03-01 18:35:43 +0000836
Greg Ward47f99a62000-09-04 20:07:15 +0000837\begin{verbatim}
838python setup.py build_ext --inplace
839\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000840
Greg Ward47f99a62000-09-04 20:07:15 +0000841But this requires that you always specify the \command{build\_ext}
842command explicitly, and remember to provide \longprogramopt{inplace}.
843An easier way is to ``set and forget'' this option, by encoding it in
844\file{setup.cfg}, the configuration file for this distribution:
Fred Drakea09262e2001-03-01 18:35:43 +0000845
Greg Ward47f99a62000-09-04 20:07:15 +0000846\begin{verbatim}
847[build_ext]
848inplace=1
849\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000850
Greg Ward47f99a62000-09-04 20:07:15 +0000851This will affect all builds of this module distribution, whether or not
852you explcitly specify \command{build\_ext}. If you include
853\file{setup.cfg} in your source distribution, it will also affect
854end-user builds---which is probably a bad idea for this option, since
855always building extensions in-place would break installation of the
856module distribution. In certain peculiar cases, though, modules are
857built right in their installation directory, so this is conceivably a
858useful ability. (Distributing extensions that expect to be built in
859their installation directory is almost always a bad idea, though.)
860
861Another example: certain commands take a lot of options that don't
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000862change from run to run; for example, \command{bdist\_rpm} needs to know
Greg Ward47f99a62000-09-04 20:07:15 +0000863everything required to generate a ``spec'' file for creating an RPM
864distribution. Some of this information comes from the setup script, and
865some is automatically generated by the Distutils (such as the list of
866files installed). But some of it has to be supplied as options to
867\command{bdist\_rpm}, which would be very tedious to do on the
868command-line for every run. Hence, here is a snippet from the
869Distutils' own \file{setup.cfg}:
Fred Drakea09262e2001-03-01 18:35:43 +0000870
Greg Ward47f99a62000-09-04 20:07:15 +0000871\begin{verbatim}
872[bdist_rpm]
873release = 1
874packager = Greg Ward <gward@python.net>
875doc_files = CHANGES.txt
876 README.txt
877 USAGE.txt
878 doc/
879 examples/
880\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000881
Greg Ward47f99a62000-09-04 20:07:15 +0000882Note that the \option{doc\_files} option is simply a
883whitespace-separated string split across multiple lines for readability.
Greg Ward16aafcd2000-04-09 04:06:44 +0000884
885
Fred Drakea09262e2001-03-01 18:35:43 +0000886\begin{seealso}
887 \seetitle[../inst/config-syntax.html]{Installing Python
888 Modules}{More information on the configuration files is
889 available in the manual for system administrators.}
890\end{seealso}
891
892
Greg Ward16aafcd2000-04-09 04:06:44 +0000893\section{Creating a Source Distribution}
Greg Warde78298a2000-04-28 17:12:24 +0000894\label{source-dist}
Greg Ward16aafcd2000-04-09 04:06:44 +0000895
Greg Warde78298a2000-04-28 17:12:24 +0000896As shown in section~\ref{simple-example}, you use the
Greg Ward16aafcd2000-04-09 04:06:44 +0000897\command{sdist} command to create a source distribution. In the
898simplest case,
Fred Drakea09262e2001-03-01 18:35:43 +0000899
Greg Ward16aafcd2000-04-09 04:06:44 +0000900\begin{verbatim}
901python setup.py sdist
902\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000903
Greg Ward19c67f82000-06-24 01:33:16 +0000904(assuming you haven't specified any \command{sdist} options in the setup
905script or config file), \command{sdist} creates the archive of the
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000906default format for the current platform. The default format is a gzip'ed
Fred Drakeeff9a872000-10-26 16:41:03 +0000907tar file (\file{.tar.gz}) on \UNIX, and ZIP file on Windows.
908\XXX{no MacOS support here}
Greg Ward54589d42000-09-06 01:37:35 +0000909
Greg Wardd5767a52000-04-19 22:48:09 +0000910You can specify as many formats as you like using the
911\longprogramopt{formats} option, for example:
Fred Drakea09262e2001-03-01 18:35:43 +0000912
Greg Ward16aafcd2000-04-09 04:06:44 +0000913\begin{verbatim}
914python setup.py sdist --formats=gztar,zip
915\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000916
Greg Ward16aafcd2000-04-09 04:06:44 +0000917to create a gzipped tarball and a zip file. The available formats are:
Greg Ward46b98e32000-04-14 01:53:36 +0000918\begin{tableiii}{l|l|c}{code}%
919 {Format}{Description}{Notes}
Greg Ward54589d42000-09-06 01:37:35 +0000920 \lineiii{zip}{zip file (\file{.zip})}{(1),(3)}
921 \lineiii{gztar}{gzip'ed tar file (\file{.tar.gz})}{(2),(4)}
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000922 \lineiii{bztar}{bzip2'ed tar file (\file{.tar.bz2})}{(4)}
Greg Ward47f99a62000-09-04 20:07:15 +0000923 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(4)}
Greg Ward54589d42000-09-06 01:37:35 +0000924 \lineiii{tar}{tar file (\file{.tar})}{(4)}
Greg Ward46b98e32000-04-14 01:53:36 +0000925\end{tableiii}
926
927\noindent Notes:
928\begin{description}
929\item[(1)] default on Windows
Fred Drakeeff9a872000-10-26 16:41:03 +0000930\item[(2)] default on \UNIX
Greg Wardb6528972000-09-07 02:40:37 +0000931\item[(3)] requires either external \program{zip} utility or
Greg Ward954ce8b2002-05-10 14:42:10 +0000932 \module{zipfile} module (part of the standard Python library since
933 Python~1.6)
Greg Ward47f99a62000-09-04 20:07:15 +0000934\item[(4)] requires external utilities: \program{tar} and possibly one
935 of \program{gzip}, \program{bzip2}, or \program{compress}
Greg Ward46b98e32000-04-14 01:53:36 +0000936\end{description}
Greg Ward16aafcd2000-04-09 04:06:44 +0000937
938
Greg Ward54589d42000-09-06 01:37:35 +0000939
940\subsection{Specifying the files to distribute}
Greg Warde78298a2000-04-28 17:12:24 +0000941\label{manifest}
Greg Ward16aafcd2000-04-09 04:06:44 +0000942
Greg Ward54589d42000-09-06 01:37:35 +0000943If you don't supply an explicit list of files (or instructions on how to
944generate one), the \command{sdist} command puts a minimal default set
945into the source distribution:
Greg Ward16aafcd2000-04-09 04:06:44 +0000946\begin{itemize}
Greg Wardfacb8db2000-04-09 04:32:40 +0000947\item all Python source files implied by the \option{py\_modules} and
Greg Ward16aafcd2000-04-09 04:06:44 +0000948 \option{packages} options
Greg Wardfacb8db2000-04-09 04:32:40 +0000949\item all C source files mentioned in the \option{ext\_modules} or
Greg Ward16aafcd2000-04-09 04:06:44 +0000950 \option{libraries} options (\XXX{getting C library sources currently
Greg Wardfacb8db2000-04-09 04:32:40 +0000951 broken -- no get\_source\_files() method in build\_clib.py!})
Greg Ward16aafcd2000-04-09 04:06:44 +0000952\item anything that looks like a test script: \file{test/test*.py}
953 (currently, the Distutils don't do anything with test scripts except
954 include them in source distributions, but in the future there will be
955 a standard for testing Python module distributions)
Greg Ward54589d42000-09-06 01:37:35 +0000956\item \file{README.txt} (or \file{README}), \file{setup.py} (or whatever
957 you called your setup script), and \file{setup.cfg}
Greg Ward16aafcd2000-04-09 04:06:44 +0000958\end{itemize}
Andrew M. Kuchling40df7102002-05-08 13:39:03 +0000959
Greg Ward16aafcd2000-04-09 04:06:44 +0000960Sometimes this is enough, but usually you will want to specify
961additional files to distribute. The typical way to do this is to write
962a \emph{manifest template}, called \file{MANIFEST.in} by default. The
Greg Ward54589d42000-09-06 01:37:35 +0000963manifest template is just a list of instructions for how to generate
964your manifest file, \file{MANIFEST}, which is the exact list of files to
965include in your source distribution. The \command{sdist} command
966processes this template and generates a manifest based on its
967instructions and what it finds in the filesystem.
968
969If you prefer to roll your own manifest file, the format is simple: one
970filename per line, regular files (or symlinks to them) only. If you do
971supply your own \file{MANIFEST}, you must specify everything: the
972default set of files described above does not apply in this case.
Greg Ward16aafcd2000-04-09 04:06:44 +0000973
974The manifest template has one command per line, where each command
975specifies a set of files to include or exclude from the source
976distribution. For an example, again we turn to the Distutils' own
977manifest template:
Fred Drakea09262e2001-03-01 18:35:43 +0000978
Greg Ward16aafcd2000-04-09 04:06:44 +0000979\begin{verbatim}
980include *.txt
Greg Ward87da1ea2000-04-21 04:35:25 +0000981recursive-include examples *.txt *.py
Greg Ward16aafcd2000-04-09 04:06:44 +0000982prune examples/sample?/build
983\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +0000984
Greg Ward16aafcd2000-04-09 04:06:44 +0000985The meanings should be fairly clear: include all files in the
986distribution root matching \code{*.txt}, all files anywhere under the
987\file{examples} directory matching \code{*.txt} or \code{*.py}, and
Greg Ward54589d42000-09-06 01:37:35 +0000988exclude all directories matching \code{examples/sample?/build}. All of
989this is done \emph{after} the standard include set, so you can exclude
990files from the standard set with explicit instructions in the manifest
991template. (Or, you can use the \longprogramopt{no-defaults} option to
992disable the standard set entirely.) There are several other commands
993available in the manifest template mini-language; see
994section~\ref{sdist-cmd}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000995
Greg Ward54589d42000-09-06 01:37:35 +0000996The order of commands in the manifest template matters: initially, we
997have the list of default files as described above, and each command in
998the template adds to or removes from that list of files. Once we have
999fully processed the manifest template, we remove files that should not
1000be included in the source distribution:
1001\begin{itemize}
1002\item all files in the Distutils ``build'' tree (default \file{build/})
1003\item all files in directories named \file{RCS} or \file{CVS}
1004\end{itemize}
1005Now we have our complete list of files, which is written to the manifest
1006for future reference, and then used to build the source distribution
1007archive(s).
1008
1009You can disable the default set of included files with the
1010\longprogramopt{no-defaults} option, and you can disable the standard
1011exclude set with \longprogramopt{no-prune}.
Greg Ward16aafcd2000-04-09 04:06:44 +00001012
Greg Ward46b98e32000-04-14 01:53:36 +00001013Following the Distutils' own manifest template, let's trace how the
Greg Ward47f99a62000-09-04 20:07:15 +00001014\command{sdist} command builds the list of files to include in the
Greg Ward46b98e32000-04-14 01:53:36 +00001015Distutils source distribution:
Greg Ward16aafcd2000-04-09 04:06:44 +00001016\begin{enumerate}
1017\item include all Python source files in the \file{distutils} and
1018 \file{distutils/command} subdirectories (because packages
1019 corresponding to those two directories were mentioned in the
Greg Ward54589d42000-09-06 01:37:35 +00001020 \option{packages} option in the setup script---see
1021 section~\ref{setup-script})
1022\item include \file{README.txt}, \file{setup.py}, and \file{setup.cfg}
1023 (standard files)
1024\item include \file{test/test*.py} (standard files)
Greg Ward16aafcd2000-04-09 04:06:44 +00001025\item include \file{*.txt} in the distribution root (this will find
1026 \file{README.txt} a second time, but such redundancies are weeded out
1027 later)
Greg Ward54589d42000-09-06 01:37:35 +00001028\item include anything matching \file{*.txt} or \file{*.py} in the
1029 sub-tree under \file{examples},
1030\item exclude all files in the sub-trees starting at directories
1031 matching \file{examples/sample?/build}---this may exclude files
1032 included by the previous two steps, so it's important that the
1033 \code{prune} command in the manifest template comes after the
1034 \code{recursive-include} command
1035\item exclude the entire \file{build} tree, and any \file{RCS} or
1036 \file{CVS} directories
Greg Wardfacb8db2000-04-09 04:32:40 +00001037\end{enumerate}
Greg Ward46b98e32000-04-14 01:53:36 +00001038Just like in the setup script, file and directory names in the manifest
1039template should always be slash-separated; the Distutils will take care
1040of converting them to the standard representation on your platform.
1041That way, the manifest template is portable across operating systems.
1042
Greg Ward16aafcd2000-04-09 04:06:44 +00001043
1044\subsection{Manifest-related options}
Greg Warde78298a2000-04-28 17:12:24 +00001045\label{manifest-options}
Greg Ward16aafcd2000-04-09 04:06:44 +00001046
1047The normal course of operations for the \command{sdist} command is as
1048follows:
1049\begin{itemize}
Greg Ward46b98e32000-04-14 01:53:36 +00001050\item if the manifest file, \file{MANIFEST} doesn't exist, read
1051 \file{MANIFEST.in} and create the manifest
Greg Ward54589d42000-09-06 01:37:35 +00001052\item if neither \file{MANIFEST} nor \file{MANIFEST.in} exist, create a
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001053 manifest with just the default file set
Greg Ward1d8f57a2000-08-05 00:43:11 +00001054\item if either \file{MANIFEST.in} or the setup script (\file{setup.py})
1055 are more recent than \file{MANIFEST}, recreate \file{MANIFEST} by
1056 reading \file{MANIFEST.in}
Greg Ward16aafcd2000-04-09 04:06:44 +00001057\item use the list of files now in \file{MANIFEST} (either just
1058 generated or read in) to create the source distribution archive(s)
1059\end{itemize}
Greg Ward54589d42000-09-06 01:37:35 +00001060There are a couple of options that modify this behaviour. First, use
1061the \longprogramopt{no-defaults} and \longprogramopt{no-prune} to
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001062disable the standard ``include'' and ``exclude'' sets.
Greg Ward16aafcd2000-04-09 04:06:44 +00001063
Greg Ward54589d42000-09-06 01:37:35 +00001064Second, you might want to force the manifest to be regenerated---for
Greg Ward16aafcd2000-04-09 04:06:44 +00001065example, if you have added or removed files or directories that match an
1066existing pattern in the manifest template, you should regenerate the
1067manifest:
Fred Drakea09262e2001-03-01 18:35:43 +00001068
Greg Ward16aafcd2000-04-09 04:06:44 +00001069\begin{verbatim}
1070python setup.py sdist --force-manifest
1071\end{verbatim}
Greg Ward16aafcd2000-04-09 04:06:44 +00001072
1073Or, you might just want to (re)generate the manifest, but not create a
1074source distribution:
Fred Drakea09262e2001-03-01 18:35:43 +00001075
Greg Ward16aafcd2000-04-09 04:06:44 +00001076\begin{verbatim}
1077python setup.py sdist --manifest-only
1078\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001079
Greg Ward54589d42000-09-06 01:37:35 +00001080\longprogramopt{manifest-only} implies \longprogramopt{force-manifest}.
1081\programopt{-o} is a shortcut for \longprogramopt{manifest-only}, and
1082\programopt{-f} for \longprogramopt{force-manifest}.
Greg Ward16aafcd2000-04-09 04:06:44 +00001083
1084
1085\section{Creating Built Distributions}
Greg Warde78298a2000-04-28 17:12:24 +00001086\label{built-dist}
Greg Ward16aafcd2000-04-09 04:06:44 +00001087
Greg Ward46b98e32000-04-14 01:53:36 +00001088A ``built distribution'' is what you're probably used to thinking of
1089either as a ``binary package'' or an ``installer'' (depending on your
1090background). It's not necessarily binary, though, because it might
1091contain only Python source code and/or byte-code; and we don't call it a
1092package, because that word is already spoken for in Python. (And
1093``installer'' is a term specific to the Windows world. \XXX{do Mac
1094 people use it?})
Greg Ward16aafcd2000-04-09 04:06:44 +00001095
Greg Ward46b98e32000-04-14 01:53:36 +00001096A built distribution is how you make life as easy as possible for
1097installers of your module distribution: for users of RPM-based Linux
1098systems, it's a binary RPM; for Windows users, it's an executable
1099installer; for Debian-based Linux users, it's a Debian package; and so
1100forth. Obviously, no one person will be able to create built
Greg Wardb6528972000-09-07 02:40:37 +00001101distributions for every platform under the sun, so the Distutils are
Greg Ward46b98e32000-04-14 01:53:36 +00001102designed to enable module developers to concentrate on their
1103specialty---writing code and creating source distributions---while an
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001104intermediary species called \emph{packagers} springs up to turn source
Greg Ward19c67f82000-06-24 01:33:16 +00001105distributions into built distributions for as many platforms as there
Greg Ward46b98e32000-04-14 01:53:36 +00001106are packagers.
1107
1108Of course, the module developer could be his own packager; or the
1109packager could be a volunteer ``out there'' somewhere who has access to
1110a platform which the original developer does not; or it could be
1111software periodically grabbing new source distributions and turning them
1112into built distributions for as many platforms as the software has
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001113access to. Regardless of who they are, a packager uses the
Greg Ward46b98e32000-04-14 01:53:36 +00001114setup script and the \command{bdist} command family to generate built
1115distributions.
1116
1117As a simple example, if I run the following command in the Distutils
1118source tree:
Fred Drakea09262e2001-03-01 18:35:43 +00001119
Greg Ward46b98e32000-04-14 01:53:36 +00001120\begin{verbatim}
1121python setup.py bdist
1122\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001123
Greg Ward46b98e32000-04-14 01:53:36 +00001124then the Distutils builds my module distribution (the Distutils itself
1125in this case), does a ``fake'' installation (also in the \file{build}
1126directory), and creates the default type of built distribution for my
Greg Wardb6528972000-09-07 02:40:37 +00001127platform. The default format for built distributions is a ``dumb'' tar
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001128file on \UNIX, and a simple executable installer on Windows. (That tar
Greg Wardb6528972000-09-07 02:40:37 +00001129file is considered ``dumb'' because it has to be unpacked in a specific
1130location to work.)
Greg Ward1d8f57a2000-08-05 00:43:11 +00001131
Fred Drakeeff9a872000-10-26 16:41:03 +00001132Thus, the above command on a \UNIX{} system creates
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001133\file{Distutils-1.0.\filevar{plat}.tar.gz}; unpacking this tarball
Greg Wardb6528972000-09-07 02:40:37 +00001134from the right place installs the Distutils just as though you had
1135downloaded the source distribution and run \code{python setup.py
1136 install}. (The ``right place'' is either the root of the filesystem or
1137Python's \filevar{prefix} directory, depending on the options given to
1138the \command{bdist\_dumb} command; the default is to make dumb
1139distributions relative to \filevar{prefix}.)
Greg Ward46b98e32000-04-14 01:53:36 +00001140
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001141Obviously, for pure Python distributions, this isn't any simpler than
1142just running \code{python setup.py install}---but for non-pure
1143distributions, which include extensions that would need to be
1144compiled, it can mean the difference between someone being able to use
1145your extensions or not. And creating ``smart'' built distributions,
1146such as an RPM package or an executable installer for Windows, is far
1147more convenient for users even if your distribution doesn't include
1148any extensions.
Greg Ward46b98e32000-04-14 01:53:36 +00001149
Greg Wardb6528972000-09-07 02:40:37 +00001150The \command{bdist} command has a \longprogramopt{formats} option,
Greg Ward1d8f57a2000-08-05 00:43:11 +00001151similar to the \command{sdist} command, which you can use to select the
1152types of built distribution to generate: for example,
Fred Drakea09262e2001-03-01 18:35:43 +00001153
Greg Ward46b98e32000-04-14 01:53:36 +00001154\begin{verbatim}
1155python setup.py bdist --format=zip
1156\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001157
Fred Drakeeff9a872000-10-26 16:41:03 +00001158would, when run on a \UNIX{} system, create
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001159\file{Distutils-1.0.\filevar{plat}.zip}---again, this archive would be
Greg Ward1d8f57a2000-08-05 00:43:11 +00001160unpacked from the root directory to install the Distutils.
Greg Ward46b98e32000-04-14 01:53:36 +00001161
1162The available formats for built distributions are:
1163\begin{tableiii}{l|l|c}{code}%
1164 {Format}{Description}{Notes}
Greg Wardb6528972000-09-07 02:40:37 +00001165 \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1),(3)}
1166 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(3)}
1167 \lineiii{tar}{tar file (\file{.tar})}{(3)}
1168 \lineiii{zip}{zip file (\file{.zip})}{(4)}
1169 \lineiii{rpm}{RPM}{(5)}
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001170 \lineiii{pkgtool}{Solaris \program{pkgtool}}{}
1171 \lineiii{sdux}{HP-UX \program{swinstall}}{}
1172 \lineiii{rpm}{RPM}{(5)}
1173% \lineiii{srpm}{source RPM}{(5) \XXX{to do!}}
Thomas Heller5f52f722001-02-19 17:48:03 +00001174 \lineiii{wininst}{self-extracting ZIP file for Windows}{(2),(4)}
Greg Ward46b98e32000-04-14 01:53:36 +00001175\end{tableiii}
1176
1177\noindent Notes:
1178\begin{description}
Fred Drakeeff9a872000-10-26 16:41:03 +00001179\item[(1)] default on \UNIX
Greg Ward1d8f57a2000-08-05 00:43:11 +00001180\item[(2)] default on Windows \XXX{to-do!}
Greg Wardb6528972000-09-07 02:40:37 +00001181\item[(3)] requires external utilities: \program{tar} and possibly one
1182 of \program{gzip}, \program{bzip2}, or \program{compress}
1183\item[(4)] requires either external \program{zip} utility or
Greg Ward954ce8b2002-05-10 14:42:10 +00001184 \module{zipfile} module (part of the standard Python library since
1185 Python~1.6)
Greg Wardb6528972000-09-07 02:40:37 +00001186\item[(5)] requires external \program{rpm} utility, version 3.0.4 or
1187 better (use \code{rpm --version} to find out which version you have)
Greg Ward46b98e32000-04-14 01:53:36 +00001188\end{description}
1189
1190You don't have to use the \command{bdist} command with the
Greg Wardd5767a52000-04-19 22:48:09 +00001191\longprogramopt{formats} option; you can also use the command that
Greg Ward1d8f57a2000-08-05 00:43:11 +00001192directly implements the format you're interested in. Some of these
Greg Ward46b98e32000-04-14 01:53:36 +00001193\command{bdist} ``sub-commands'' actually generate several similar
1194formats; for instance, the \command{bdist\_dumb} command generates all
1195the ``dumb'' archive formats (\code{tar}, \code{ztar}, \code{gztar}, and
1196\code{zip}), and \command{bdist\_rpm} generates both binary and source
1197RPMs. The \command{bdist} sub-commands, and the formats generated by
1198each, are:
1199\begin{tableii}{l|l}{command}%
1200 {Command}{Formats}
1201 \lineii{bdist\_dumb}{tar, ztar, gztar, zip}
1202 \lineii{bdist\_rpm}{rpm, srpm}
Greg Ward1d8f57a2000-08-05 00:43:11 +00001203 \lineii{bdist\_wininst}{wininst}
Greg Ward46b98e32000-04-14 01:53:36 +00001204\end{tableii}
Greg Ward16aafcd2000-04-09 04:06:44 +00001205
Greg Wardb6528972000-09-07 02:40:37 +00001206The following sections give details on the individual \command{bdist\_*}
1207commands.
1208
1209
1210\subsection{Creating dumb built distributions}
1211\label{creating-dumb}
1212
1213\XXX{Need to document absolute vs. prefix-relative packages here, but
1214 first I have to implement it!}
1215
1216
1217\subsection{Creating RPM packages}
1218\label{creating-rpms}
1219
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001220The RPM format is used by many popular Linux distributions, including
Greg Wardb6528972000-09-07 02:40:37 +00001221Red Hat, SuSE, and Mandrake. If one of these (or any of the other
1222RPM-based Linux distributions) is your usual environment, creating RPM
1223packages for other users of that same distribution is trivial.
1224Depending on the complexity of your module distribution and differences
1225between Linux distributions, you may also be able to create RPMs that
1226work on different RPM-based distributions.
1227
1228The usual way to create an RPM of your module distribution is to run the
1229\command{bdist\_rpm} command:
Fred Drakea09262e2001-03-01 18:35:43 +00001230
Greg Wardb6528972000-09-07 02:40:37 +00001231\begin{verbatim}
1232python setup.py bdist_rpm
1233\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001234
Greg Wardb6528972000-09-07 02:40:37 +00001235or the \command{bdist} command with the \longprogramopt{format} option:
Fred Drakea09262e2001-03-01 18:35:43 +00001236
Greg Wardb6528972000-09-07 02:40:37 +00001237\begin{verbatim}
1238python setup.py bdist --formats=rpm
1239\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001240
Greg Wardb6528972000-09-07 02:40:37 +00001241The former allows you to specify RPM-specific options; the latter allows
1242you to easily specify multiple formats in one run. If you need to do
1243both, you can explicitly specify multiple \command{bdist\_*} commands
1244and their options:
Fred Drakea09262e2001-03-01 18:35:43 +00001245
Greg Wardb6528972000-09-07 02:40:37 +00001246\begin{verbatim}
1247python setup.py bdist_rpm --packager="John Doe <jdoe@python.net>" \
1248 bdist_wininst --target_version="2.0"
1249\end{verbatim}
1250
1251Creating RPM packages is driven by a \file{.spec} file, much as using
1252the Distutils is driven by the setup script. To make your life easier,
1253the \command{bdist\_rpm} command normally creates a \file{.spec} file
1254based on the information you supply in the setup script, on the command
1255line, and in any Distutils configuration files. Various options and
Andrew M. Kuchlingda23c4f2001-02-17 00:38:48 +00001256sections in the \file{.spec} file are derived from options in the setup
Greg Wardb6528972000-09-07 02:40:37 +00001257script as follows:
1258\begin{tableii}{l|l}{textrm}%
1259 {RPM \file{.spec} file option or section}{Distutils setup script option}
1260 \lineii{Name}{\option{name}}
1261 \lineii{Summary (in preamble)}{\option{description}}
1262 \lineii{Version}{\option{version}}
1263 \lineii{Vendor}{\option{author} and \option{author\_email}, or \\&
1264 \option{maintainer} and \option{maintainer\_email}}
1265 \lineii{Copyright}{\option{licence}}
1266 \lineii{Url}{\option{url}}
1267 \lineii{\%description (section)}{\option{long\_description}}
1268\end{tableii}
1269
1270Additionally, there many options in \file{.spec} files that don't have
1271corresponding options in the setup script. Most of these are handled
1272through options to the \command{bdist\_rpm} command as follows:
1273\begin{tableiii}{l|l|l}{textrm}%
1274 {RPM \file{.spec} file option or section}%
1275 {\command{bdist\_rpm} option}%
1276 {default value}
1277 \lineiii{Release}{\option{release}}{``1''}
1278 \lineiii{Group}{\option{group}}{``Development/Libraries''}
1279 \lineiii{Vendor}{\option{vendor}}{(see above)}
Andrew M. Kuchlingda23c4f2001-02-17 00:38:48 +00001280 \lineiii{Packager}{\option{packager}}{(none)}
1281 \lineiii{Provides}{\option{provides}}{(none)}
1282 \lineiii{Requires}{\option{requires}}{(none)}
1283 \lineiii{Conflicts}{\option{conflicts}}{(none)}
1284 \lineiii{Obsoletes}{\option{obsoletes}}{(none)}
Greg Wardb6528972000-09-07 02:40:37 +00001285 \lineiii{Distribution}{\option{distribution\_name}}{(none)}
1286 \lineiii{BuildRequires}{\option{build\_requires}}{(none)}
1287 \lineiii{Icon}{\option{icon}}{(none)}
1288\end{tableiii}
1289Obviously, supplying even a few of these options on the command-line
1290would be tedious and error-prone, so it's usually best to put them in
1291the setup configuration file, \file{setup.cfg}---see
1292section~\ref{setup-config}. If you distribute or package many Python
1293module distributions, you might want to put options that apply to all of
1294them in your personal Distutils configuration file
1295(\file{\textasciitilde/.pydistutils.cfg}).
1296
1297There are three steps to building a binary RPM package, all of which are
1298handled automatically by the Distutils:
1299\begin{enumerate}
1300\item create a \file{.spec} file, which describes the package (analogous
1301 to the Distutils setup script; in fact, much of the information in the
1302 setup script winds up in the \file{.spec} file)
1303\item create the source RPM
1304\item create the ``binary'' RPM (which may or may not contain binary
1305 code, depending on whether your module distribution contains Python
1306 extensions)
1307\end{enumerate}
1308Normally, RPM bundles the last two steps together; when you use the
1309Distutils, all three steps are typically bundled together.
1310
1311If you wish, you can separate these three steps. You can use the
1312\longprogramopt{spec-only} option to make \command{bdist\_rpm} just
1313create the \file{.spec} file and exit; in this case, the \file{.spec}
1314file will be written to the ``distribution directory''---normally
1315\file{dist/}, but customizable with the \longprogramopt{dist-dir}
1316option. (Normally, the \file{.spec} file winds up deep in the ``build
1317tree,'' in a temporary directory created by \command{bdist\_rpm}.)
1318
1319\XXX{this isn't implemented yet---is it needed?!}
1320You can also specify a custom \file{.spec} file with the
Thomas Heller5f52f722001-02-19 17:48:03 +00001321\longprogramopt{spec-file} option; used in conjunction with
Greg Wardb6528972000-09-07 02:40:37 +00001322\longprogramopt{spec-only}, this gives you an opportunity to customize
1323the \file{.spec} file manually:
Fred Drakea09262e2001-03-01 18:35:43 +00001324
Greg Wardb6528972000-09-07 02:40:37 +00001325\begin{verbatim}
1326> python setup.py bdist_rpm --spec-only
1327# ...edit dist/FooBar-1.0.spec
1328> python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec
1329\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001330
Greg Wardb6528972000-09-07 02:40:37 +00001331(Although a better way to do this is probably to override the standard
1332\command{bdist\_rpm} command with one that writes whatever else you want
1333to the \file{.spec} file; see section~\ref{extending} for information on
1334extending the Distutils.)
1335
1336
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001337\subsection{Creating Windows Installers}
Greg Wardb6528972000-09-07 02:40:37 +00001338\label{creating-wininst}
1339
Thomas Hellere61f3652002-11-15 20:13:26 +00001340Executable installers are the natural format for binary distributions
1341on Windows. They display a nice graphical user interface, display
1342some information about the module distribution to be installed taken
Andrew M. Kuchlingd7abe2a2002-05-29 17:33:48 +00001343from the metadata in the setup script, let the user select a few
Thomas Hellere61f3652002-11-15 20:13:26 +00001344options, and start or cancel the installation.
Greg Wardb6528972000-09-07 02:40:37 +00001345
Thomas Hellere61f3652002-11-15 20:13:26 +00001346Since the metadata is taken from the setup script, creating Windows
1347installers is usually as easy as running:
Fred Drakea09262e2001-03-01 18:35:43 +00001348
Thomas Heller5f52f722001-02-19 17:48:03 +00001349\begin{verbatim}
1350python setup.py bdist_wininst
1351\end{verbatim}
Fred Drakea09262e2001-03-01 18:35:43 +00001352
Thomas Heller36343f62002-11-15 19:20:56 +00001353or the \command{bdist} command with the \longprogramopt{formats} option:
Fred Drakea09262e2001-03-01 18:35:43 +00001354
Thomas Heller5f52f722001-02-19 17:48:03 +00001355\begin{verbatim}
1356python setup.py bdist --formats=wininst
1357\end{verbatim}
1358
Thomas Hellere61f3652002-11-15 20:13:26 +00001359If you have a pure module distribution (only containing pure Python
1360modules and packages), the resulting installer will be version
1361independent and have a name like \file{foo-1.0.win32.exe}. These
1362installers can even be created on \UNIX{} or MacOS platforms.
Thomas Heller5f52f722001-02-19 17:48:03 +00001363
1364If you have a non-pure distribution, the extensions can only be
Andrew M. Kuchling40df7102002-05-08 13:39:03 +00001365created on a Windows platform, and will be Python version dependent.
Thomas Heller5f52f722001-02-19 17:48:03 +00001366The installer filename will reflect this and now has the form
Thomas Hellere61f3652002-11-15 20:13:26 +00001367\file{foo-1.0.win32-py2.0.exe}. You have to create a separate installer
Thomas Heller5f52f722001-02-19 17:48:03 +00001368for every Python version you want to support.
1369
1370The installer will try to compile pure modules into bytecode after
Thomas Hellere61f3652002-11-15 20:13:26 +00001371installation on the target system in normal and optimizing mode. If
1372you don't want this to happen for some reason, you can run the
Fred Drake0e9bfa32002-11-15 20:34:52 +00001373\command{bdist_wininst} command with the
1374\longprogramopt{no-target-compile} and/or the
1375\longprogramopt{no-target-optimize} option.
Thomas Hellere61f3652002-11-15 20:13:26 +00001376
Fred Drake0e9bfa32002-11-15 20:34:52 +00001377By default the installer will display the cool ``Python Powered'' logo
Thomas Hellere61f3652002-11-15 20:13:26 +00001378when it is run, but you can also supply your own bitmap which must be
Fred Drake0e9bfa32002-11-15 20:34:52 +00001379a Windows \file{.bmp} file with the \longprogramopt{bitmap} option.
Thomas Hellere61f3652002-11-15 20:13:26 +00001380
1381The installer will also display a large title on the desktop
1382background window when it is run, which is constructed from the name
1383of your distribution and the version number. This can be changed to
1384another text by using the \longprogramopt{title} option.
1385
1386The installer file will be written to the ``distribution directory''
1387--- normally \file{dist/}, but customizable with the
1388\longprogramopt{dist-dir} option.
1389
Thomas Heller2c3bfc22002-12-12 18:54:19 +00001390\subsubsection{The Postinstallation script}
1391\label{postinstallation-script}
1392
1393Starting with Python 2.3, a postinstallation script can be specified
1394which the \longprogramopt{install-script} option. The basename of the
1395script must be specified, and the script filename must also be listed
1396in the scripts argument to the setup function.
1397
1398This script will be run at installation time on the target system
1399after all the files have been copied, with argv[1] set to '-install',
1400and again at uninstallation time before the files are removed with argv[1]
1401set to '-remove'.
1402
1403The installation script runs embedded in the windows installer, every
1404output (sys.stdout, sys.stderr) is redirected into a buffer and will
1405be displayed in the GUI after the script has finished.
1406
1407Some functions especially useful in this context are available in the
1408installation script.
1409
1410\begin{verbatim}
1411dir_created(pathname)
1412file_created(pathname)
1413\end{verbatim}
1414
1415These functions should be called when a directory or file is created
1416by the postinstall script at installation time. It will register the
1417pathname with the uninstaller, so that it will be removed when the
1418distribution is uninstalled. To be safe, directories are only removed
1419if they are empty.
1420
1421\begin{verbatim}
1422get_special_folder_path(csidl_string)
1423\end{verbatim}
1424
1425This function can be used to retrieve special folder locations on
1426Windows like the Start Menu or the Desktop. It returns the full path
1427to the folder. 'csidl_string' must be on of the following strings:
1428
1429\begin{verbatim}
1430"CSIDL_APPDATA"
1431
1432"CSIDL_COMMON_STARTMENU"
1433"CSIDL_STARTMENU"
1434
1435"CSIDL_COMMON_DESKTOPDIRECTORY"
1436"CSIDL_DESKTOPDIRECTORY"
1437
1438"CSIDL_COMMON_STARTUP"
1439"CSIDL_STARTUP"
1440
1441"CSIDL_COMMON_PROGRAMS"
1442"CSIDL_PROGRAMS"
1443
1444"CSIDL_FONTS"
1445\end{verbatim}
1446
1447If the folder cannot be retrieved, OSError is raised.
1448
1449Which folders are available depends on the exact Windows version, and probably
1450also the configuration. For details refer to Microsoft's documentation of the
Thomas Heller63b4dd32002-12-12 19:35:00 +00001451\code{SHGetSpecialFolderPath} function.
Thomas Heller2c3bfc22002-12-12 18:54:19 +00001452
1453\begin{verbatim}
1454create_shortcut(target, description, filename[, arguments[,
1455 workdir[, iconpath[, iconindex]]]])
1456\end{verbatim}
1457
1458This function creates a shortcut.
Thomas Heller63b4dd32002-12-12 19:35:00 +00001459\var{target} is the path to the program to be started by the shortcut.
1460\var{description} is the description of the sortcut.
1461\var{filename} is the title of the shortcut that the user will see.
1462\var{arguments} specifies the command line arguments, if any.
1463\var{workdir} is the working directory for the program.
1464\var{iconpath} is the file containing the icon for the shortcut,
1465and \var{iconindex} is the index of the icon in the file
1466\var{iconpath}. Again, for details consult the Microsoft
1467documentation for the \code{IShellLink} interface.
Greg Wardb6528972000-09-07 02:40:37 +00001468
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +00001469\section{Registering with the Package Index}
1470\label{package-index}
1471
1472The Python Package Index (PyPI) holds meta-data describing distributions
1473packaged with distutils. The distutils command \command{register} is
1474used to submit your distribution's meta-data to the index. It is invoked
1475as follows:
1476
1477\begin{verbatim}
1478python setup.py register
1479\end{verbatim}
1480
1481Distutils will respond with the following prompt:
1482
1483\begin{verbatim}
1484running register
1485We need to know who you are, so please choose either:
1486 1. use your existing login,
1487 2. register as a new user,
1488 3. have the server generate a new password for you (and email it to you), or
1489 4. quit
1490Your selection [default 1]:
1491\end{verbatim}
1492
1493\noindent Note: if your username and password are saved locally, you will
1494not see this menu.
1495
1496If you have not registered with PyPI, then you will need to do so now. You
1497should choose option 2, and enter your details as required. Soon after
1498submitting your details, you will receive an email which will be used to
1499confirm your registration.
1500
1501Once you are registered, you may choose option 1 from the menu. You will
1502be prompted for your PyPI username and password, and \command{register}
1503will then submit your meta-data to the index.
1504
1505You may submit any number of versions of your distribution to the index. If
1506you alter the meta-data for a particular version, you may submit it again
1507and the index will be updated.
1508
1509PyPI holds a record for each (name, version) combination submitted. The
1510first user to submit information for a given name is designated the Owner
1511of that name. They may submit changes through the \command{register}
1512command or through the web interface. They may also designate other users
1513as Owners or Maintainers. Maintainers may edit the package information, but
1514not designate other Owners or Maintainers.
1515
1516By default PyPI will list all versions of a given package. To hide certain
1517versions, the Hidden property should be set to yes. This must be edited
1518through the web interface.
1519
1520
1521
Greg Ward007c04a2002-05-10 14:45:59 +00001522\section{Examples}
1523\label{examples}
Andrew M. Kuchlingd15f4e32003-01-03 15:42:14 +00001524
Greg Ward007c04a2002-05-10 14:45:59 +00001525\subsection{Pure Python distribution (by module)}
1526\label{pure-mod}
1527
1528If you're just distributing a couple of modules, especially if they
1529don't live in a particular package, you can specify them individually
1530using the \option{py\_modules} option in the setup script.
1531
1532In the simplest case, you'll have two files to worry about: a setup
1533script and the single module you're distributing, \file{foo.py} in this
1534example:
1535\begin{verbatim}
1536<root>/
1537 setup.py
1538 foo.py
1539\end{verbatim}
1540(In all diagrams in this section, \verb|<root>| will refer to the
1541distribution root directory.) A minimal setup script to describe this
1542situation would be:
1543\begin{verbatim}
1544from distutils.core import setup
1545setup(name = "foo", version = "1.0",
1546 py_modules = ["foo"])
1547\end{verbatim}
1548Note that the name of the distribution is specified independently with
1549the \option{name} option, and there's no rule that says it has to be the
1550same as the name of the sole module in the distribution (although that's
1551probably a good convention to follow). However, the distribution name
1552is used to generate filenames, so you should stick to letters, digits,
1553underscores, and hyphens.
1554
1555Since \option{py\_modules} is a list, you can of course specify multiple
1556modules, eg. if you're distributing modules \module{foo} and
1557\module{bar}, your setup might look like this:
1558\begin{verbatim}
1559<root>/
1560 setup.py
1561 foo.py
1562 bar.py
1563\end{verbatim}
1564and the setup script might be
1565\begin{verbatim}
1566from distutils.core import setup
1567setup(name = "foobar", version = "1.0",
1568 py_modules = ["foo", "bar"])
1569\end{verbatim}
1570
1571You can put module source files into another directory, but if you have
1572enough modules to do that, it's probably easier to specify modules by
1573package rather than listing them individually.
Greg Ward16aafcd2000-04-09 04:06:44 +00001574
1575
Greg Ward007c04a2002-05-10 14:45:59 +00001576\subsection{Pure Python distribution (by package)}
1577\label{pure-pkg}
1578
1579If you have more than a couple of modules to distribute, especially if
1580they are in multiple packages, it's probably easier to specify whole
1581packages rather than individual modules. This works even if your
1582modules are not in a package; you can just tell the Distutils to process
1583modules from the root package, and that works the same as any other
1584package (except that you don't have to have an \file{\_\_init\_\_.py}
1585file).
1586
1587The setup script from the last example could also be written as
1588\begin{verbatim}
1589from distutils.core import setup
1590setup(name = "foobar", version = "1.0",
1591 packages = [""])
1592\end{verbatim}
1593(The empty string stands for the root package.)
1594
1595If those two files are moved into a subdirectory, but remain in the root
1596package, e.g.:
1597\begin{verbatim}
1598<root>/
1599 setup.py
1600 src/ foo.py
1601 bar.py
1602\end{verbatim}
1603then you would still specify the root package, but you have to tell the
1604Distutils where source files in the root package live:
1605\begin{verbatim}
1606from distutils.core import setup
1607setup(name = "foobar", version = "1.0",
1608 package_dir = {"": "src"},
1609 packages = [""])
1610\end{verbatim}
1611
1612More typically, though, you will want to distribute multiple modules in
1613the same package (or in sub-packages). For example, if the \module{foo}
1614and \module{bar} modules belong in package \module{foobar}, one way to
1615layout your source tree is
1616\begin{verbatim}
1617<root>/
1618 setup.py
1619 foobar/
1620 __init__.py
1621 foo.py
1622 bar.py
1623\end{verbatim}
1624This is in fact the default layout expected by the Distutils, and the
1625one that requires the least work to describe in your setup script:
1626\begin{verbatim}
1627from distutils.core import setup
1628setup(name = "foobar", version = "1.0",
1629 packages = ["foobar"])
1630\end{verbatim}
1631
1632If you want to put modules in directories not named for their package,
1633then you need to use the \option{package\_dir} option again. For
1634example, if the \file{src} directory holds modules in the
1635\module{foobar} package:
1636\begin{verbatim}
1637<root>/
1638 setup.py
1639 src/
1640 __init__.py
1641 foo.py
1642 bar.py
1643\end{verbatim}
1644an appropriate setup script would be
1645\begin{verbatim}
1646from distutils.core import setup
1647setup(name = "foobar", version = "1.0",
1648 package_dir = {"foobar" : "src"},
1649 packages = ["foobar"])
1650\end{verbatim}
1651
1652Or, you might put modules from your main package right in the
1653distribution root:
1654\begin{verbatim}
1655<root>/
1656 setup.py
1657 __init__.py
1658 foo.py
1659 bar.py
1660\end{verbatim}
1661in which case your setup script would be
1662\begin{verbatim}
1663from distutils.core import setup
1664setup(name = "foobar", version = "1.0",
1665 package_dir = {"foobar" : ""},
1666 packages = ["foobar"])
1667\end{verbatim}
1668(The empty string also stands for the current directory.)
1669
1670If you have sub-packages, they must be explicitly listed in
1671\option{packages}, but any entries in \option{package\_dir}
1672automatically extend to sub-packages. (In other words, the Distutils
1673does \emph{not} scan your source tree, trying to figure out which
1674directories correspond to Python packages by looking for
1675\file{\_\_init\_\_.py} files.) Thus, if the default layout grows a
1676sub-package:
1677\begin{verbatim}
1678<root>/
1679 setup.py
1680 foobar/
1681 __init__.py
1682 foo.py
1683 bar.py
1684 subfoo/
1685 __init__.py
1686 blah.py
1687\end{verbatim}
1688then the corresponding setup script would be
1689\begin{verbatim}
1690from distutils.core import setup
1691setup(name = "foobar", version = "1.0",
1692 packages = ["foobar", "foobar.subfoo"])
1693\end{verbatim}
1694(Again, the empty string in \option{package\_dir} stands for the current
1695directory.)
Greg Ward16aafcd2000-04-09 04:06:44 +00001696
1697
Greg Ward007c04a2002-05-10 14:45:59 +00001698\subsection{Single extension module}
1699\label{single-ext}
1700
1701Extension modules are specified using the \option{ext\_modules} option.
1702\option{package\_dir} has no effect on where extension source files are
1703found; it only affects the source for pure Python modules. The simplest
1704case, a single extension module in a single C source file, is:
1705\begin{verbatim}
1706<root>/
1707 setup.py
1708 foo.c
1709\end{verbatim}
1710If the \module{foo} extension belongs in the root package, the setup
1711script for this could be
1712\begin{verbatim}
1713from distutils.core import setup
1714setup(name = "foobar", version = "1.0",
1715 ext_modules = [Extension("foo", ["foo.c"])])
1716\end{verbatim}
1717
1718If the extension actually belongs in a package, say \module{foopkg},
1719then
1720
1721With exactly the same source tree layout, this extension can be put in
1722the \module{foopkg} package simply by changing the name of the
1723extension:
1724\begin{verbatim}
1725from distutils.core import setup
1726setup(name = "foobar", version = "1.0",
1727 ext_modules = [Extension("foopkg.foo", ["foo.c"])])
1728\end{verbatim}
Greg Ward16aafcd2000-04-09 04:06:44 +00001729
1730
Fred Drakea09262e2001-03-01 18:35:43 +00001731%\subsection{Multiple extension modules}
1732%\label{multiple-ext}
Greg Ward16aafcd2000-04-09 04:06:44 +00001733
1734
Fred Drakea09262e2001-03-01 18:35:43 +00001735%\subsection{Putting it all together}
Greg Ward16aafcd2000-04-09 04:06:44 +00001736
1737
Fred Drakea09262e2001-03-01 18:35:43 +00001738%\section{Extending the Distutils}
1739%\label{extending}
Greg Ward4a9e7222000-04-25 02:57:36 +00001740
1741
Fred Drakea09262e2001-03-01 18:35:43 +00001742%\subsection{Extending existing commands}
1743%\label{extend-existing}
Greg Ward4a9e7222000-04-25 02:57:36 +00001744
1745
Fred Drakea09262e2001-03-01 18:35:43 +00001746%\subsection{Writing new commands}
1747%\label{new-commands}
Greg Ward4a9e7222000-04-25 02:57:36 +00001748
Fred Drakea09262e2001-03-01 18:35:43 +00001749%\XXX{Would an uninstall command be a good example here?}
Thomas Heller5f52f722001-02-19 17:48:03 +00001750
Greg Ward4a9e7222000-04-25 02:57:36 +00001751
1752
Greg Ward16aafcd2000-04-09 04:06:44 +00001753\section{Reference}
Greg Ward47f99a62000-09-04 20:07:15 +00001754\label{reference}
Greg Ward16aafcd2000-04-09 04:06:44 +00001755
1756
Fred Drakea09262e2001-03-01 18:35:43 +00001757%\subsection{Building modules: the \protect\command{build} command family}
1758%\label{build-cmds}
Greg Ward16aafcd2000-04-09 04:06:44 +00001759
Fred Drakea09262e2001-03-01 18:35:43 +00001760%\subsubsection{\protect\command{build}}
1761%\label{build-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001762
Fred Drakea09262e2001-03-01 18:35:43 +00001763%\subsubsection{\protect\command{build\_py}}
1764%\label{build-py-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001765
Fred Drakea09262e2001-03-01 18:35:43 +00001766%\subsubsection{\protect\command{build\_ext}}
1767%\label{build-ext-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001768
Fred Drakea09262e2001-03-01 18:35:43 +00001769%\subsubsection{\protect\command{build\_clib}}
1770%\label{build-clib-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001771
1772
Greg Wardfacb8db2000-04-09 04:32:40 +00001773\subsection{Installing modules: the \protect\command{install} command family}
Greg Warde78298a2000-04-28 17:12:24 +00001774\label{install-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001775
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001776The install command ensures that the build commands have been run and then
1777runs the subcommands \command{install\_lib},
1778\command{install\_data} and
1779\command{install\_scripts}.
1780
Fred Drakea09262e2001-03-01 18:35:43 +00001781%\subsubsection{\protect\command{install\_lib}}
1782%\label{install-lib-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001783
1784\subsubsection{\protect\command{install\_data}}
Greg Ward1365a302000-08-31 14:47:05 +00001785\label{install-data-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001786This command installs all data files provided with the distribution.
1787
1788\subsubsection{\protect\command{install\_scripts}}
Greg Ward1365a302000-08-31 14:47:05 +00001789\label{install-scripts-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001790This command installs all (Python) scripts in the distribution.
1791
Greg Ward16aafcd2000-04-09 04:06:44 +00001792
Fred Drakea09262e2001-03-01 18:35:43 +00001793%\subsection{Cleaning up: the \protect\command{clean} command}
1794%\label{clean-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001795
1796
Fred Drakeeff9a872000-10-26 16:41:03 +00001797\subsection{Creating a source distribution: the
1798 \protect\command{sdist} command}
Greg Warde78298a2000-04-28 17:12:24 +00001799\label{sdist-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001800
1801
1802\XXX{fragment moved down from above: needs context!}
Greg Wardb6528972000-09-07 02:40:37 +00001803
Greg Ward16aafcd2000-04-09 04:06:44 +00001804The manifest template commands are:
1805\begin{tableii}{ll}{command}{Command}{Description}
Greg Ward87da1ea2000-04-21 04:35:25 +00001806 \lineii{include \var{pat1} \var{pat2} ... }
1807 {include all files matching any of the listed patterns}
1808 \lineii{exclude \var{pat1} \var{pat2} ... }
1809 {exclude all files matching any of the listed patterns}
1810 \lineii{recursive-include \var{dir} \var{pat1} \var{pat2} ... }
1811 {include all files under \var{dir} matching any of the listed patterns}
1812 \lineii{recursive-exclude \var{dir} \var{pat1} \var{pat2} ...}
1813 {exclude all files under \var{dir} matching any of the listed patterns}
1814 \lineii{global-include \var{pat1} \var{pat2} ...}
Greg Ward1bbe3292000-06-25 03:14:13 +00001815 {include all files anywhere in the source tree matching\\&
Greg Ward87da1ea2000-04-21 04:35:25 +00001816 any of the listed patterns}
1817 \lineii{global-exclude \var{pat1} \var{pat2} ...}
Greg Ward1bbe3292000-06-25 03:14:13 +00001818 {exclude all files anywhere in the source tree matching\\&
Greg Ward87da1ea2000-04-21 04:35:25 +00001819 any of the listed patterns}
Greg Ward16aafcd2000-04-09 04:06:44 +00001820 \lineii{prune \var{dir}}{exclude all files under \var{dir}}
1821 \lineii{graft \var{dir}}{include all files under \var{dir}}
1822\end{tableii}
Fred Drakeeff9a872000-10-26 16:41:03 +00001823The patterns here are \UNIX-style ``glob'' patterns: \code{*} matches any
Greg Ward16aafcd2000-04-09 04:06:44 +00001824sequence of regular filename characters, \code{?} matches any single
1825regular filename character, and \code{[\var{range}]} matches any of the
1826characters in \var{range} (e.g., \code{a-z}, \code{a-zA-Z},
Greg Wardfacb8db2000-04-09 04:32:40 +00001827\code{a-f0-9\_.}). The definition of ``regular filename character'' is
Fred Drakeeff9a872000-10-26 16:41:03 +00001828platform-specific: on \UNIX{} it is anything except slash; on Windows
1829anything except backslash or colon; on MacOS anything except colon.
Greg Wardb6528972000-09-07 02:40:37 +00001830
Fred Drakeeff9a872000-10-26 16:41:03 +00001831\XXX{Windows and MacOS support not there yet}
Greg Ward16aafcd2000-04-09 04:06:44 +00001832
1833
Fred Drakea09262e2001-03-01 18:35:43 +00001834%\subsection{Creating a built distribution: the
1835% \protect\command{bdist} command family}
1836%\label{bdist-cmds}
Greg Ward16aafcd2000-04-09 04:06:44 +00001837
1838
Fred Drakeab70b382001-08-02 15:13:15 +00001839%\subsubsection{\protect\command{bdist}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001840
Fred Drakeab70b382001-08-02 15:13:15 +00001841%\subsubsection{\protect\command{bdist\_dumb}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001842
Fred Drakeab70b382001-08-02 15:13:15 +00001843%\subsubsection{\protect\command{bdist\_rpm}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001844
Fred Drakeab70b382001-08-02 15:13:15 +00001845%\subsubsection{\protect\command{bdist\_wininst}}
1846
1847
1848\input{sysconfig}
Greg Ward16aafcd2000-04-09 04:06:44 +00001849
1850
Greg Wardabc52162000-02-26 00:52:48 +00001851\end{document}