blob: d29d805fb2506194d91e53509bba871be3b6e060 [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 Ward16aafcd2000-04-09 04:06:44 +000011
Greg Wardabc52162000-02-26 00:52:48 +000012\begin{document}
13
Greg Wardfacb8db2000-04-09 04:32:40 +000014\maketitle
15\tableofcontents
Greg Ward16aafcd2000-04-09 04:06:44 +000016
17\section{Introduction}
Greg Warde78298a2000-04-28 17:12:24 +000018\label{intro}
Greg Ward16aafcd2000-04-09 04:06:44 +000019
20In the past, Python module developers have not had much infrastructure
21support for distributing modules, nor have Python users had much support
22for installing and maintaining third-party modules. With the
23introduction of the Python Distribution Utilities (Distutils for short)
24in Python 1.6, this situation should start to improve.
25
26This document only covers using the Distutils to distribute your Python
27modules. Using the Distutils does not tie you to Python 1.6, though:
28the Distutils work just fine with Python 1.5, and it is reasonable (and
29expected to become commonplace) to expect users of Python 1.5 to
30download and install the Distutils separately before they can install
31your modules. Python 1.6 users, of course, won't have to add anything
32to their Python installation in order to use the Distutils to install
33third-party modules.
34
35This document concentrates on the role of developer/distributor: if
36you're looking for information on installing Python modules, you should
37refer to the ``Installing Python Modules'' manual.
38
39
Greg Wardfacb8db2000-04-09 04:32:40 +000040\section{Concepts \& Terminology}
Greg Warde78298a2000-04-28 17:12:24 +000041\label{concepts}
Greg Ward16aafcd2000-04-09 04:06:44 +000042
43Using the Distutils is quite simple, both for module developers and for
44users/administrators installing third-party modules. As a developer,
45your responsibilites (apart from writing solid, well-documented and
46well-tested code, of course!) are:
47\begin{itemize}
48\item write a setup script (\file{setup.py} by convention)
49\item (optional) write a setup configuration file
50\item create a source distribution
51\item (optional) create one or more built (binary) distributions
52\end{itemize}
53Each of these tasks is covered in this document.
54
55Not all module developers have access to a multitude of platforms, so
56it's not always feasible to expect them to create a multitude of built
57distributions. It is hoped that a class of intermediaries, called
Greg Ward19c67f82000-06-24 01:33:16 +000058\emph{packagers}, will arise to address this need. Packagers will take
59source distributions released by module developers, build them on one or
60more platforms, and release the resulting built distributions. Thus,
61users on the most popular platforms will be able to install most popular
62Python module distributions in the most natural way for their platform,
63without having to run a single setup script or compile a line of code.
Greg Ward16aafcd2000-04-09 04:06:44 +000064
65
66\subsection{A simple example}
Greg Warde78298a2000-04-28 17:12:24 +000067\label{simple-example}
Greg Ward16aafcd2000-04-09 04:06:44 +000068
69The setup script is usually quite simple, although since it's written in
70Python, there are no arbitrary limits to what you can do. If all you
71want to do is distribute a module called \module{foo}, contained in a
Greg Ward370248d2000-06-24 01:45:47 +000072file \file{foo.py}, then your setup script can be as little as this:
Greg Ward16aafcd2000-04-09 04:06:44 +000073\begin{verbatim}
74from distutils.core import setup
75setup (name = "foo",
76 version = "1.0",
77 py_modules = ["foo"])
78\end{verbatim}
Greg Ward370248d2000-06-24 01:45:47 +000079
Greg Ward16aafcd2000-04-09 04:06:44 +000080Some observations:
81\begin{itemize}
Greg Ward370248d2000-06-24 01:45:47 +000082\item most information that you supply to the Distutils is supplied as
Greg Wardfacb8db2000-04-09 04:32:40 +000083 keyword arguments to the \function{setup()} function
Greg Ward16aafcd2000-04-09 04:06:44 +000084\item those keyword arguments fall into two categories: package
85 meta-data (name, version number) and information about what's in the
Greg Ward370248d2000-06-24 01:45:47 +000086 package (a list of pure Python modules, in this case)
Greg Ward16aafcd2000-04-09 04:06:44 +000087\item modules are specified by module name, not filename (the same will
88 hold true for packages and extensions)
89\item it's recommended that you supply a little more meta-data, in
90 particular your name, email address and a URL for the project
91\end{itemize}
92
Greg Ward370248d2000-06-24 01:45:47 +000093To create a source distribution for this module, you would create a
94setup script, \file{setup.py}, containing the above code, and run:
Greg Ward16aafcd2000-04-09 04:06:44 +000095\begin{verbatim}
96python setup.py sdist
97\end{verbatim}
98which will create an archive file (e.g., tarball on Unix, zip file on
99Windows) containing your setup script, \file{setup.py}, and your module,
100\file{foo.py}. The archive file will be named \file{Foo-1.0.tar.gz} (or
101\file{.zip}), and will unpack into a directory \file{Foo-1.0}.
102
103If an end-user wishes to install your \module{foo} module, all she has
Greg Ward59d382e2000-05-26 01:04:47 +0000104to do is download \file{Foo-1.0.tar.gz} (or \file{.zip}), unpack it,
Greg Ward16aafcd2000-04-09 04:06:44 +0000105and---from the \file{Foo-1.0} directory---run
106\begin{verbatim}
107python setup.py install
108\end{verbatim}
109which will ultimately copy \file{foo.py} to the appropriate directory
110for third-party modules in their Python installation.
111
112This simple example demonstrates some fundamental concepts of the
113Distutils: first, both developers and installers have the same basic
114user interface, i.e. the setup script. The difference is which
115Distutils \emph{commands} they use: the \command{sdist} command is
116almost exclusively for module developers, while \command{install} is
117more often for installers (although most developers will want to install
118their own code occasionally).
119
120\XXX{only partially implemented}%
121If you want to make things really easy for your users, you can create
122one or more built distributions for them. For instance, if you are
123running on a Windows machine, and want to make things easy for other
124Windows users, you can create an executable installer (the most
125appropriate type of built distribution for this platform) with the
Greg Ward59d382e2000-05-26 01:04:47 +0000126\command{bdist\_wininst} command. For example:
Greg Ward16aafcd2000-04-09 04:06:44 +0000127\begin{verbatim}
Greg Ward59d382e2000-05-26 01:04:47 +0000128python setup.py bdist_wininst
Greg Ward16aafcd2000-04-09 04:06:44 +0000129\end{verbatim}
Greg Wardfacb8db2000-04-09 04:32:40 +0000130will create an executable installer, \file{Foo-1\_0.exe}, in the current
Greg Ward16aafcd2000-04-09 04:06:44 +0000131directory.
132
Greg Ward59d382e2000-05-26 01:04:47 +0000133(Another way to create executable installers for Windows is with the
134\command{bdist\_wise} command, which uses Wise---the commercial
135installer-generator used to create Python's own installer---to create
136the installer. Wise-based installers are more appropriate for large,
137industrial-strength applications that need the full capabilities of a
138``real'' installer. \command{bdist\_wininst} creates a self-extracting
139zip file with a minimal user interface, which is enough for small- to
140medium-sized module collections. You'll need to have version XXX of
Greg Ward370248d2000-06-24 01:45:47 +0000141Wise installed on your system for the \command{bdist\_wise} command to
142work; it's available from \url{http://foo/bar/baz}.)
Greg Ward59d382e2000-05-26 01:04:47 +0000143
144Other \command{bdist} commands exist for other platforms: for example,
145\command{bdist\_rpm} for RPM-based Linux systems, (\command{bdist\_deb})
146for Debian-based Linux systems, and so forth. See
147section~\ref{bdist-cmds} for details on all the \command{bdist}
148commands.
Greg Ward16aafcd2000-04-09 04:06:44 +0000149
150
151\subsection{General Python terminology}
Greg Warde78298a2000-04-28 17:12:24 +0000152\label{python-terms}
Greg Ward16aafcd2000-04-09 04:06:44 +0000153
154If you're reading this document, you probably have a good idea of what
155modules, extensions, and so forth are. Nevertheless, just to be sure
156that everyone is operating from a common starting point, we offer the
157following glossary of common Python terms:
158\begin{description}
159\item[module] the basic unit of code reusability in Python: a block of
160 code imported by some other code. There are three types of modules
161 that concern us here: pure Python modules, extension modules, and
162 packages.
163\item[pure Python module] a module written in Python and contained in a
164 single \file{.py} file (and possibly associated \file{.pyc} and/or
165 \file{.pyo} files). Sometimes referred to as a ``pure module.''
166\item[extension module] a module written in the low-level language of
167 the Python implemention: C/C++ for CPython, Java for JPython.
168 Typically contained in a single dynamically loadable pre-compiled
169 file, e.g. a shared object (\file{.so}) file for CPython extensions on
170 Unix, a DLL (given the \file{.pyd} extension) for CPython extensions
171 on Windows, or a Java class file for JPython extensions.
172\item[package] a module that contains other modules; typically contained
173 in a directory in the filesystem and distinguished from other
174 directories by the presence of a file \file{\_\_init\_\_.py}.
Greg Ward6153fa12000-05-26 02:24:28 +0000175\item[root package] the root of the hierarchy of packages. (This isn't
176 really a package, since it doesn't have an \file{\_\_init\_\_.py}
177 file. But we have to call it something.) The vast majority of the
178 standard library is in the root package, as are many small, standalone
179 third-party modules that don't belong to a larger module collection.
180 Unlike regular packages, modules in the root package can be found in
181 many directories: in fact, every directory listed in \code{sys.path}
182 can contribute modules to the root package.
Greg Ward16aafcd2000-04-09 04:06:44 +0000183\end{description}
184
185
186\subsection{Distutils-specific terminology}
Greg Warde78298a2000-04-28 17:12:24 +0000187\label{distutils-term}
Greg Ward16aafcd2000-04-09 04:06:44 +0000188
189The following terms apply more specifically to the domain of
190distributing Python modules using the Distutils:
191\begin{description}
192\item[module distribution] a collection of Python modules distributed
193 together as a single downloadable resource and meant to be installed
194 \emph{en masse}. Examples of some well-known module distributions are
195 Numeric Python, PyXML, PIL (the Python Imaging Library), or
196 mxDateTime. (This would be called a \emph{package}, except that term
Greg Ward59d382e2000-05-26 01:04:47 +0000197 is already taken in the Python context: a single module distribution
198 may contain zero, one, or many Python packages.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000199\item[pure module distribution] a module distribution that contains only
200 pure Python modules and packages. Sometimes referred to as a ``pure
201 distribution.''
202\item[non-pure module distribution] a module distribution that contains
203 at least one extension module. Sometimes referred to as a ``non-pure
204 distribution.''
205\item[distribution root] the top-level directory of your source tree (or
206 source distribution); the directory where \file{setup.py} exists and
207 is run from
208\end{description}
209
210
211\section{Writing the Setup Script}
Greg Warde78298a2000-04-28 17:12:24 +0000212\label{setup-script}
Greg Ward16aafcd2000-04-09 04:06:44 +0000213
214The setup script is the centre of all activity in building,
215distributing, and installing modules using the Distutils. The main
216purpose of the setup script is to describe your module distribution to
Greg Wardd5767a52000-04-19 22:48:09 +0000217the Distutils, so that the various commands that operate on your modules
Greg Ward59d382e2000-05-26 01:04:47 +0000218do the right thing. As we saw in section~\ref{simple-example} above,
219the setup script consists mainly of a call to \function{setup()}, and
220all information supplied to the Distutils is supplied as keyword
Greg Wardfacb8db2000-04-09 04:32:40 +0000221arguments to \function{setup()}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000222
223Here's a slightly more involved example, which we'll follow for the next
224couple of sections: the Distutils' own setup script. (Keep in mind that
225although the Distutils are included with Python 1.6, they also have an
226independent existence so that Python 1.5 users can use them to install
Greg Ward59d382e2000-05-26 01:04:47 +0000227other module distributions. The Distutils' own setup script is used to
228install the package into Python 1.5.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000229
230\begin{verbatim}
231#!/usr/bin/env python
232
233from distutils.core import setup
234
235setup (name = "Distutils",
236 version = "1.0",
237 description = "Python Module Distribution Utilities",
238 author = "Greg Ward",
239 author_email = "gward@python.net",
240 url = "http://www.python.org/sigs/distutils-sig/",
241
242 packages = ['distutils', 'distutils.command'],
243 )
244\end{verbatim}
245There are only two differences between this and the trivial one-file
Greg Warde78298a2000-04-28 17:12:24 +0000246distribution presented in section~\ref{simple-example}: more
Greg Ward16aafcd2000-04-09 04:06:44 +0000247meta-data, and the specification of pure Python modules by package,
248rather than by module. This is important since the Distutils consist of
249a couple of dozen modules split into (so far) two packages; an explicit
250list of every module would be tedious to generate and difficult to
251maintain.
252
Greg Ward46b98e32000-04-14 01:53:36 +0000253Note that any pathnames (files or directories) supplied in the setup
254script should be written using the Unix convention, i.e.
255slash-separated. The Distutils will take care of converting this
Greg Ward59d382e2000-05-26 01:04:47 +0000256platform-neutral representation into whatever is appropriate on your
Greg Ward46b98e32000-04-14 01:53:36 +0000257current platform before actually using the pathname. This makes your
258setup script portable across operating systems, which of course is one
259of the major goals of the Distutils. In this spirit, all pathnames in
Greg Ward59d382e2000-05-26 01:04:47 +0000260this document are slash-separated (Mac OS programmers should keep in
261mind that the \emph{absence} of a leading slash indicates a relative
262path, the opposite of the Mac OS convention with colons).
Greg Ward46b98e32000-04-14 01:53:36 +0000263
Greg Ward16aafcd2000-04-09 04:06:44 +0000264
265\subsection{Package directories}
Greg Warde78298a2000-04-28 17:12:24 +0000266\label{package-dirs}
Greg Ward16aafcd2000-04-09 04:06:44 +0000267
268The \option{packages} option tells the Distutils to process (build,
269distribute, install, etc.) all pure Python modules found in each package
270mentioned in the \option{packages} list. In order to do this, of
271course, there has to be a correspondence between package names and
272directories in the filesystem. The default correspondence is the most
Greg Ward1ecc2512000-04-19 22:36:24 +0000273obvious one, i.e. package \module{distutils} is found in the directory
Greg Ward16aafcd2000-04-09 04:06:44 +0000274\file{distutils} relative to the distribution root. Thus, when you say
275\code{packages = ['foo']} in your setup script, you are promising that
276the Distutils will find a file \file{foo/\_\_init\_\_.py} (which might
277be spelled differently on your system, but you get the idea) relative to
278the directory where your setup script lives. (If you break this
279promise, the Distutils will issue a warning but process the broken
280package anyways.)
281
282If you use a different convention to lay out your source directory,
283that's no problem: you just have to supply the \option{package\_dir}
284option to tell the Distutils about your convention. For example, say
285you keep all Python source under \file{lib}, so that modules not in any
Greg Ward1ecc2512000-04-19 22:36:24 +0000286package are right in \file{lib}, modules in the \module{foo} package
Greg Ward16aafcd2000-04-09 04:06:44 +0000287are in \file{lib/foo}, and so forth. Then you would put
288\begin{verbatim}
289package_dir = {'': 'lib'}
290\end{verbatim}
291in your setup script. (The keys to this dictionary are package names,
292and an empty package name stands for the ``root package,'' i.e. no
293package at all. The values are directory names relative to your
294distribution root.) In this case, when you say
295\code{packages = ['foo']}, you are promising that the file
296\file{lib/foo/\_\_init\_\_.py} exists.
297
Greg Ward1ecc2512000-04-19 22:36:24 +0000298Another possible convention is to put the \module{foo} package right in
299\file{lib}, the \module{foo.bar} package in \file{lib/bar}, etc. This
Greg Ward16aafcd2000-04-09 04:06:44 +0000300would be written in the setup script as
301\begin{verbatim}
302package_dir = {'foo': 'lib'}
303\end{verbatim}
Greg Ward59d382e2000-05-26 01:04:47 +0000304A \code{\var{package}: \var{dir}} entry in the \option{package\_dir}
305dictionary implicitly applies to all packages below \var{package}, so
306the \module{foo.bar} case is automatically handled here. In this
307example, having \code{packages = ['foo', 'foo.bar']} tells the Distutils
308to look for \file{lib/\_\_init\_\_.py} and
309\file{lib/bar/\_\_init\_\_.py}. (Keep in mind that although
310\option{package\_dir} applies recursively, you must explicitly list all
311packages in \option{packages}: the Distutils will \emph{not} recursively
312scan your source tree looking for any directory with an
313\file{\_\_init\_\_.py} file.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000314
315
316\subsection{Listing individual modules}
Greg Warde78298a2000-04-28 17:12:24 +0000317\label{listing-modules}
Greg Ward16aafcd2000-04-09 04:06:44 +0000318
319For a small module distribution, you might prefer to list all modules
320rather than listing packages---especially the case of a single module
321that goes in the ``root package'' (i.e., no package at all). This
Greg Warde78298a2000-04-28 17:12:24 +0000322simplest case was shown in section~\ref{simple-example}; here is a
Greg Ward16aafcd2000-04-09 04:06:44 +0000323slightly more involved example:
324\begin{verbatim}
325py_modules = ['mod1', 'pkg.mod2']
326\end{verbatim}
327This describes two modules, one of them in the ``root'' package, the
Greg Wardd5767a52000-04-19 22:48:09 +0000328other in the \module{pkg} package. Again, the default package/directory
329layout implies that these two modules can be found in \file{mod1.py} and
330\file{pkg/mod2.py}, and that \file{pkg/\_\_init\_\_.py} exists as well.
331And again, you can override the package/directory layout using the
Greg Ward59d382e2000-05-26 01:04:47 +0000332\option{package\_dir} option.
333
334
335\subsection{Describing extension modules}
336\label{sec:describing-extensions}
337
338\XXX{be sure to describe the whole \code{build\_info} dict, including
339 \code{extra\_compile\_args} and \code{extra\_link\_args}}
Greg Ward16aafcd2000-04-09 04:06:44 +0000340
341
342\section{Writing the Setup Configuration File}
Greg Warde78298a2000-04-28 17:12:24 +0000343\label{setup-config}
Greg Ward16aafcd2000-04-09 04:06:44 +0000344
345\XXX{not implemented yet!}
346
347Often, it's not possible to write down everything needed to build a
348distribution \emph{a priori}. You need to get some information from the
349user, or from the user's system, in order to proceed. For example, you
350might include an optional extension module that provides an interface to
351a particular C library. If that library is installed on the user's
352system, then you can build your optional extension---but you need to
353know where to find the header and library file. If it's not installed,
354you need to know this so you can omit your optional extension.
355
356The preferred way to do this, of course, would be for you to tell the
357Distutils which optional features (C libraries, system calls, external
358utilities, etc.) you're looking for, and it would inspect the user's
359system and try to find them. This functionality may appear in a future
360version of the Distutils, but it isn't there now. So, for the time
361being, we rely on the user building and installing your software to
362provide the necessary information. The vehicle for doing so is the
363setup configuration file, \file{setup.cfg}.
364
365\XXX{need more here!}
366
367
368\section{Creating a Source Distribution}
Greg Warde78298a2000-04-28 17:12:24 +0000369\label{source-dist}
Greg Ward16aafcd2000-04-09 04:06:44 +0000370
Greg Warde78298a2000-04-28 17:12:24 +0000371As shown in section~\ref{simple-example}, you use the
Greg Ward16aafcd2000-04-09 04:06:44 +0000372\command{sdist} command to create a source distribution. In the
373simplest case,
374\begin{verbatim}
375python setup.py sdist
376\end{verbatim}
Greg Ward19c67f82000-06-24 01:33:16 +0000377(assuming you haven't specified any \command{sdist} options in the setup
378script or config file), \command{sdist} creates the archive of the
Greg Ward16aafcd2000-04-09 04:06:44 +0000379default format for the current platform. The default formats are:
380\begin{tableii}{ll}{textrm}%
381 {Platform}{Default archive format for source distributions}
382 \lineii{Unix}{gzipped tar file (\file{.tar.gz})}
383 \lineii{Windows}{zip file}
384\end{tableii}
Greg Wardd5767a52000-04-19 22:48:09 +0000385You can specify as many formats as you like using the
386\longprogramopt{formats} option, for example:
Greg Ward16aafcd2000-04-09 04:06:44 +0000387\begin{verbatim}
388python setup.py sdist --formats=gztar,zip
389\end{verbatim}
390to create a gzipped tarball and a zip file. The available formats are:
Greg Ward46b98e32000-04-14 01:53:36 +0000391\begin{tableiii}{l|l|c}{code}%
392 {Format}{Description}{Notes}
393 \lineiii{zip}{zip file (\file{.zip})}{(1)}
394 \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(2)}
395 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{}
396 \lineiii{tar}{tar file (\file{.tar})}{}
397\end{tableiii}
398
399\noindent Notes:
400\begin{description}
401\item[(1)] default on Windows
402\item[(2)] default on Unix
403\end{description}
Greg Ward16aafcd2000-04-09 04:06:44 +0000404
405
406\subsection{The manifest and manifest template}
Greg Warde78298a2000-04-28 17:12:24 +0000407\label{manifest}
Greg Ward16aafcd2000-04-09 04:06:44 +0000408
409Without any additional information, the \command{sdist} command puts a
410minimal set of files into the source distribution:
411\begin{itemize}
Greg Wardfacb8db2000-04-09 04:32:40 +0000412\item all Python source files implied by the \option{py\_modules} and
Greg Ward16aafcd2000-04-09 04:06:44 +0000413 \option{packages} options
Greg Wardfacb8db2000-04-09 04:32:40 +0000414\item all C source files mentioned in the \option{ext\_modules} or
Greg Ward16aafcd2000-04-09 04:06:44 +0000415 \option{libraries} options (\XXX{getting C library sources currently
Greg Wardfacb8db2000-04-09 04:32:40 +0000416 broken -- no get\_source\_files() method in build\_clib.py!})
Greg Ward16aafcd2000-04-09 04:06:44 +0000417\item anything that looks like a test script: \file{test/test*.py}
418 (currently, the Distutils don't do anything with test scripts except
419 include them in source distributions, but in the future there will be
420 a standard for testing Python module distributions)
421\item \file{README.txt} (or \file{README}) and \file{setup.py}
422\end{itemize}
423Sometimes this is enough, but usually you will want to specify
424additional files to distribute. The typical way to do this is to write
425a \emph{manifest template}, called \file{MANIFEST.in} by default. The
426\command{sdist} command processes this template and generates a manifest
427file, \file{MANIFEST}. (If you prefer, you can skip the manifest
428template and generate the manifest yourself: it just lists one file per
429line.)
430
431The manifest template has one command per line, where each command
432specifies a set of files to include or exclude from the source
433distribution. For an example, again we turn to the Distutils' own
434manifest template:
435\begin{verbatim}
436include *.txt
Greg Ward87da1ea2000-04-21 04:35:25 +0000437recursive-include examples *.txt *.py
Greg Ward16aafcd2000-04-09 04:06:44 +0000438prune examples/sample?/build
439\end{verbatim}
440The meanings should be fairly clear: include all files in the
441distribution root matching \code{*.txt}, all files anywhere under the
442\file{examples} directory matching \code{*.txt} or \code{*.py}, and
443exclude all directories matching \code{examples/sample?/build}. There
444are several other commands available in the manifest template
Greg Warde78298a2000-04-28 17:12:24 +0000445mini-language; see section~\ref{sdist-cmd}.
Greg Ward16aafcd2000-04-09 04:06:44 +0000446
447The order of commands in the manifest template very much matters:
448initially, we have the list of default files as described above, and
449each command in the template adds to or removes from that list of files.
450When we have fully processed the manifest template, we have our complete
451list of files. This list is written to the manifest for future
452reference, and then used to build the source distribution archive(s).
453
Greg Ward46b98e32000-04-14 01:53:36 +0000454Following the Distutils' own manifest template, let's trace how the
455\command{sdist} command will build the list of files to include in the
456Distutils source distribution:
Greg Ward16aafcd2000-04-09 04:06:44 +0000457\begin{enumerate}
458\item include all Python source files in the \file{distutils} and
459 \file{distutils/command} subdirectories (because packages
460 corresponding to those two directories were mentioned in the
461 \option{packages} option in the setup script)
462\item include \file{test/test*.py} (always included)
463\item include \file{README.txt} and \file{setup.py} (always included)
464\item include \file{*.txt} in the distribution root (this will find
465 \file{README.txt} a second time, but such redundancies are weeded out
466 later)
467\item in the sub-tree under \file{examples}, include anything matching
468 \file{*.txt}
469\item in the sub-tree under \file{examples}, include anything matching
470 \file{*.py}
471\item remove all files in the sub-trees starting at directories matching
472 \file{examples/sample?/build}---this may exclude files included by the
473 previous two steps, so it's important that the \code{prune} command in
474 the manifest template comes after the two \code{recursive-include}
475 commands
Greg Wardfacb8db2000-04-09 04:32:40 +0000476\end{enumerate}
Greg Ward16aafcd2000-04-09 04:06:44 +0000477
Greg Ward46b98e32000-04-14 01:53:36 +0000478Just like in the setup script, file and directory names in the manifest
479template should always be slash-separated; the Distutils will take care
480of converting them to the standard representation on your platform.
481That way, the manifest template is portable across operating systems.
482
Greg Ward16aafcd2000-04-09 04:06:44 +0000483
484\subsection{Manifest-related options}
Greg Warde78298a2000-04-28 17:12:24 +0000485\label{manifest-options}
Greg Ward16aafcd2000-04-09 04:06:44 +0000486
487The normal course of operations for the \command{sdist} command is as
488follows:
489\begin{itemize}
Greg Ward46b98e32000-04-14 01:53:36 +0000490\item if the manifest file, \file{MANIFEST} doesn't exist, read
491 \file{MANIFEST.in} and create the manifest
492\item if \file{MANIFEST.in} is more recent than \file{MANIFEST},
493 recreate \file{MANIFEST} by reading \file{MANIFEST.in}
Greg Ward16aafcd2000-04-09 04:06:44 +0000494\item use the list of files now in \file{MANIFEST} (either just
495 generated or read in) to create the source distribution archive(s)
496\end{itemize}
497There are a couple of options that modify this behaviour.
498
499First, you might want to force the manifest to be regenerated---for
500example, if you have added or removed files or directories that match an
501existing pattern in the manifest template, you should regenerate the
502manifest:
503\begin{verbatim}
504python setup.py sdist --force-manifest
505\end{verbatim}
506\XXX{this is stupid, but is there a better way to do it without
507 reprocessing MANIFEST.in every single bloody time?}
508
509Or, you might just want to (re)generate the manifest, but not create a
510source distribution:
511\begin{verbatim}
512python setup.py sdist --manifest-only
513\end{verbatim}
Greg Warda021aca2000-04-19 22:34:11 +0000514(\longprogramopt{manifest-only} implies \longprogramopt{force-manifest}.)
Greg Ward16aafcd2000-04-09 04:06:44 +0000515
516If you don't want to use the default file set, you can supply the
Greg Wardd5767a52000-04-19 22:48:09 +0000517\longprogramopt{no-defaults} option. If you use
518\longprogramopt{no-defaults} and don't supply a manifest template (or
519it's empty, or nothing matches the patterns in it), then your source
520distribution will be empty.
Greg Ward16aafcd2000-04-09 04:06:44 +0000521
522
523\section{Creating Built Distributions}
Greg Warde78298a2000-04-28 17:12:24 +0000524\label{built-dist}
Greg Ward16aafcd2000-04-09 04:06:44 +0000525
Greg Ward46b98e32000-04-14 01:53:36 +0000526A ``built distribution'' is what you're probably used to thinking of
527either as a ``binary package'' or an ``installer'' (depending on your
528background). It's not necessarily binary, though, because it might
529contain only Python source code and/or byte-code; and we don't call it a
530package, because that word is already spoken for in Python. (And
531``installer'' is a term specific to the Windows world. \XXX{do Mac
532 people use it?})
Greg Ward16aafcd2000-04-09 04:06:44 +0000533
Greg Ward46b98e32000-04-14 01:53:36 +0000534A built distribution is how you make life as easy as possible for
535installers of your module distribution: for users of RPM-based Linux
536systems, it's a binary RPM; for Windows users, it's an executable
537installer; for Debian-based Linux users, it's a Debian package; and so
538forth. Obviously, no one person will be able to create built
539distributions for every platform under the sun, so the Distutils is
540designed to enable module developers to concentrate on their
541specialty---writing code and creating source distributions---while an
542intermediary species of \emph{packager} springs up to turn source
Greg Ward19c67f82000-06-24 01:33:16 +0000543distributions into built distributions for as many platforms as there
Greg Ward46b98e32000-04-14 01:53:36 +0000544are packagers.
545
546Of course, the module developer could be his own packager; or the
547packager could be a volunteer ``out there'' somewhere who has access to
548a platform which the original developer does not; or it could be
549software periodically grabbing new source distributions and turning them
550into built distributions for as many platforms as the software has
551access to. Regardless of the nature of the beast, a packager uses the
552setup script and the \command{bdist} command family to generate built
553distributions.
554
555As a simple example, if I run the following command in the Distutils
556source tree:
557\begin{verbatim}
558python setup.py bdist
559\end{verbatim}
560then the Distutils builds my module distribution (the Distutils itself
561in this case), does a ``fake'' installation (also in the \file{build}
562directory), and creates the default type of built distribution for my
563platform. In Distutils 0.8, only two types of built distribution are
564supported: \code{gztar} (default on non-Linux Unix) and \code{zip}
565(default on Windows). Thus, the above command on a Unix system creates
566\file{Distutils-0.8.built-posix.tar.gz}; unpacking this tarball from
567Python's \filevar{prefix} directory installs the Distutils just as
568though you had downloaded the source distribution and run \code{python
569 setup.py install}. Obviously, for pure Python distributions, this
570isn't a huge win---but for non-pure distributions, which include
571extensions that would need to be compiled, it can mean the difference
572between someone being able to use your extensions or not.
573
574\XXX{filenames are inaccurate here!}
575
Greg Wardd5767a52000-04-19 22:48:09 +0000576The \command{bdist} command has a \longprogramopt{format} option,
577similar to the \command{sdist} command, that you can use to select which
578formats to generate: for example,
Greg Ward46b98e32000-04-14 01:53:36 +0000579\begin{verbatim}
580python setup.py bdist --format=zip
581\end{verbatim}
582would, when run on a Unix system, create
583\file{Distutils-0.8.built-posix.tar.gz}---again, this archive would be
584unpacked from Python's \filevar{prefix} directory to install the
585Distutils.
586
587The available formats for built distributions are:
588\begin{tableiii}{l|l|c}{code}%
589 {Format}{Description}{Notes}
590 \lineiii{zip}{zip file (\file{.zip})}{(1)}
591 \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(2)}
592 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{}
593 \lineiii{tar}{tar file (\file{.tar})}{}
594 \lineiii{rpm}{RPM}{(3)}
595 \lineiii{srpm}{source RPM}{}
596 \lineiii{wise}{Wise installer for Windows}{}
597\end{tableiii}
598
599\noindent Notes:
600\begin{description}
601\item[(1)] default on Windows
602\item[(2)] default on Unix
603\item[(3)] not implemented yet; will be default on RPM-based Linux
604 systems
605\item[(5)] not implemented yet; will be default on Windows
606\end{description}
607
608You don't have to use the \command{bdist} command with the
Greg Wardd5767a52000-04-19 22:48:09 +0000609\longprogramopt{formats} option; you can also use the command that
610directly implements the format you're interested in. Many of these
Greg Ward46b98e32000-04-14 01:53:36 +0000611\command{bdist} ``sub-commands'' actually generate several similar
612formats; for instance, the \command{bdist\_dumb} command generates all
613the ``dumb'' archive formats (\code{tar}, \code{ztar}, \code{gztar}, and
614\code{zip}), and \command{bdist\_rpm} generates both binary and source
615RPMs. The \command{bdist} sub-commands, and the formats generated by
616each, are:
617\begin{tableii}{l|l}{command}%
618 {Command}{Formats}
619 \lineii{bdist\_dumb}{tar, ztar, gztar, zip}
620 \lineii{bdist\_rpm}{rpm, srpm}
621 \lineii{bdist\_wise}{wise}
622\end{tableii}
Greg Ward16aafcd2000-04-09 04:06:44 +0000623
624\section{Examples}
Greg Warde78298a2000-04-28 17:12:24 +0000625\label{examples}
Greg Ward16aafcd2000-04-09 04:06:44 +0000626
627
628\subsection{Pure Python distribution (by module)}
Greg Warde78298a2000-04-28 17:12:24 +0000629\label{pure-mod}
Greg Ward16aafcd2000-04-09 04:06:44 +0000630
631
632\subsection{Pure Python distribution (by package)}
Greg Warde78298a2000-04-28 17:12:24 +0000633\label{pure-pkg}
Greg Ward16aafcd2000-04-09 04:06:44 +0000634
635
636\subsection{Single extension module}
Greg Warde78298a2000-04-28 17:12:24 +0000637\label{single-ext}
Greg Ward16aafcd2000-04-09 04:06:44 +0000638
639
640\subsection{Multiple extension modules}
Greg Warde78298a2000-04-28 17:12:24 +0000641\label{multiple-ext}
Greg Ward16aafcd2000-04-09 04:06:44 +0000642
643
644\subsection{Putting it all together}
645
646
Greg Ward4a9e7222000-04-25 02:57:36 +0000647
648\section{Extending the Distutils}
Greg Warde78298a2000-04-28 17:12:24 +0000649\label{extending}
Greg Ward4a9e7222000-04-25 02:57:36 +0000650
651
652\subsection{Extending existing commands}
Greg Warde78298a2000-04-28 17:12:24 +0000653\label{extend-existing}
Greg Ward4a9e7222000-04-25 02:57:36 +0000654
655
656\subsection{Writing new commands}
Greg Warde78298a2000-04-28 17:12:24 +0000657\label{new-commands}
Greg Ward4a9e7222000-04-25 02:57:36 +0000658
659
660
Greg Ward16aafcd2000-04-09 04:06:44 +0000661\section{Reference}
Greg Warde78298a2000-04-28 17:12:24 +0000662\label{ref}
Greg Ward16aafcd2000-04-09 04:06:44 +0000663
664
Greg Wardfacb8db2000-04-09 04:32:40 +0000665\subsection{Building modules: the \protect\command{build} command family}
Greg Warde78298a2000-04-28 17:12:24 +0000666\label{build-cmds}
Greg Ward16aafcd2000-04-09 04:06:44 +0000667
Greg Wardfacb8db2000-04-09 04:32:40 +0000668\subsubsection{\protect\command{build}}
Greg Warde78298a2000-04-28 17:12:24 +0000669\label{build-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000670
Greg Wardfacb8db2000-04-09 04:32:40 +0000671\subsubsection{\protect\command{build\_py}}
Greg Warde78298a2000-04-28 17:12:24 +0000672\label{build-py-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000673
Greg Wardfacb8db2000-04-09 04:32:40 +0000674\subsubsection{\protect\command{build\_ext}}
Greg Warde78298a2000-04-28 17:12:24 +0000675\label{build-ext-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000676
Greg Wardfacb8db2000-04-09 04:32:40 +0000677\subsubsection{\protect\command{build\_clib}}
Greg Warde78298a2000-04-28 17:12:24 +0000678\label{build-clib-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000679
680
Greg Wardfacb8db2000-04-09 04:32:40 +0000681\subsection{Installing modules: the \protect\command{install} command family}
Greg Warde78298a2000-04-28 17:12:24 +0000682\label{install-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000683
Gregory P. Smith147e5f32000-05-12 00:58:18 +0000684The install command ensures that the build commands have been run and then
685runs the subcommands \command{install\_lib},
686\command{install\_data} and
687\command{install\_scripts}.
688
689\subsubsection{\protect\command{install\_lib}}
690\label{sec:install-lib-cmd}
691
692\subsubsection{\protect\command{install\_data}}
693\label{sec:install-data-cmd}
694This command installs all data files provided with the distribution.
695
696\subsubsection{\protect\command{install\_scripts}}
697\label{sec:install-scripts-cmd}
698This command installs all (Python) scripts in the distribution.
699
Greg Ward16aafcd2000-04-09 04:06:44 +0000700
Greg Wardfacb8db2000-04-09 04:32:40 +0000701\subsection{Cleaning up: the \protect\command{clean} command}
Greg Warde78298a2000-04-28 17:12:24 +0000702\label{clean-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000703
704
Greg Wardfacb8db2000-04-09 04:32:40 +0000705\subsection{Creating a source distribution: the \protect\command{sdist} command}
Greg Warde78298a2000-04-28 17:12:24 +0000706\label{sdist-cmd}
Greg Ward16aafcd2000-04-09 04:06:44 +0000707
708
709\XXX{fragment moved down from above: needs context!}
710The manifest template commands are:
711\begin{tableii}{ll}{command}{Command}{Description}
Greg Ward87da1ea2000-04-21 04:35:25 +0000712 \lineii{include \var{pat1} \var{pat2} ... }
713 {include all files matching any of the listed patterns}
714 \lineii{exclude \var{pat1} \var{pat2} ... }
715 {exclude all files matching any of the listed patterns}
716 \lineii{recursive-include \var{dir} \var{pat1} \var{pat2} ... }
717 {include all files under \var{dir} matching any of the listed patterns}
718 \lineii{recursive-exclude \var{dir} \var{pat1} \var{pat2} ...}
719 {exclude all files under \var{dir} matching any of the listed patterns}
720 \lineii{global-include \var{pat1} \var{pat2} ...}
721 {include all files anywhere in the source tree matching
722 any of the listed patterns}
723 \lineii{global-exclude \var{pat1} \var{pat2} ...}
724 {exclude all files anywhere in the source tree matching
725 any of the listed patterns}
Greg Ward16aafcd2000-04-09 04:06:44 +0000726 \lineii{prune \var{dir}}{exclude all files under \var{dir}}
727 \lineii{graft \var{dir}}{include all files under \var{dir}}
728\end{tableii}
729The patterns here are Unix-style ``glob'' patterns: \code{*} matches any
730sequence of regular filename characters, \code{?} matches any single
731regular filename character, and \code{[\var{range}]} matches any of the
732characters in \var{range} (e.g., \code{a-z}, \code{a-zA-Z},
Greg Wardfacb8db2000-04-09 04:32:40 +0000733\code{a-f0-9\_.}). The definition of ``regular filename character'' is
Greg Ward16aafcd2000-04-09 04:06:44 +0000734platform-specific: on Unix it is anything except slash; on Windows
735anything except backslash or colon; on Mac OS anything except colon.
736\XXX{Windows and Mac OS support not there yet}
737
738
Greg Wardd5767a52000-04-19 22:48:09 +0000739\subsection{Creating a ``built'' distribution: the
740 \protect\command{bdist} command family}
Greg Warde78298a2000-04-28 17:12:24 +0000741\label{bdist-cmds}
Greg Ward16aafcd2000-04-09 04:06:44 +0000742
743
Greg Wardfacb8db2000-04-09 04:32:40 +0000744\subsubsection{\protect\command{blib}}
Greg Ward16aafcd2000-04-09 04:06:44 +0000745
Greg Wardfacb8db2000-04-09 04:32:40 +0000746\subsubsection{\protect\command{blib\_dumb}}
Greg Ward16aafcd2000-04-09 04:06:44 +0000747
Greg Wardfacb8db2000-04-09 04:32:40 +0000748\subsubsection{\protect\command{blib\_rpm}}
Greg Ward16aafcd2000-04-09 04:06:44 +0000749
Greg Wardfacb8db2000-04-09 04:32:40 +0000750\subsubsection{\protect\command{blib\_wise}}
Greg Ward16aafcd2000-04-09 04:06:44 +0000751
752
753
754
755
756
757
758
Greg Wardabc52162000-02-26 00:52:48 +0000759\end{document}