blob: abf749d72489352bd61332a02473fce2a8da710d [file] [log] [blame]
Greg Wardabc52162000-02-26 00:52:48 +00001\documentclass{howto}
2\usepackage{ltxmarkup}
Greg Wardfacb8db2000-04-09 04:32:40 +00003\usepackage{times}
Greg Ward16aafcd2000-04-09 04:06:44 +00004\usepackage{distutils}
Greg Wardabc52162000-02-26 00:52:48 +00005
Greg Ward16aafcd2000-04-09 04:06:44 +00006\title{Distributing Python Modules}
Greg Wardabc52162000-02-26 00:52:48 +00007
Greg Wardabc52162000-02-26 00:52:48 +00008\author{Greg Ward}
9\authoraddress{E-mail: \email{gward@python.net}}
10
Greg Warde3cca262000-08-31 16:36:31 +000011\makeindex
Greg Ward16aafcd2000-04-09 04:06:44 +000012
Greg Wardabc52162000-02-26 00:52:48 +000013\begin{document}
14
Greg Wardfacb8db2000-04-09 04:32:40 +000015\maketitle
Greg Warde3cca262000-08-31 16:36:31 +000016\begin{abstract}
17 \noindent
18 This document describes the Python Distribution Utilities
19 (``Distutils'') from the module developer's point-of-view, describing
20 how to use the Distutils to make Python modules and extensions easily
21 available to a wider audience with very little overhead for
22 build/release/install mechanics.
23\end{abstract}
24
Greg Wardfacb8db2000-04-09 04:32:40 +000025\tableofcontents
Greg Ward16aafcd2000-04-09 04:06:44 +000026
27\section{Introduction}
Greg Warde78298a2000-04-28 17:12:24 +000028\label{intro}
Greg Ward16aafcd2000-04-09 04:06:44 +000029
30In the past, Python module developers have not had much infrastructure
31support for distributing modules, nor have Python users had much support
32for installing and maintaining third-party modules. With the
33introduction of the Python Distribution Utilities (Distutils for short)
Greg Ward1d8f57a2000-08-05 00:43:11 +000034in Python 1.6, this situation should start to improve.
Greg Ward16aafcd2000-04-09 04:06:44 +000035
36This document only covers using the Distutils to distribute your Python
Greg Ward1d8f57a2000-08-05 00:43:11 +000037modules. Using the Distutils does not tie you to Python 1.6, though:
38the Distutils work just fine with Python 1.5.2, and it is reasonable
39(and expected to become commonplace) to expect users of Python 1.5.2 to
Greg Ward16aafcd2000-04-09 04:06:44 +000040download and install the Distutils separately before they can install
Greg Ward1d8f57a2000-08-05 00:43:11 +000041your modules. Python 1.6 (or later) users, of course, won't have to add
42anything to their Python installation in order to use the Distutils to
43install third-party modules.
Greg Ward16aafcd2000-04-09 04:06:44 +000044
45This document concentrates on the role of developer/distributor: if
Fred Drake01df4532000-06-30 03:36:41 +000046you're looking for information on installing Python modules, you
47should refer to the \citetitle[../inst/inst.html]{Installing Python
48Modules} manual.
Greg Ward16aafcd2000-04-09 04:06:44 +000049
50
Greg Wardfacb8db2000-04-09 04:32:40 +000051\section{Concepts \& Terminology}
Greg Warde78298a2000-04-28 17:12:24 +000052\label{concepts}
Greg Ward16aafcd2000-04-09 04:06:44 +000053
54Using the Distutils is quite simple, both for module developers and for
55users/administrators installing third-party modules. As a developer,
56your responsibilites (apart from writing solid, well-documented and
57well-tested code, of course!) are:
58\begin{itemize}
59\item write a setup script (\file{setup.py} by convention)
60\item (optional) write a setup configuration file
61\item create a source distribution
62\item (optional) create one or more built (binary) distributions
63\end{itemize}
64Each of these tasks is covered in this document.
65
66Not all module developers have access to a multitude of platforms, so
67it's not always feasible to expect them to create a multitude of built
68distributions. It is hoped that a class of intermediaries, called
Greg Ward19c67f82000-06-24 01:33:16 +000069\emph{packagers}, will arise to address this need. Packagers will take
70source distributions released by module developers, build them on one or
71more platforms, and release the resulting built distributions. Thus,
72users on the most popular platforms will be able to install most popular
73Python module distributions in the most natural way for their platform,
74without having to run a single setup script or compile a line of code.
Greg Ward16aafcd2000-04-09 04:06:44 +000075
76
77\subsection{A simple example}
Greg Warde78298a2000-04-28 17:12:24 +000078\label{simple-example}
Greg Ward16aafcd2000-04-09 04:06:44 +000079
80The setup script is usually quite simple, although since it's written in
Greg Ward47f99a62000-09-04 20:07:15 +000081Python, there are no arbitrary limits to what you can do with
82it.\footnote{But be careful about putting arbitrarily expensive
83 operations in your setup script; unlike, say, Autoconf-style configure
84 scripts, the setup script may be run multiple times in the course of
85 building and installing your module distribution. If you need to
86 insert potentially expensive processing steps into the Distutils
87 chain, see section~\ref{extending} on extending the Distutils.} If
Greg Ward1d8f57a2000-08-05 00:43:11 +000088all you want to do is distribute a module called \module{foo}, contained
89in a file \file{foo.py}, then your setup script can be as little as
90this:
Greg Ward16aafcd2000-04-09 04:06:44 +000091\begin{verbatim}
92from distutils.core import setup
93setup (name = "foo",
94 version = "1.0",
95 py_modules = ["foo"])
96\end{verbatim}
Greg Ward370248d2000-06-24 01:45:47 +000097
Greg Ward16aafcd2000-04-09 04:06:44 +000098Some observations:
99\begin{itemize}
Greg Ward370248d2000-06-24 01:45:47 +0000100\item most information that you supply to the Distutils is supplied as
Greg Wardfacb8db2000-04-09 04:32:40 +0000101 keyword arguments to the \function{setup()} function
Greg Ward16aafcd2000-04-09 04:06:44 +0000102\item those keyword arguments fall into two categories: package
103 meta-data (name, version number) and information about what's in the
Greg Ward370248d2000-06-24 01:45:47 +0000104 package (a list of pure Python modules, in this case)
Greg Ward16aafcd2000-04-09 04:06:44 +0000105\item modules are specified by module name, not filename (the same will
106 hold true for packages and extensions)
107\item it's recommended that you supply a little more meta-data, in
108 particular your name, email address and a URL for the project
Greg Ward47f99a62000-09-04 20:07:15 +0000109 (see section~\ref{setup-script} for an example)
Greg Ward16aafcd2000-04-09 04:06:44 +0000110\end{itemize}
111
Greg Ward370248d2000-06-24 01:45:47 +0000112To create a source distribution for this module, you would create a
113setup script, \file{setup.py}, containing the above code, and run:
Greg Ward16aafcd2000-04-09 04:06:44 +0000114\begin{verbatim}
115python setup.py sdist
116\end{verbatim}
117which will create an archive file (e.g., tarball on Unix, zip file on
118Windows) containing your setup script, \file{setup.py}, and your module,
119\file{foo.py}. The archive file will be named \file{Foo-1.0.tar.gz} (or
120\file{.zip}), and will unpack into a directory \file{Foo-1.0}.
121
122If an end-user wishes to install your \module{foo} module, all she has
Greg Ward59d382e2000-05-26 01:04:47 +0000123to do is download \file{Foo-1.0.tar.gz} (or \file{.zip}), unpack it,
Greg Ward16aafcd2000-04-09 04:06:44 +0000124and---from the \file{Foo-1.0} directory---run
125\begin{verbatim}
126python setup.py install
127\end{verbatim}
128which will ultimately copy \file{foo.py} to the appropriate directory
129for third-party modules in their Python installation.
130
131This simple example demonstrates some fundamental concepts of the
132Distutils: first, both developers and installers have the same basic
133user interface, i.e. the setup script. The difference is which
134Distutils \emph{commands} they use: the \command{sdist} command is
135almost exclusively for module developers, while \command{install} is
136more often for installers (although most developers will want to install
137their own code occasionally).
138
Greg Ward16aafcd2000-04-09 04:06:44 +0000139If you want to make things really easy for your users, you can create
140one or more built distributions for them. For instance, if you are
141running on a Windows machine, and want to make things easy for other
142Windows users, you can create an executable installer (the most
143appropriate type of built distribution for this platform) with the
Greg Ward59d382e2000-05-26 01:04:47 +0000144\command{bdist\_wininst} command. For example:
Greg Ward16aafcd2000-04-09 04:06:44 +0000145\begin{verbatim}
Greg Ward59d382e2000-05-26 01:04:47 +0000146python setup.py bdist_wininst
Greg Ward16aafcd2000-04-09 04:06:44 +0000147\end{verbatim}
Greg Ward1d8f57a2000-08-05 00:43:11 +0000148will create an executable installer, \file{Foo-1.0.win32.exe}, in the
149current directory.
Greg Ward16aafcd2000-04-09 04:06:44 +0000150
Greg Ward1d8f57a2000-08-05 00:43:11 +0000151\XXX{not implemented yet}
Greg Ward59d382e2000-05-26 01:04:47 +0000152(Another way to create executable installers for Windows is with the
153\command{bdist\_wise} command, which uses Wise---the commercial
154installer-generator used to create Python's own installer---to create
155the installer. Wise-based installers are more appropriate for large,
156industrial-strength applications that need the full capabilities of a
157``real'' installer. \command{bdist\_wininst} creates a self-extracting
158zip file with a minimal user interface, which is enough for small- to
159medium-sized module collections. You'll need to have version XXX of
Greg Ward370248d2000-06-24 01:45:47 +0000160Wise installed on your system for the \command{bdist\_wise} command to
161work; it's available from \url{http://foo/bar/baz}.)
Greg Ward59d382e2000-05-26 01:04:47 +0000162
Greg Ward47f99a62000-09-04 20:07:15 +0000163Currently (Distutils 0.9.2), the are only other useful built
Greg Ward1d8f57a2000-08-05 00:43:11 +0000164distribution format is RPM, implemented by the \command{bdist\_rpm}
165command. For example, the following command will create an RPM file
166called \file{Foo-1.0.noarch.rpm}:
167\begin{verbatim}
168python setup.py bdist_rpm
169\end{verbatim}
170(This uses the \command{rpm} command, so has to be run on an RPM-based
171system such as Red Hat Linux, SuSE Linux, or Mandrake Linux.)
172
173You can find out what distribution formats are available at any time by
174running
175\begin{verbatim}
176python setup.py bdist --help-formats
177\end{verbatim}
Greg Ward16aafcd2000-04-09 04:06:44 +0000178
179
180\subsection{General Python terminology}
Greg Warde78298a2000-04-28 17:12:24 +0000181\label{python-terms}
Greg Ward16aafcd2000-04-09 04:06:44 +0000182
183If you're reading this document, you probably have a good idea of what
184modules, extensions, and so forth are. Nevertheless, just to be sure
185that everyone is operating from a common starting point, we offer the
186following glossary of common Python terms:
187\begin{description}
188\item[module] the basic unit of code reusability in Python: a block of
Greg Ward1d8f57a2000-08-05 00:43:11 +0000189 code imported by some other code. Three types of modules concern us
190 here: pure Python modules, extension modules, and packages.
Greg Ward16aafcd2000-04-09 04:06:44 +0000191\item[pure Python module] a module written in Python and contained in a
192 single \file{.py} file (and possibly associated \file{.pyc} and/or
193 \file{.pyo} files). Sometimes referred to as a ``pure module.''
194\item[extension module] a module written in the low-level language of
195 the Python implemention: C/C++ for CPython, Java for JPython.
196 Typically contained in a single dynamically loadable pre-compiled
197 file, e.g. a shared object (\file{.so}) file for CPython extensions on
198 Unix, a DLL (given the \file{.pyd} extension) for CPython extensions
Greg Ward1bbe3292000-06-25 03:14:13 +0000199 on Windows, or a Java class file for JPython extensions. (Note that
200 currently, the Distutils only handles C/C++ extensions for CPython.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000201\item[package] a module that contains other modules; typically contained
202 in a directory in the filesystem and distinguished from other
203 directories by the presence of a file \file{\_\_init\_\_.py}.
Greg Ward6153fa12000-05-26 02:24:28 +0000204\item[root package] the root of the hierarchy of packages. (This isn't
205 really a package, since it doesn't have an \file{\_\_init\_\_.py}
206 file. But we have to call it something.) The vast majority of the
207 standard library is in the root package, as are many small, standalone
208 third-party modules that don't belong to a larger module collection.
209 Unlike regular packages, modules in the root package can be found in
210 many directories: in fact, every directory listed in \code{sys.path}
211 can contribute modules to the root package.
Greg Ward16aafcd2000-04-09 04:06:44 +0000212\end{description}
213
214
215\subsection{Distutils-specific terminology}
Greg Warde78298a2000-04-28 17:12:24 +0000216\label{distutils-term}
Greg Ward16aafcd2000-04-09 04:06:44 +0000217
218The following terms apply more specifically to the domain of
219distributing Python modules using the Distutils:
220\begin{description}
221\item[module distribution] a collection of Python modules distributed
222 together as a single downloadable resource and meant to be installed
223 \emph{en masse}. Examples of some well-known module distributions are
224 Numeric Python, PyXML, PIL (the Python Imaging Library), or
225 mxDateTime. (This would be called a \emph{package}, except that term
Greg Ward59d382e2000-05-26 01:04:47 +0000226 is already taken in the Python context: a single module distribution
227 may contain zero, one, or many Python packages.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000228\item[pure module distribution] a module distribution that contains only
229 pure Python modules and packages. Sometimes referred to as a ``pure
230 distribution.''
231\item[non-pure module distribution] a module distribution that contains
232 at least one extension module. Sometimes referred to as a ``non-pure
233 distribution.''
234\item[distribution root] the top-level directory of your source tree (or
235 source distribution); the directory where \file{setup.py} exists and
236 is run from
237\end{description}
238
239
240\section{Writing the Setup Script}
Greg Warde78298a2000-04-28 17:12:24 +0000241\label{setup-script}
Greg Ward16aafcd2000-04-09 04:06:44 +0000242
243The setup script is the centre of all activity in building,
244distributing, and installing modules using the Distutils. The main
245purpose of the setup script is to describe your module distribution to
Greg Wardd5767a52000-04-19 22:48:09 +0000246the Distutils, so that the various commands that operate on your modules
Greg Ward59d382e2000-05-26 01:04:47 +0000247do the right thing. As we saw in section~\ref{simple-example} above,
248the setup script consists mainly of a call to \function{setup()}, and
Greg Ward1bbe3292000-06-25 03:14:13 +0000249most information supplied to the Distutils by the module developer is
250supplied as keyword arguments to \function{setup()}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000251
252Here's a slightly more involved example, which we'll follow for the next
253couple of sections: the Distutils' own setup script. (Keep in mind that
Greg Ward1d8f57a2000-08-05 00:43:11 +0000254although the Distutils are included with Python 1.6 and later, they also
255have an independent existence so that Python 1.5.2 users can use them to
256install other module distributions. The Distutils' own setup script,
257shown here, is used to install the package into Python 1.5.2.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000258
259\begin{verbatim}
260#!/usr/bin/env python
261
262from distutils.core import setup
263
264setup (name = "Distutils",
265 version = "1.0",
Greg Ward1d8f57a2000-08-05 00:43:11 +0000266 description = "Python Distribution Utilities",
Greg Ward16aafcd2000-04-09 04:06:44 +0000267 author = "Greg Ward",
268 author_email = "gward@python.net",
269 url = "http://www.python.org/sigs/distutils-sig/",
270
271 packages = ['distutils', 'distutils.command'],
272 )
273\end{verbatim}
274There are only two differences between this and the trivial one-file
Greg Warde78298a2000-04-28 17:12:24 +0000275distribution presented in section~\ref{simple-example}: more
Greg Ward16aafcd2000-04-09 04:06:44 +0000276meta-data, and the specification of pure Python modules by package,
277rather than by module. This is important since the Distutils consist of
278a couple of dozen modules split into (so far) two packages; an explicit
279list of every module would be tedious to generate and difficult to
280maintain.
281
Greg Ward46b98e32000-04-14 01:53:36 +0000282Note that any pathnames (files or directories) supplied in the setup
283script should be written using the Unix convention, i.e.
284slash-separated. The Distutils will take care of converting this
Greg Ward59d382e2000-05-26 01:04:47 +0000285platform-neutral representation into whatever is appropriate on your
Greg Ward46b98e32000-04-14 01:53:36 +0000286current platform before actually using the pathname. This makes your
287setup script portable across operating systems, which of course is one
288of the major goals of the Distutils. In this spirit, all pathnames in
Greg Ward59d382e2000-05-26 01:04:47 +0000289this document are slash-separated (Mac OS programmers should keep in
290mind that the \emph{absence} of a leading slash indicates a relative
291path, the opposite of the Mac OS convention with colons).
Greg Ward46b98e32000-04-14 01:53:36 +0000292
Greg Ward16aafcd2000-04-09 04:06:44 +0000293
Greg Ward2afffd42000-08-06 20:37:24 +0000294\subsection{Listing whole packages}
295\label{listing-packages}
Greg Ward16aafcd2000-04-09 04:06:44 +0000296
297The \option{packages} option tells the Distutils to process (build,
298distribute, install, etc.) all pure Python modules found in each package
299mentioned in the \option{packages} list. In order to do this, of
300course, there has to be a correspondence between package names and
301directories in the filesystem. The default correspondence is the most
Greg Ward1ecc2512000-04-19 22:36:24 +0000302obvious one, i.e. package \module{distutils} is found in the directory
Greg Ward16aafcd2000-04-09 04:06:44 +0000303\file{distutils} relative to the distribution root. Thus, when you say
304\code{packages = ['foo']} in your setup script, you are promising that
305the Distutils will find a file \file{foo/\_\_init\_\_.py} (which might
306be spelled differently on your system, but you get the idea) relative to
307the directory where your setup script lives. (If you break this
308promise, the Distutils will issue a warning but process the broken
309package anyways.)
310
311If you use a different convention to lay out your source directory,
312that's no problem: you just have to supply the \option{package\_dir}
313option to tell the Distutils about your convention. For example, say
Greg Ward1d8f57a2000-08-05 00:43:11 +0000314you keep all Python source under \file{lib}, so that modules in the
315``root package'' (i.e., not in any package at all) are right in
316\file{lib}, modules in the \module{foo} package are in \file{lib/foo},
317and so forth. Then you would put
Greg Ward16aafcd2000-04-09 04:06:44 +0000318\begin{verbatim}
319package_dir = {'': 'lib'}
320\end{verbatim}
321in your setup script. (The keys to this dictionary are package names,
Greg Ward1d8f57a2000-08-05 00:43:11 +0000322and an empty package name stands for the root package. The values are
323directory names relative to your distribution root.) In this case, when
324you say \code{packages = ['foo']}, you are promising that the file
Greg Ward16aafcd2000-04-09 04:06:44 +0000325\file{lib/foo/\_\_init\_\_.py} exists.
326
Greg Ward1ecc2512000-04-19 22:36:24 +0000327Another possible convention is to put the \module{foo} package right in
328\file{lib}, the \module{foo.bar} package in \file{lib/bar}, etc. This
Greg Ward16aafcd2000-04-09 04:06:44 +0000329would be written in the setup script as
330\begin{verbatim}
331package_dir = {'foo': 'lib'}
332\end{verbatim}
Greg Ward59d382e2000-05-26 01:04:47 +0000333A \code{\var{package}: \var{dir}} entry in the \option{package\_dir}
334dictionary implicitly applies to all packages below \var{package}, so
335the \module{foo.bar} case is automatically handled here. In this
336example, having \code{packages = ['foo', 'foo.bar']} tells the Distutils
337to look for \file{lib/\_\_init\_\_.py} and
338\file{lib/bar/\_\_init\_\_.py}. (Keep in mind that although
339\option{package\_dir} applies recursively, you must explicitly list all
340packages in \option{packages}: the Distutils will \emph{not} recursively
341scan your source tree looking for any directory with an
342\file{\_\_init\_\_.py} file.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000343
344
345\subsection{Listing individual modules}
Greg Warde78298a2000-04-28 17:12:24 +0000346\label{listing-modules}
Greg Ward16aafcd2000-04-09 04:06:44 +0000347
348For a small module distribution, you might prefer to list all modules
349rather than listing packages---especially the case of a single module
350that goes in the ``root package'' (i.e., no package at all). This
Greg Warde78298a2000-04-28 17:12:24 +0000351simplest case was shown in section~\ref{simple-example}; here is a
Greg Ward16aafcd2000-04-09 04:06:44 +0000352slightly more involved example:
353\begin{verbatim}
354py_modules = ['mod1', 'pkg.mod2']
355\end{verbatim}
356This describes two modules, one of them in the ``root'' package, the
Greg Wardd5767a52000-04-19 22:48:09 +0000357other in the \module{pkg} package. Again, the default package/directory
358layout implies that these two modules can be found in \file{mod1.py} and
359\file{pkg/mod2.py}, and that \file{pkg/\_\_init\_\_.py} exists as well.
Greg Ward2afffd42000-08-06 20:37:24 +0000360And again, you can override the package/directory correspondence using
361the \option{package\_dir} option.
Greg Ward59d382e2000-05-26 01:04:47 +0000362
363
364\subsection{Describing extension modules}
Greg Ward1365a302000-08-31 14:47:05 +0000365\label{describing-extensions}
Greg Ward59d382e2000-05-26 01:04:47 +0000366
Greg Ward2afffd42000-08-06 20:37:24 +0000367Just as writing Python extension modules is a bit more complicated than
368writing pure Python modules, describing them to the Distutils is a bit
369more complicated. Unlike pure modules, it's not enough just to list
370modules or packages and expect the Distutils to go out and find the
371right files; you have to specify the extension name, source file(s), and
372any compile/link requirements (include directories, libraries to link
373with, etc.).
374
375All of this is done through another keyword argument to
376\function{setup()}, the \option{extensions} option. \option{extensions}
377is just a list of \class{Extension} instances, each of which describes a
378single extension module. Suppose your distribution includes a single
379extension, called \module{foo} and implemented by \file{foo.c}. If no
380additional instructions to the compiler/linker are needed, describing
381this extension is quite simple:
382\begin{verbatim}
383Extension("foo", ["foo.c"])
384\end{verbatim}
385The \class{Extension} class can be imported from
386\module{distutils.core}, along with \function{setup()}. Thus, the setup
387script for a module distribution that contains only this one extension
388and nothing else might be:
389\begin{verbatim}
390from distutils.core import setup, Extension
391setup(name = "foo", version = "1.0",
392 extensions = [Extension("foo", ["foo.c"])])
393\end{verbatim}
394
395The \class{Extension} class (actually, the underlying extension-building
396machinery implemented by the \command{built\_ext} command) supports a
397great deal of flexibility in describing Python extensions, which is
398explained in the following sections.
399
400
401\subsubsection{Extension names and packages}
402
403The first argument to the \class{Extension} constructor is always the
404name of the extension, including any package names. For example,
405\begin{verbatim}
406Extension("foo", ["src/foo1.c", "src/foo2.c"])
407\end{verbatim}
408describes an extension that lives in the root package, while
409\begin{verbatim}
410Extension("pkg.foo", ["src/foo1.c", "src/foo2.c"])
411\end{verbatim}
412describes the same extension in the \module{pkg} package. The source
413files and resulting object code are identical in both cases; the only
414difference is where in the filesystem (and therefore where in Python's
415namespace hierarchy) the resulting extension lives.
416
417If you have a number of extensions all in the same package (or all under
418the same base package), use the \option{ext\_package} keyword argument
419to \function{setup()}. For example,
420\begin{verbatim}
421setup(...
422 ext_package = "pkg",
423 extensions = [Extension("foo", ["foo.c"]),
424 Extension("subpkg.bar", ["bar.c"])]
425 )
426\end{verbatim}
427will compile \file{foo.c} to the extension \module{pkg.foo}, and
428\file{bar.c} to \module{pkg.subpkg.bar}.
429
430
431\subsubsection{Extension source files}
432
433The second argument to the \class{Extension} constructor is a list of
434source files. Since the Distutils currently only support C/C++
435extensions, these are normally C/C++ source files. (Be sure to use
436appropriate extensions to distinguish C++ source files: \file{.cc} and
437\file{.cpp} seem to be recognized by both Unix and Windows compilers.)
438
439However, you can also include SWIG interface (\file{.i}) files in the
440list; the \command{build\_ext} command knows how to deal with SWIG
441extensions: it will run SWIG on the interface file and compile the
442resulting C/C++ file into your extension.
443
444\XXX{SWIG support is rough around the edges and largely untested;
445 especially SWIG support of C++ extensions! Explain in more detail
446 here when the interface firms up.}
447
448On some platforms, you can include non-source files that are processed
449by the compiler and included in your extension. Currently, this just
450means Windows resource files for Visual C++. \XXX{get more detail on
451 this feature from Thomas Heller!}
452
453
454\subsubsection{Preprocessor options}
455
456Three optional arguments to \class{Extension} will help if you need to
457specify include directories to search or preprocessor macros to
458define/undefine: \code{include\_dirs}, \code{define\_macros}, and
459\code{undef\_macros}.
460
461For example, if your extension requires header files in the
462\file{include} directory under your distribution root, use the
463\code{include\_dirs} option:
464\begin{verbatim}
465Extension("foo", ["foo.c"], include_dirs=["include"])
466\end{verbatim}
467
468You can specify absolute directories there; if you know that your
469extension will only be built on Unix systems with X11R6 installed to
470\file{/usr}, you can get away with
471\begin{verbatim}
472Extension("foo", ["foo.c"], include_dirs=["/usr/include/X11"])
473\end{verbatim}
474You should avoid this sort of non-portable usage if you plan to
475distribute your code: it's probably better to write your code to include
476(e.g.) \code{<X11/Xlib.h>}.
477
478If you need to include header files from some other Python extension,
479you can take advantage of the fact that the Distutils install extension
480header files in a consistent way. For example, the Numerical Python
481header files are installed (on a standard Unix installation) to
482\file{/usr/local/include/python1.5/Numerical}. (The exact location will
483differ according to your platform and Python installation.) Since the
484Python include directory---\file{/usr/local/include/python1.5} in this
485case---is always included in the search path when building Python
486extensions, the best approach is to include (e.g.)
487\code{<Numerical/arrayobject.h>}. If you insist on putting the
488\file{Numerical} include directory right into your header search path,
489though, you can find that directory using the Distutils
490\module{sysconfig} module:
491\begin{verbatim}
492from distutils.sysconfig import get_python_inc
493incdir = os.path.join(get_python_inc(plat_specific=1), "Numerical")
494setup(...,
495 Extension(..., include_dirs=[incdir]))
496\end{verbatim}
497Even though this is quite portable---it will work on any Python
498installation, regardless of platform---it's probably easier to just
499write your C code in the sensible way.
500
501You can define and undefine pre-processor macros with the
502\code{define\_macros} and \code{undef\_macros} options.
503\code{define\_macros} takes a list of \code{(name, value)} tuples, where
504\code{name} is the name of the macro to define (a string) and
505\code{value} is its value: either a string or \code{None}. (Defining a
506macro \code{FOO} to \code{None} is the equivalent of a bare
507\code{\#define FOO} in your C source: with most compilers, this sets
508\code{FOO} to the string \code{1}.) \code{undef\_macros} is just
509a list of macros to undefine.
510
511For example:
512\begin{verbatim}
513Extension(...,
514 define_macros=[('NDEBUG', '1')],
515 ('HAVE_STRFTIME', None),
516 undef_macros=['HAVE_FOO', 'HAVE_BAR'])
517\end{verbatim}
518is the equivalent of having this at the top of every C source file:
519\begin{verbatim}
520#define NDEBUG 1
521#define HAVE_STRFTIME
522#undef HAVE_FOO
523#undef HAVE_BAR
524\end{verbatim}
525
526
527\subsubsection{Library options}
528
529You can also specify the libraries to link against when building your
530extension, and the directories to search for those libraries. The
531\code{libraries} option is a list of libraries to link against,
532\code{library\_dirs} is a list of directories to search for libraries at
533link-time, and \code{runtime\_library\_dirs} is a list of directories to
534search for shared (dynamically loaded) libraries at run-time.
535
536For example, if you need to link against libraries known to be in the
537standard library search path on target systems
538\begin{verbatim}
539Extension(...,
540 libraries=["gdbm", "readline"])
541\end{verbatim}
542
543If you need to link with libraries in a non-standard location, you'll
544have to include the location in \code{library\_dirs}:
545\begin{verbatim}
546Extension(...,
547 library_dirs=["/usr/X11R6/lib"],
548 libraries=["X11", "Xt"])
549\end{verbatim}
550(Again, this sort of non-portable construct should be avoided if you
551intend to distribute your code.)
552
553\XXX{still undocumented: extra\_objects, extra\_compile\_args,
554 extra\_link\_args, export\_symbols---none of which are frequently
555 needed, some of which might be completely unnecessary!}
Greg Ward16aafcd2000-04-09 04:06:44 +0000556
557
558\section{Writing the Setup Configuration File}
Greg Warde78298a2000-04-28 17:12:24 +0000559\label{setup-config}
Greg Ward16aafcd2000-04-09 04:06:44 +0000560
Greg Ward16aafcd2000-04-09 04:06:44 +0000561Often, it's not possible to write down everything needed to build a
Greg Ward47f99a62000-09-04 20:07:15 +0000562distribution \emph{a priori}: you may need to get some information from
563the user, or from the user's system, in order to proceed. As long as
564that information is fairly simple---a list of directories to search for
565C header files or libraries, for example---then providing a
566configuration file, \file{setup.cfg}, for users to edit is a cheap and
567easy way to solicit it. Configuration files also let you provide
568default values for any command option, which the installer can then
569override either on the command-line or by editing the config file.
Greg Ward16aafcd2000-04-09 04:06:44 +0000570
Greg Ward47f99a62000-09-04 20:07:15 +0000571(If you have more advanced needs, such as determining which extensions
572to build based on what capabilities are present on the target system,
573then you need the Distutils ``auto-configuration'' facility. This
574started to appear in Distutils 0.9 but, as of this writing, isn't mature
575or stable enough yet for real-world use.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000576
Greg Ward47f99a62000-09-04 20:07:15 +0000577\XXX{should reference description of distutils config files in
578 ``Installing'' manual here}
579
580The setup configuration file is a useful middle-ground between the setup
581script---which, ideally, would be opaque to installers\footnote{This
582 ideal probably won't be achieved until auto-configuration is fully
583 supported by the Distutils.}---and the command-line to the setup
584script, which is outside of your control and entirely up to the
585installer. In fact, \file{setup.cfg} (and any other Distutils
586configuration files present on the target system) are processed after
587the contents of the setup script, but before the command-line. This has
588several useful consequences:
589\begin{itemize}
590\item installers can override some of what you put in \file{setup.py} by
591 editing \file{setup.cfg}
592\item you can provide non-standard defaults for options that are not
593 easily set in \file{setup.py}
594\item installers can override anything in \file{setup.cfg} using the
595 command-line options to \file{setup.py}
596\end{itemize}
597
598The basic syntax of the configuration file is simple:
599\begin{verbatim}
600[command]
601option=value
602...
603\end{verbatim}
604where \var{command} is one of the Distutils commands (e.g.
605\command{build\_py}, \command{install}), and \var{option} is one of the
606options that command supports. Any number of options can be supplied
607for each command, and any number of command sections can be included in
608the file. Blank lines are ignored, as are comments (from a \verb+#+
609character to end-of-line). Long option values can be split across
610multiple lines simply by indenting the continuation lines.
611
612You can find out the list of options supported by a particular command
613with the universal \longprogramopt{help} option, e.g.
614\begin{verbatim}
615> python setup.py --help build_ext
616[...]
617Options for 'build_ext' command:
618 --build-lib (-b) directory for compiled extension modules
619 --build-temp (-t) directory for temporary files (build by-products)
620 --inplace (-i) ignore build-lib and put compiled extensions into the
621 source directory alongside your pure Python modules
622 --include-dirs (-I) list of directories to search for header files
623 --define (-D) C preprocessor macros to define
624 --undef (-U) C preprocessor macros to undefine
625[...]
626\end{verbatim}
627Or consult section \ref{reference} of this document (the command
628reference).
629
630Note that an option spelled \longprogramopt{foo-bar} on the command-line
631is spelled \option{foo\_bar} in configuration files.
632
633For example, say you want your extensions to be built
634``in-place''---that is, you have an extension \module{pkg.ext}, and you
635want the compiled extension file (\file{ext.so} on Unix, say) to be put
636in the same source directory as your pure Python modules
637\module{pkg.mod1} and \module{pkg.mod2}. You can always use the
638\longprogramopt{inplace} option on the command-line to ensure this:
639\begin{verbatim}
640python setup.py build_ext --inplace
641\end{verbatim}
642But this requires that you always specify the \command{build\_ext}
643command explicitly, and remember to provide \longprogramopt{inplace}.
644An easier way is to ``set and forget'' this option, by encoding it in
645\file{setup.cfg}, the configuration file for this distribution:
646\begin{verbatim}
647[build_ext]
648inplace=1
649\end{verbatim}
650This will affect all builds of this module distribution, whether or not
651you explcitly specify \command{build\_ext}. If you include
652\file{setup.cfg} in your source distribution, it will also affect
653end-user builds---which is probably a bad idea for this option, since
654always building extensions in-place would break installation of the
655module distribution. In certain peculiar cases, though, modules are
656built right in their installation directory, so this is conceivably a
657useful ability. (Distributing extensions that expect to be built in
658their installation directory is almost always a bad idea, though.)
659
660Another example: certain commands take a lot of options that don't
661change from run-to-run; for example, \command{bdist\_rpm} needs to know
662everything required to generate a ``spec'' file for creating an RPM
663distribution. Some of this information comes from the setup script, and
664some is automatically generated by the Distutils (such as the list of
665files installed). But some of it has to be supplied as options to
666\command{bdist\_rpm}, which would be very tedious to do on the
667command-line for every run. Hence, here is a snippet from the
668Distutils' own \file{setup.cfg}:
669\begin{verbatim}
670[bdist_rpm]
671release = 1
672packager = Greg Ward <gward@python.net>
673doc_files = CHANGES.txt
674 README.txt
675 USAGE.txt
676 doc/
677 examples/
678\end{verbatim}
679Note that the \option{doc\_files} option is simply a
680whitespace-separated string split across multiple lines for readability.
Greg Ward16aafcd2000-04-09 04:06:44 +0000681
682
683\section{Creating a Source Distribution}
Greg Warde78298a2000-04-28 17:12:24 +0000684\label{source-dist}
Greg Ward16aafcd2000-04-09 04:06:44 +0000685
Greg Warde78298a2000-04-28 17:12:24 +0000686As shown in section~\ref{simple-example}, you use the
Greg Ward16aafcd2000-04-09 04:06:44 +0000687\command{sdist} command to create a source distribution. In the
688simplest case,
689\begin{verbatim}
690python setup.py sdist
691\end{verbatim}
Greg Ward19c67f82000-06-24 01:33:16 +0000692(assuming you haven't specified any \command{sdist} options in the setup
693script or config file), \command{sdist} creates the archive of the
Greg Ward16aafcd2000-04-09 04:06:44 +0000694default format for the current platform. The default formats are:
695\begin{tableii}{ll}{textrm}%
696 {Platform}{Default archive format for source distributions}
697 \lineii{Unix}{gzipped tar file (\file{.tar.gz})}
698 \lineii{Windows}{zip file}
699\end{tableii}
Greg Wardd5767a52000-04-19 22:48:09 +0000700You can specify as many formats as you like using the
701\longprogramopt{formats} option, for example:
Greg Ward16aafcd2000-04-09 04:06:44 +0000702\begin{verbatim}
703python setup.py sdist --formats=gztar,zip
704\end{verbatim}
705to create a gzipped tarball and a zip file. The available formats are:
Greg Ward46b98e32000-04-14 01:53:36 +0000706\begin{tableiii}{l|l|c}{code}%
707 {Format}{Description}{Notes}
Greg Ward47f99a62000-09-04 20:07:15 +0000708 \lineiii{zip}{zip file (\file{.zip})}{(1),(2)}
709 \lineiii{gztar}{gzip'ed tar file (\file{.tar.gz})}{(3),(4)}
710 \lineiii{bztar}{bzip2'ed tar file (\file{.tar.gz})}{(4)}
711 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(4)}
Greg Ward46b98e32000-04-14 01:53:36 +0000712 \lineiii{tar}{tar file (\file{.tar})}{}
713\end{tableiii}
714
715\noindent Notes:
716\begin{description}
717\item[(1)] default on Windows
Greg Ward47f99a62000-09-04 20:07:15 +0000718\item[(2)] under both Unix and Windows, requires either external
719 Info-ZIP utility \emph{or} the \module{zipfile} module
720\item[(3)] default on Unix
721\item[(4)] requires external utilities: \program{tar} and possibly one
722 of \program{gzip}, \program{bzip2}, or \program{compress}
Greg Ward46b98e32000-04-14 01:53:36 +0000723\end{description}
Greg Ward16aafcd2000-04-09 04:06:44 +0000724
725
726\subsection{The manifest and manifest template}
Greg Warde78298a2000-04-28 17:12:24 +0000727\label{manifest}
Greg Ward16aafcd2000-04-09 04:06:44 +0000728
729Without any additional information, the \command{sdist} command puts a
730minimal set of files into the source distribution:
731\begin{itemize}
Greg Wardfacb8db2000-04-09 04:32:40 +0000732\item all Python source files implied by the \option{py\_modules} and
Greg Ward16aafcd2000-04-09 04:06:44 +0000733 \option{packages} options
Greg Wardfacb8db2000-04-09 04:32:40 +0000734\item all C source files mentioned in the \option{ext\_modules} or
Greg Ward16aafcd2000-04-09 04:06:44 +0000735 \option{libraries} options (\XXX{getting C library sources currently
Greg Wardfacb8db2000-04-09 04:32:40 +0000736 broken -- no get\_source\_files() method in build\_clib.py!})
Greg Ward16aafcd2000-04-09 04:06:44 +0000737\item anything that looks like a test script: \file{test/test*.py}
738 (currently, the Distutils don't do anything with test scripts except
739 include them in source distributions, but in the future there will be
740 a standard for testing Python module distributions)
741\item \file{README.txt} (or \file{README}) and \file{setup.py}
742\end{itemize}
743Sometimes this is enough, but usually you will want to specify
744additional files to distribute. The typical way to do this is to write
745a \emph{manifest template}, called \file{MANIFEST.in} by default. The
746\command{sdist} command processes this template and generates a manifest
747file, \file{MANIFEST}. (If you prefer, you can skip the manifest
748template and generate the manifest yourself: it just lists one file per
749line.)
750
751The manifest template has one command per line, where each command
752specifies a set of files to include or exclude from the source
753distribution. For an example, again we turn to the Distutils' own
754manifest template:
755\begin{verbatim}
756include *.txt
Greg Ward87da1ea2000-04-21 04:35:25 +0000757recursive-include examples *.txt *.py
Greg Ward16aafcd2000-04-09 04:06:44 +0000758prune examples/sample?/build
759\end{verbatim}
760The meanings should be fairly clear: include all files in the
761distribution root matching \code{*.txt}, all files anywhere under the
762\file{examples} directory matching \code{*.txt} or \code{*.py}, and
763exclude all directories matching \code{examples/sample?/build}. There
764are several other commands available in the manifest template
Greg Warde78298a2000-04-28 17:12:24 +0000765mini-language; see section~\ref{sdist-cmd}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000766
767The order of commands in the manifest template very much matters:
768initially, we have the list of default files as described above, and
769each command in the template adds to or removes from that list of files.
770When we have fully processed the manifest template, we have our complete
771list of files. This list is written to the manifest for future
772reference, and then used to build the source distribution archive(s).
773
Greg Ward46b98e32000-04-14 01:53:36 +0000774Following the Distutils' own manifest template, let's trace how the
Greg Ward47f99a62000-09-04 20:07:15 +0000775\command{sdist} command builds the list of files to include in the
Greg Ward46b98e32000-04-14 01:53:36 +0000776Distutils source distribution:
Greg Ward16aafcd2000-04-09 04:06:44 +0000777\begin{enumerate}
778\item include all Python source files in the \file{distutils} and
779 \file{distutils/command} subdirectories (because packages
780 corresponding to those two directories were mentioned in the
781 \option{packages} option in the setup script)
782\item include \file{test/test*.py} (always included)
783\item include \file{README.txt} and \file{setup.py} (always included)
784\item include \file{*.txt} in the distribution root (this will find
785 \file{README.txt} a second time, but such redundancies are weeded out
786 later)
787\item in the sub-tree under \file{examples}, include anything matching
788 \file{*.txt}
789\item in the sub-tree under \file{examples}, include anything matching
790 \file{*.py}
791\item remove all files in the sub-trees starting at directories matching
792 \file{examples/sample?/build}---this may exclude files included by the
793 previous two steps, so it's important that the \code{prune} command in
794 the manifest template comes after the two \code{recursive-include}
795 commands
Greg Wardfacb8db2000-04-09 04:32:40 +0000796\end{enumerate}
Greg Ward16aafcd2000-04-09 04:06:44 +0000797
Greg Ward46b98e32000-04-14 01:53:36 +0000798Just like in the setup script, file and directory names in the manifest
799template should always be slash-separated; the Distutils will take care
800of converting them to the standard representation on your platform.
801That way, the manifest template is portable across operating systems.
802
Greg Ward16aafcd2000-04-09 04:06:44 +0000803
804\subsection{Manifest-related options}
Greg Warde78298a2000-04-28 17:12:24 +0000805\label{manifest-options}
Greg Ward16aafcd2000-04-09 04:06:44 +0000806
807The normal course of operations for the \command{sdist} command is as
808follows:
809\begin{itemize}
Greg Ward46b98e32000-04-14 01:53:36 +0000810\item if the manifest file, \file{MANIFEST} doesn't exist, read
811 \file{MANIFEST.in} and create the manifest
Greg Ward1d8f57a2000-08-05 00:43:11 +0000812\item if either \file{MANIFEST.in} or the setup script (\file{setup.py})
813 are more recent than \file{MANIFEST}, recreate \file{MANIFEST} by
814 reading \file{MANIFEST.in}
Greg Ward16aafcd2000-04-09 04:06:44 +0000815\item use the list of files now in \file{MANIFEST} (either just
816 generated or read in) to create the source distribution archive(s)
817\end{itemize}
818There are a couple of options that modify this behaviour.
819
820First, you might want to force the manifest to be regenerated---for
821example, if you have added or removed files or directories that match an
822existing pattern in the manifest template, you should regenerate the
823manifest:
824\begin{verbatim}
825python setup.py sdist --force-manifest
826\end{verbatim}
Greg Ward16aafcd2000-04-09 04:06:44 +0000827
828Or, you might just want to (re)generate the manifest, but not create a
829source distribution:
830\begin{verbatim}
831python setup.py sdist --manifest-only
832\end{verbatim}
Greg Warda021aca2000-04-19 22:34:11 +0000833(\longprogramopt{manifest-only} implies \longprogramopt{force-manifest}.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000834
835If you don't want to use the default file set, you can supply the
Greg Wardd5767a52000-04-19 22:48:09 +0000836\longprogramopt{no-defaults} option. If you use
837\longprogramopt{no-defaults} and don't supply a manifest template (or
838it's empty, or nothing matches the patterns in it), then your source
839distribution will be empty.
Greg Ward16aafcd2000-04-09 04:06:44 +0000840
841
842\section{Creating Built Distributions}
Greg Warde78298a2000-04-28 17:12:24 +0000843\label{built-dist}
Greg Ward16aafcd2000-04-09 04:06:44 +0000844
Greg Ward46b98e32000-04-14 01:53:36 +0000845A ``built distribution'' is what you're probably used to thinking of
846either as a ``binary package'' or an ``installer'' (depending on your
847background). It's not necessarily binary, though, because it might
848contain only Python source code and/or byte-code; and we don't call it a
849package, because that word is already spoken for in Python. (And
850``installer'' is a term specific to the Windows world. \XXX{do Mac
851 people use it?})
Greg Ward16aafcd2000-04-09 04:06:44 +0000852
Greg Ward46b98e32000-04-14 01:53:36 +0000853A built distribution is how you make life as easy as possible for
854installers of your module distribution: for users of RPM-based Linux
855systems, it's a binary RPM; for Windows users, it's an executable
856installer; for Debian-based Linux users, it's a Debian package; and so
857forth. Obviously, no one person will be able to create built
858distributions for every platform under the sun, so the Distutils is
859designed to enable module developers to concentrate on their
860specialty---writing code and creating source distributions---while an
861intermediary species of \emph{packager} springs up to turn source
Greg Ward19c67f82000-06-24 01:33:16 +0000862distributions into built distributions for as many platforms as there
Greg Ward46b98e32000-04-14 01:53:36 +0000863are packagers.
864
865Of course, the module developer could be his own packager; or the
866packager could be a volunteer ``out there'' somewhere who has access to
867a platform which the original developer does not; or it could be
868software periodically grabbing new source distributions and turning them
869into built distributions for as many platforms as the software has
870access to. Regardless of the nature of the beast, a packager uses the
871setup script and the \command{bdist} command family to generate built
872distributions.
873
874As a simple example, if I run the following command in the Distutils
875source tree:
876\begin{verbatim}
877python setup.py bdist
878\end{verbatim}
879then the Distutils builds my module distribution (the Distutils itself
880in this case), does a ``fake'' installation (also in the \file{build}
881directory), and creates the default type of built distribution for my
Greg Ward1d8f57a2000-08-05 00:43:11 +0000882platform. Currently, the default format for built distributions is a
883``dumb'' archive---tarball on Unix, ZIP file on Windows. (These are
884called ``dumb'' built distributions, because they must be unpacked in a
885specific location to work.)
886
887Thus, the above command on a Unix system creates
888\file{Distutils-0.9.1.\filevar{plat}.tar.gz}; unpacking this tarball
889from the root of the filesystemq installs the Distutils just as though
890you had downloaded the source distribution and run \code{python setup.py
891 install}. (Assuming that the target system has their Python
892installation laid out the same as you do---another reason these are
893called ``dumb'' distributions.) Obviously, for pure Python
894distributions, this isn't a huge win---but for non-pure distributions,
895which include extensions that would need to be compiled, it can mean the
896difference between someone being able to use your extensions or not.
Greg Ward46b98e32000-04-14 01:53:36 +0000897
898\XXX{filenames are inaccurate here!}
899
Greg Wardd5767a52000-04-19 22:48:09 +0000900The \command{bdist} command has a \longprogramopt{format} option,
Greg Ward1d8f57a2000-08-05 00:43:11 +0000901similar to the \command{sdist} command, which you can use to select the
902types of built distribution to generate: for example,
Greg Ward46b98e32000-04-14 01:53:36 +0000903\begin{verbatim}
904python setup.py bdist --format=zip
905\end{verbatim}
906would, when run on a Unix system, create
Greg Ward1d8f57a2000-08-05 00:43:11 +0000907\file{Distutils-0.8.\filevar{plat}.zip}---again, this archive would be
908unpacked from the root directory to install the Distutils.
Greg Ward46b98e32000-04-14 01:53:36 +0000909
910The available formats for built distributions are:
911\begin{tableiii}{l|l|c}{code}%
912 {Format}{Description}{Notes}
Greg Ward1d8f57a2000-08-05 00:43:11 +0000913 \lineiii{zip}{zip file (\file{.zip})}{}
914 \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1)}
Greg Ward46b98e32000-04-14 01:53:36 +0000915 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{}
916 \lineiii{tar}{tar file (\file{.tar})}{}
Greg Ward1d8f57a2000-08-05 00:43:11 +0000917 \lineiii{rpm}{RPM}{}
918 \lineiii{srpm}{source RPM}{\XXX{to do!}}
919 \lineiii{wininst}{self-extracting ZIP file for Windows}{(2)}
920 %\lineiii{wise}{Wise installer for Windows}{(3)}
Greg Ward46b98e32000-04-14 01:53:36 +0000921\end{tableiii}
922
923\noindent Notes:
924\begin{description}
Greg Ward1d8f57a2000-08-05 00:43:11 +0000925\item[(1)] default on Unix
926\item[(2)] default on Windows \XXX{to-do!}
927%\item[(3)] not implemented yet
Greg Ward46b98e32000-04-14 01:53:36 +0000928\end{description}
929
930You don't have to use the \command{bdist} command with the
Greg Wardd5767a52000-04-19 22:48:09 +0000931\longprogramopt{formats} option; you can also use the command that
Greg Ward1d8f57a2000-08-05 00:43:11 +0000932directly implements the format you're interested in. Some of these
Greg Ward46b98e32000-04-14 01:53:36 +0000933\command{bdist} ``sub-commands'' actually generate several similar
934formats; for instance, the \command{bdist\_dumb} command generates all
935the ``dumb'' archive formats (\code{tar}, \code{ztar}, \code{gztar}, and
936\code{zip}), and \command{bdist\_rpm} generates both binary and source
937RPMs. The \command{bdist} sub-commands, and the formats generated by
938each, are:
939\begin{tableii}{l|l}{command}%
940 {Command}{Formats}
941 \lineii{bdist\_dumb}{tar, ztar, gztar, zip}
942 \lineii{bdist\_rpm}{rpm, srpm}
Greg Ward1d8f57a2000-08-05 00:43:11 +0000943 \lineii{bdist\_wininst}{wininst}
944 %\lineii{bdist\_wise}{wise}
Greg Ward46b98e32000-04-14 01:53:36 +0000945\end{tableii}
Greg Ward16aafcd2000-04-09 04:06:44 +0000946
947\section{Examples}
Greg Warde78298a2000-04-28 17:12:24 +0000948\label{examples}
Greg Ward16aafcd2000-04-09 04:06:44 +0000949
950
951\subsection{Pure Python distribution (by module)}
Greg Warde78298a2000-04-28 17:12:24 +0000952\label{pure-mod}
Greg Ward16aafcd2000-04-09 04:06:44 +0000953
954
955\subsection{Pure Python distribution (by package)}
Greg Warde78298a2000-04-28 17:12:24 +0000956\label{pure-pkg}
Greg Ward16aafcd2000-04-09 04:06:44 +0000957
958
959\subsection{Single extension module}
Greg Warde78298a2000-04-28 17:12:24 +0000960\label{single-ext}
Greg Ward16aafcd2000-04-09 04:06:44 +0000961
962
963\subsection{Multiple extension modules}
Greg Warde78298a2000-04-28 17:12:24 +0000964\label{multiple-ext}
Greg Ward16aafcd2000-04-09 04:06:44 +0000965
966
967\subsection{Putting it all together}
968
969
Greg Ward4a9e7222000-04-25 02:57:36 +0000970
971\section{Extending the Distutils}
Greg Warde78298a2000-04-28 17:12:24 +0000972\label{extending}
Greg Ward4a9e7222000-04-25 02:57:36 +0000973
974
975\subsection{Extending existing commands}
Greg Warde78298a2000-04-28 17:12:24 +0000976\label{extend-existing}
Greg Ward4a9e7222000-04-25 02:57:36 +0000977
978
979\subsection{Writing new commands}
Greg Warde78298a2000-04-28 17:12:24 +0000980\label{new-commands}
Greg Ward4a9e7222000-04-25 02:57:36 +0000981
982
983
Greg Ward16aafcd2000-04-09 04:06:44 +0000984\section{Reference}
Greg Ward47f99a62000-09-04 20:07:15 +0000985\label{reference}
Greg Ward16aafcd2000-04-09 04:06:44 +0000986
987
Greg Wardfacb8db2000-04-09 04:32:40 +0000988\subsection{Building modules: the \protect\command{build} command family}
Greg Warde78298a2000-04-28 17:12:24 +0000989\label{build-cmds}
Greg Ward16aafcd2000-04-09 04:06:44 +0000990
Greg Wardfacb8db2000-04-09 04:32:40 +0000991\subsubsection{\protect\command{build}}
Greg Warde78298a2000-04-28 17:12:24 +0000992\label{build-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000993
Greg Wardfacb8db2000-04-09 04:32:40 +0000994\subsubsection{\protect\command{build\_py}}
Greg Warde78298a2000-04-28 17:12:24 +0000995\label{build-py-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000996
Greg Wardfacb8db2000-04-09 04:32:40 +0000997\subsubsection{\protect\command{build\_ext}}
Greg Warde78298a2000-04-28 17:12:24 +0000998\label{build-ext-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000999
Greg Wardfacb8db2000-04-09 04:32:40 +00001000\subsubsection{\protect\command{build\_clib}}
Greg Warde78298a2000-04-28 17:12:24 +00001001\label{build-clib-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001002
1003
Greg Wardfacb8db2000-04-09 04:32:40 +00001004\subsection{Installing modules: the \protect\command{install} command family}
Greg Warde78298a2000-04-28 17:12:24 +00001005\label{install-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001006
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001007The install command ensures that the build commands have been run and then
1008runs the subcommands \command{install\_lib},
1009\command{install\_data} and
1010\command{install\_scripts}.
1011
1012\subsubsection{\protect\command{install\_lib}}
Greg Ward1365a302000-08-31 14:47:05 +00001013\label{install-lib-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001014
1015\subsubsection{\protect\command{install\_data}}
Greg Ward1365a302000-08-31 14:47:05 +00001016\label{install-data-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001017This command installs all data files provided with the distribution.
1018
1019\subsubsection{\protect\command{install\_scripts}}
Greg Ward1365a302000-08-31 14:47:05 +00001020\label{install-scripts-cmd}
Gregory P. Smith147e5f32000-05-12 00:58:18 +00001021This command installs all (Python) scripts in the distribution.
1022
Greg Ward16aafcd2000-04-09 04:06:44 +00001023
Greg Wardfacb8db2000-04-09 04:32:40 +00001024\subsection{Cleaning up: the \protect\command{clean} command}
Greg Warde78298a2000-04-28 17:12:24 +00001025\label{clean-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001026
1027
Greg Wardfacb8db2000-04-09 04:32:40 +00001028\subsection{Creating a source distribution: the \protect\command{sdist} command}
Greg Warde78298a2000-04-28 17:12:24 +00001029\label{sdist-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +00001030
1031
1032\XXX{fragment moved down from above: needs context!}
1033The manifest template commands are:
1034\begin{tableii}{ll}{command}{Command}{Description}
Greg Ward87da1ea2000-04-21 04:35:25 +00001035 \lineii{include \var{pat1} \var{pat2} ... }
1036 {include all files matching any of the listed patterns}
1037 \lineii{exclude \var{pat1} \var{pat2} ... }
1038 {exclude all files matching any of the listed patterns}
1039 \lineii{recursive-include \var{dir} \var{pat1} \var{pat2} ... }
1040 {include all files under \var{dir} matching any of the listed patterns}
1041 \lineii{recursive-exclude \var{dir} \var{pat1} \var{pat2} ...}
1042 {exclude all files under \var{dir} matching any of the listed patterns}
1043 \lineii{global-include \var{pat1} \var{pat2} ...}
Greg Ward1bbe3292000-06-25 03:14:13 +00001044 {include all files anywhere in the source tree matching\\&
Greg Ward87da1ea2000-04-21 04:35:25 +00001045 any of the listed patterns}
1046 \lineii{global-exclude \var{pat1} \var{pat2} ...}
Greg Ward1bbe3292000-06-25 03:14:13 +00001047 {exclude all files anywhere in the source tree matching\\&
Greg Ward87da1ea2000-04-21 04:35:25 +00001048 any of the listed patterns}
Greg Ward16aafcd2000-04-09 04:06:44 +00001049 \lineii{prune \var{dir}}{exclude all files under \var{dir}}
1050 \lineii{graft \var{dir}}{include all files under \var{dir}}
1051\end{tableii}
1052The patterns here are Unix-style ``glob'' patterns: \code{*} matches any
1053sequence of regular filename characters, \code{?} matches any single
1054regular filename character, and \code{[\var{range}]} matches any of the
1055characters in \var{range} (e.g., \code{a-z}, \code{a-zA-Z},
Greg Wardfacb8db2000-04-09 04:32:40 +00001056\code{a-f0-9\_.}). The definition of ``regular filename character'' is
Greg Ward16aafcd2000-04-09 04:06:44 +00001057platform-specific: on Unix it is anything except slash; on Windows
1058anything except backslash or colon; on Mac OS anything except colon.
1059\XXX{Windows and Mac OS support not there yet}
1060
1061
Greg Wardd5767a52000-04-19 22:48:09 +00001062\subsection{Creating a ``built'' distribution: the
1063 \protect\command{bdist} command family}
Greg Warde78298a2000-04-28 17:12:24 +00001064\label{bdist-cmds}
Greg Ward16aafcd2000-04-09 04:06:44 +00001065
1066
Greg Wardfacb8db2000-04-09 04:32:40 +00001067\subsubsection{\protect\command{blib}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001068
Greg Wardfacb8db2000-04-09 04:32:40 +00001069\subsubsection{\protect\command{blib\_dumb}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001070
Greg Wardfacb8db2000-04-09 04:32:40 +00001071\subsubsection{\protect\command{blib\_rpm}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001072
Greg Wardfacb8db2000-04-09 04:32:40 +00001073\subsubsection{\protect\command{blib\_wise}}
Greg Ward16aafcd2000-04-09 04:06:44 +00001074
1075
1076
1077
1078
1079
1080
1081
Greg Wardabc52162000-02-26 00:52:48 +00001082\end{document}