Updated for 2.1a3
[python/dscho.git] / Doc / dist / dist.tex
blob884a0ee4f6bc426310ae69f32b64f459be13b19a
1 \documentclass{howto}
2 \usepackage{distutils}
4 % $Id$
6 \title{Distributing Python Modules}
8 \author{Greg Ward}
9 \authoraddress{E-mail: \email{gward@python.net}}
11 \makeindex
13 \begin{document}
15 \maketitle
16 \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}
25 \tableofcontents
27 \section{Introduction}
28 \label{intro}
30 In the past, Python module developers have not had much infrastructure
31 support for distributing modules, nor have Python users had much support
32 for installing and maintaining third-party modules. With the
33 introduction of the Python Distribution Utilities (Distutils for short)
34 in Python 1.6, this situation should start to improve.
36 This document only covers using the Distutils to distribute your Python
37 modules. Using the Distutils does not tie you to Python 1.6, though:
38 the 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
40 download and install the Distutils separately before they can install
41 your modules. Python 1.6 (or later) users, of course, won't have to add
42 anything to their Python installation in order to use the Distutils to
43 install third-party modules.
45 This document concentrates on the role of developer/distributor: if
46 you're looking for information on installing Python modules, you
47 should refer to the \citetitle[../inst/inst.html]{Installing Python
48 Modules} manual.
51 \section{Concepts \& Terminology}
52 \label{concepts}
54 Using the Distutils is quite simple, both for module developers and for
55 users/administrators installing third-party modules. As a developer,
56 your responsibilities (apart from writing solid, well-documented and
57 well-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}
64 Each of these tasks is covered in this document.
66 Not all module developers have access to a multitude of platforms, so
67 it's not always feasible to expect them to create a multitude of built
68 distributions. It is hoped that a class of intermediaries, called
69 \emph{packagers}, will arise to address this need. Packagers will take
70 source distributions released by module developers, build them on one or
71 more platforms, and release the resulting built distributions. Thus,
72 users on the most popular platforms will be able to install most popular
73 Python module distributions in the most natural way for their platform,
74 without having to run a single setup script or compile a line of code.
77 \subsection{A simple example}
78 \label{simple-example}
80 The setup script is usually quite simple, although since it's written in
81 Python, there are no arbitrary limits to what you can do with
82 it.\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
88 all you want to do is distribute a module called \module{foo}, contained
89 in a file \file{foo.py}, then your setup script can be as little as
90 this:
91 \begin{verbatim}
92 from distutils.core import setup
93 setup (name = "foo",
94 version = "1.0",
95 py_modules = ["foo"])
96 \end{verbatim}
98 Some observations:
99 \begin{itemize}
100 \item most information that you supply to the Distutils is supplied as
101 keyword arguments to the \function{setup()} function
102 \item those keyword arguments fall into two categories: package
103 meta-data (name, version number) and information about what's in the
104 package (a list of pure Python modules, in this case)
105 \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
109 (see section~\ref{setup-script} for an example)
110 \end{itemize}
112 To create a source distribution for this module, you would create a
113 setup script, \file{setup.py}, containing the above code, and run:
114 \begin{verbatim}
115 python setup.py sdist
116 \end{verbatim}
117 which will create an archive file (e.g., tarball on \UNIX, ZIP file on
118 Windows) 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}.
122 If an end-user wishes to install your \module{foo} module, all she has
123 to do is download \file{Foo-1.0.tar.gz} (or \file{.zip}), unpack it,
124 and---from the \file{Foo-1.0} directory---run
125 \begin{verbatim}
126 python setup.py install
127 \end{verbatim}
128 which will ultimately copy \file{foo.py} to the appropriate directory
129 for third-party modules in their Python installation.
131 This simple example demonstrates some fundamental concepts of the
132 Distutils: first, both developers and installers have the same basic
133 user interface, i.e. the setup script. The difference is which
134 Distutils \emph{commands} they use: the \command{sdist} command is
135 almost exclusively for module developers, while \command{install} is
136 more often for installers (although most developers will want to install
137 their own code occasionally).
139 If you want to make things really easy for your users, you can create
140 one or more built distributions for them. For instance, if you are
141 running on a Windows machine, and want to make things easy for other
142 Windows users, you can create an executable installer (the most
143 appropriate type of built distribution for this platform) with the
144 \command{bdist\_wininst} command. For example:
145 \begin{verbatim}
146 python setup.py bdist_wininst
147 \end{verbatim}
148 will create an executable installer, \file{Foo-1.0.win32.exe}, in the
149 current directory.
151 Currently (Distutils 0.9.2), the only other useful built
152 distribution format is RPM, implemented by the \command{bdist\_rpm}
153 command. For example, the following command will create an RPM file
154 called \file{Foo-1.0.noarch.rpm}:
155 \begin{verbatim}
156 python setup.py bdist_rpm
157 \end{verbatim}
158 (This uses the \command{rpm} command, so has to be run on an RPM-based
159 system such as Red Hat Linux, SuSE Linux, or Mandrake Linux.)
161 You can find out what distribution formats are available at any time by
162 running
163 \begin{verbatim}
164 python setup.py bdist --help-formats
165 \end{verbatim}
168 \subsection{General Python terminology}
169 \label{python-terms}
171 If you're reading this document, you probably have a good idea of what
172 modules, extensions, and so forth are. Nevertheless, just to be sure
173 that everyone is operating from a common starting point, we offer the
174 following glossary of common Python terms:
175 \begin{description}
176 \item[module] the basic unit of code reusability in Python: a block of
177 code imported by some other code. Three types of modules concern us
178 here: pure Python modules, extension modules, and packages.
179 \item[pure Python module] a module written in Python and contained in a
180 single \file{.py} file (and possibly associated \file{.pyc} and/or
181 \file{.pyo} files). Sometimes referred to as a ``pure module.''
182 \item[extension module] a module written in the low-level language of
183 the Python implementation: C/C++ for Python, Java for JPython.
184 Typically contained in a single dynamically loadable pre-compiled
185 file, e.g. a shared object (\file{.so}) file for Python extensions on
186 \UNIX, a DLL (given the \file{.pyd} extension) for Python extensions
187 on Windows, or a Java class file for JPython extensions. (Note that
188 currently, the Distutils only handles C/C++ extensions for Python.)
189 \item[package] a module that contains other modules; typically contained
190 in a directory in the filesystem and distinguished from other
191 directories by the presence of a file \file{\_\_init\_\_.py}.
192 \item[root package] the root of the hierarchy of packages. (This isn't
193 really a package, since it doesn't have an \file{\_\_init\_\_.py}
194 file. But we have to call it something.) The vast majority of the
195 standard library is in the root package, as are many small, standalone
196 third-party modules that don't belong to a larger module collection.
197 Unlike regular packages, modules in the root package can be found in
198 many directories: in fact, every directory listed in \code{sys.path}
199 can contribute modules to the root package.
200 \end{description}
203 \subsection{Distutils-specific terminology}
204 \label{distutils-term}
206 The following terms apply more specifically to the domain of
207 distributing Python modules using the Distutils:
208 \begin{description}
209 \item[module distribution] a collection of Python modules distributed
210 together as a single downloadable resource and meant to be installed
211 \emph{en masse}. Examples of some well-known module distributions are
212 Numeric Python, PyXML, PIL (the Python Imaging Library), or
213 mxDateTime. (This would be called a \emph{package}, except that term
214 is already taken in the Python context: a single module distribution
215 may contain zero, one, or many Python packages.)
216 \item[pure module distribution] a module distribution that contains only
217 pure Python modules and packages. Sometimes referred to as a ``pure
218 distribution.''
219 \item[non-pure module distribution] a module distribution that contains
220 at least one extension module. Sometimes referred to as a ``non-pure
221 distribution.''
222 \item[distribution root] the top-level directory of your source tree (or
223 source distribution); the directory where \file{setup.py} exists and
224 is run from
225 \end{description}
228 \section{Writing the Setup Script}
229 \label{setup-script}
231 The setup script is the centre of all activity in building,
232 distributing, and installing modules using the Distutils. The main
233 purpose of the setup script is to describe your module distribution to
234 the Distutils, so that the various commands that operate on your modules
235 do the right thing. As we saw in section~\ref{simple-example} above,
236 the setup script consists mainly of a call to \function{setup()}, and
237 most information supplied to the Distutils by the module developer is
238 supplied as keyword arguments to \function{setup()}.
240 Here's a slightly more involved example, which we'll follow for the next
241 couple of sections: the Distutils' own setup script. (Keep in mind that
242 although the Distutils are included with Python 1.6 and later, they also
243 have an independent existence so that Python 1.5.2 users can use them to
244 install other module distributions. The Distutils' own setup script,
245 shown here, is used to install the package into Python 1.5.2.)
247 \begin{verbatim}
248 #!/usr/bin/env python
250 from distutils.core import setup
252 setup (name = "Distutils",
253 version = "1.0",
254 description = "Python Distribution Utilities",
255 author = "Greg Ward",
256 author_email = "gward@python.net",
257 url = "http://www.python.org/sigs/distutils-sig/",
259 packages = ['distutils', 'distutils.command'],
261 \end{verbatim}
262 There are only two differences between this and the trivial one-file
263 distribution presented in section~\ref{simple-example}: more
264 meta-data, and the specification of pure Python modules by package,
265 rather than by module. This is important since the Distutils consist of
266 a couple of dozen modules split into (so far) two packages; an explicit
267 list of every module would be tedious to generate and difficult to
268 maintain.
270 Note that any pathnames (files or directories) supplied in the setup
271 script should be written using the \UNIX{} convention, i.e.
272 slash-separated. The Distutils will take care of converting this
273 platform-neutral representation into whatever is appropriate on your
274 current platform before actually using the pathname. This makes your
275 setup script portable across operating systems, which of course is one
276 of the major goals of the Distutils. In this spirit, all pathnames in
277 this document are slash-separated (MacOS programmers should keep in
278 mind that the \emph{absence} of a leading slash indicates a relative
279 path, the opposite of the MacOS convention with colons).
281 This, of course, only applies to pathnames given to Distutils functions.
282 If you, for example, use standard python functions such as glob.glob
283 or os.listdir to specify files, you should be careful to write portable
284 code instead of hardcoding path separators:
285 \begin{verbatim}
286 glob.glob(os.path.join('mydir', 'subdir', '*.html'))
287 os.listdir(os.path.join('mydir', 'subdir'))
288 \end{verbatim}
290 \subsection{Listing whole packages}
291 \label{listing-packages}
293 The \option{packages} option tells the Distutils to process (build,
294 distribute, install, etc.) all pure Python modules found in each package
295 mentioned in the \option{packages} list. In order to do this, of
296 course, there has to be a correspondence between package names and
297 directories in the filesystem. The default correspondence is the most
298 obvious one, i.e. package \module{distutils} is found in the directory
299 \file{distutils} relative to the distribution root. Thus, when you say
300 \code{packages = ['foo']} in your setup script, you are promising that
301 the Distutils will find a file \file{foo/\_\_init\_\_.py} (which might
302 be spelled differently on your system, but you get the idea) relative to
303 the directory where your setup script lives. (If you break this
304 promise, the Distutils will issue a warning but process the broken
305 package anyways.)
307 If you use a different convention to lay out your source directory,
308 that's no problem: you just have to supply the \option{package\_dir}
309 option to tell the Distutils about your convention. For example, say
310 you keep all Python source under \file{lib}, so that modules in the
311 ``root package'' (i.e., not in any package at all) are right in
312 \file{lib}, modules in the \module{foo} package are in \file{lib/foo},
313 and so forth. Then you would put
314 \begin{verbatim}
315 package_dir = {'': 'lib'}
316 \end{verbatim}
317 in your setup script. (The keys to this dictionary are package names,
318 and an empty package name stands for the root package. The values are
319 directory names relative to your distribution root.) In this case, when
320 you say \code{packages = ['foo']}, you are promising that the file
321 \file{lib/foo/\_\_init\_\_.py} exists.
323 Another possible convention is to put the \module{foo} package right in
324 \file{lib}, the \module{foo.bar} package in \file{lib/bar}, etc. This
325 would be written in the setup script as
326 \begin{verbatim}
327 package_dir = {'foo': 'lib'}
328 \end{verbatim}
329 A \code{\var{package}: \var{dir}} entry in the \option{package\_dir}
330 dictionary implicitly applies to all packages below \var{package}, so
331 the \module{foo.bar} case is automatically handled here. In this
332 example, having \code{packages = ['foo', 'foo.bar']} tells the Distutils
333 to look for \file{lib/\_\_init\_\_.py} and
334 \file{lib/bar/\_\_init\_\_.py}. (Keep in mind that although
335 \option{package\_dir} applies recursively, you must explicitly list all
336 packages in \option{packages}: the Distutils will \emph{not} recursively
337 scan your source tree looking for any directory with an
338 \file{\_\_init\_\_.py} file.)
341 \subsection{Listing individual modules}
342 \label{listing-modules}
344 For a small module distribution, you might prefer to list all modules
345 rather than listing packages---especially the case of a single module
346 that goes in the ``root package'' (i.e., no package at all). This
347 simplest case was shown in section~\ref{simple-example}; here is a
348 slightly more involved example:
349 \begin{verbatim}
350 py_modules = ['mod1', 'pkg.mod2']
351 \end{verbatim}
352 This describes two modules, one of them in the ``root'' package, the
353 other in the \module{pkg} package. Again, the default package/directory
354 layout implies that these two modules can be found in \file{mod1.py} and
355 \file{pkg/mod2.py}, and that \file{pkg/\_\_init\_\_.py} exists as well.
356 And again, you can override the package/directory correspondence using
357 the \option{package\_dir} option.
360 \subsection{Describing extension modules}
361 \label{describing-extensions}
363 Just as writing Python extension modules is a bit more complicated than
364 writing pure Python modules, describing them to the Distutils is a bit
365 more complicated. Unlike pure modules, it's not enough just to list
366 modules or packages and expect the Distutils to go out and find the
367 right files; you have to specify the extension name, source file(s), and
368 any compile/link requirements (include directories, libraries to link
369 with, etc.).
371 All of this is done through another keyword argument to
372 \function{setup()}, the \option{extensions} option. \option{extensions}
373 is just a list of \class{Extension} instances, each of which describes a
374 single extension module. Suppose your distribution includes a single
375 extension, called \module{foo} and implemented by \file{foo.c}. If no
376 additional instructions to the compiler/linker are needed, describing
377 this extension is quite simple:
378 \begin{verbatim}
379 Extension("foo", ["foo.c"])
380 \end{verbatim}
381 The \class{Extension} class can be imported from
382 \module{distutils.core}, along with \function{setup()}. Thus, the setup
383 script for a module distribution that contains only this one extension
384 and nothing else might be:
385 \begin{verbatim}
386 from distutils.core import setup, Extension
387 setup(name = "foo", version = "1.0",
388 ext_modules = [Extension("foo", ["foo.c"])])
389 \end{verbatim}
391 The \class{Extension} class (actually, the underlying extension-building
392 machinery implemented by the \command{build\_ext} command) supports a
393 great deal of flexibility in describing Python extensions, which is
394 explained in the following sections.
397 \subsubsection{Extension names and packages}
399 The first argument to the \class{Extension} constructor is always the
400 name of the extension, including any package names. For example,
401 \begin{verbatim}
402 Extension("foo", ["src/foo1.c", "src/foo2.c"])
403 \end{verbatim}
404 describes an extension that lives in the root package, while
405 \begin{verbatim}
406 Extension("pkg.foo", ["src/foo1.c", "src/foo2.c"])
407 \end{verbatim}
408 describes the same extension in the \module{pkg} package. The source
409 files and resulting object code are identical in both cases; the only
410 difference is where in the filesystem (and therefore where in Python's
411 namespace hierarchy) the resulting extension lives.
413 If you have a number of extensions all in the same package (or all under
414 the same base package), use the \option{ext\_package} keyword argument
415 to \function{setup()}. For example,
416 \begin{verbatim}
417 setup(...
418 ext_package = "pkg",
419 ext_modules = [Extension("foo", ["foo.c"]),
420 Extension("subpkg.bar", ["bar.c"])]
422 \end{verbatim}
423 will compile \file{foo.c} to the extension \module{pkg.foo}, and
424 \file{bar.c} to \module{pkg.subpkg.bar}.
427 \subsubsection{Extension source files}
429 The second argument to the \class{Extension} constructor is a list of
430 source files. Since the Distutils currently only support C/C++
431 extensions, these are normally C/C++ source files. (Be sure to use
432 appropriate extensions to distinguish C++ source files: \file{.cc} and
433 \file{.cpp} seem to be recognized by both \UNIX{} and Windows compilers.)
435 However, you can also include SWIG interface (\file{.i}) files in the
436 list; the \command{build\_ext} command knows how to deal with SWIG
437 extensions: it will run SWIG on the interface file and compile the
438 resulting C/C++ file into your extension.
440 \XXX{SWIG support is rough around the edges and largely untested;
441 especially SWIG support of C++ extensions! Explain in more detail
442 here when the interface firms up.}
444 On some platforms, you can include non-source files that are processed
445 by the compiler and included in your extension. Currently, this just
446 means Windows message text (\file{.mc}) files and resource definition
447 (\file{.rc}) files for Visual C++. These will be compiled to binary resource
448 (\file{.res}) files and linked into the executable.
451 \subsubsection{Preprocessor options}
453 Three optional arguments to \class{Extension} will help if you need to
454 specify include directories to search or preprocessor macros to
455 define/undefine: \code{include\_dirs}, \code{define\_macros}, and
456 \code{undef\_macros}.
458 For example, if your extension requires header files in the
459 \file{include} directory under your distribution root, use the
460 \code{include\_dirs} option:
461 \begin{verbatim}
462 Extension("foo", ["foo.c"], include_dirs=["include"])
463 \end{verbatim}
465 You can specify absolute directories there; if you know that your
466 extension will only be built on \UNIX{} systems with X11R6 installed to
467 \file{/usr}, you can get away with
468 \begin{verbatim}
469 Extension("foo", ["foo.c"], include_dirs=["/usr/include/X11"])
470 \end{verbatim}
471 You should avoid this sort of non-portable usage if you plan to
472 distribute your code: it's probably better to write your code to include
473 (e.g.) \code{<X11/Xlib.h>}.
475 If you need to include header files from some other Python extension,
476 you can take advantage of the fact that the Distutils install extension
477 header files in a consistent way. For example, the Numerical Python
478 header files are installed (on a standard \UNIX{} installation) to
479 \file{/usr/local/include/python1.5/Numerical}. (The exact location will
480 differ according to your platform and Python installation.) Since the
481 Python include directory---\file{/usr/local/include/python1.5} in this
482 case---is always included in the search path when building Python
483 extensions, the best approach is to include (e.g.)
484 \code{<Numerical/arrayobject.h>}. If you insist on putting the
485 \file{Numerical} include directory right into your header search path,
486 though, you can find that directory using the Distutils
487 \module{sysconfig} module:
488 \begin{verbatim}
489 from distutils.sysconfig import get_python_inc
490 incdir = os.path.join(get_python_inc(plat_specific=1), "Numerical")
491 setup(...,
492 Extension(..., include_dirs=[incdir]))
493 \end{verbatim}
494 Even though this is quite portable---it will work on any Python
495 installation, regardless of platform---it's probably easier to just
496 write your C code in the sensible way.
498 You can define and undefine pre-processor macros with the
499 \code{define\_macros} and \code{undef\_macros} options.
500 \code{define\_macros} takes a list of \code{(name, value)} tuples, where
501 \code{name} is the name of the macro to define (a string) and
502 \code{value} is its value: either a string or \code{None}. (Defining a
503 macro \code{FOO} to \code{None} is the equivalent of a bare
504 \code{\#define FOO} in your C source: with most compilers, this sets
505 \code{FOO} to the string \code{1}.) \code{undef\_macros} is just
506 a list of macros to undefine.
508 For example:
509 \begin{verbatim}
510 Extension(...,
511 define_macros=[('NDEBUG', '1')],
512 ('HAVE_STRFTIME', None),
513 undef_macros=['HAVE_FOO', 'HAVE_BAR'])
514 \end{verbatim}
515 is the equivalent of having this at the top of every C source file:
516 \begin{verbatim}
517 #define NDEBUG 1
518 #define HAVE_STRFTIME
519 #undef HAVE_FOO
520 #undef HAVE_BAR
521 \end{verbatim}
524 \subsubsection{Library options}
526 You can also specify the libraries to link against when building your
527 extension, and the directories to search for those libraries. The
528 \code{libraries} option is a list of libraries to link against,
529 \code{library\_dirs} is a list of directories to search for libraries at
530 link-time, and \code{runtime\_library\_dirs} is a list of directories to
531 search for shared (dynamically loaded) libraries at run-time.
533 For example, if you need to link against libraries known to be in the
534 standard library search path on target systems
535 \begin{verbatim}
536 Extension(...,
537 libraries=["gdbm", "readline"])
538 \end{verbatim}
540 If you need to link with libraries in a non-standard location, you'll
541 have to include the location in \code{library\_dirs}:
542 \begin{verbatim}
543 Extension(...,
544 library_dirs=["/usr/X11R6/lib"],
545 libraries=["X11", "Xt"])
546 \end{verbatim}
547 (Again, this sort of non-portable construct should be avoided if you
548 intend to distribute your code.)
550 \XXX{Should mention clib libraries here or somewhere else!}
552 \subsubsection{Other options}
554 There are still some other options which can be used to handle special
555 cases.
557 The \option{extra\_objects} option is a list of object files to be passed
558 to the linker. These files must not have extensions, as the default
559 extension for the compiler is used.
561 \option{extra\_compile\_args} and \option{extra\_link\_args} can be used
562 to specify additional command line options for the compiler resp.
563 the linker command line.
565 \option{export\_symbols} is only useful on windows, it can contain a list
566 of symbols (functions or variables) to be exported. This option
567 is not needed when building compiled extensions: the \code{initmodule}
568 function will automatically be added to the exported symbols list
569 by Distutils.
571 \subsection{Listing scripts}
572 So far we have been dealing with pure and non-pure Python modules,
573 which are usually not run by themselves but imported by scripts.
575 Scripts are files containing Python source code, indended to be started
576 from the command line.
577 Distutils doesn't provide much functionality for the scripts: the only
578 support Distutils gives is to adjust the first line of the script
579 if it starts with \code{\#!} and contains the word ``python'' to refer
580 to the current interpreter location.
582 The \option{scripts} option simply is a list of files to be handled
583 in this way.
586 \subsection{Listing additional files}
587 The \option{data\_files} option can be used to specify additional
588 files needed by the module distribution: configuration files,
589 data files, anything which does not fit in the previous categories.
591 \option{data\_files} specify a sequence of \code{(directory, files)}
592 pairs in the following way:
593 \begin{verbatim}
594 setup(...
595 data_files=[('bitmaps', ['bm/b1.gif', 'bm/b2.gif']),
596 ('config', ['cfg/data.cfg'])])
597 \end{verbatim}
599 Note that you can specify the directory names where the data files
600 will be installed, but you cannot rename the data files themselves.
602 You can specify the \option{data\_files} options as a simple sequence
603 of files without specifying a target directory, but this is not recommended,
604 and the \command{install} command will print a warning in this case.
605 To install data files directly in the target directory, an empty
606 string should be given as the directory.
609 \section{Writing the Setup Configuration File}
610 \label{setup-config}
612 Often, it's not possible to write down everything needed to build a
613 distribution \emph{a priori}: you may need to get some information from
614 the user, or from the user's system, in order to proceed. As long as
615 that information is fairly simple---a list of directories to search for
616 C header files or libraries, for example---then providing a
617 configuration file, \file{setup.cfg}, for users to edit is a cheap and
618 easy way to solicit it. Configuration files also let you provide
619 default values for any command option, which the installer can then
620 override either on the command-line or by editing the config file.
622 (If you have more advanced needs, such as determining which extensions
623 to build based on what capabilities are present on the target system,
624 then you need the Distutils ``auto-configuration'' facility. This
625 started to appear in Distutils 0.9 but, as of this writing, isn't mature
626 or stable enough yet for real-world use.)
628 \XXX{should reference description of distutils config files in
629 ``Installing'' manual here}
631 The setup configuration file is a useful middle-ground between the setup
632 script---which, ideally, would be opaque to installers\footnote{This
633 ideal probably won't be achieved until auto-configuration is fully
634 supported by the Distutils.}---and the command-line to the setup
635 script, which is outside of your control and entirely up to the
636 installer. In fact, \file{setup.cfg} (and any other Distutils
637 configuration files present on the target system) are processed after
638 the contents of the setup script, but before the command-line. This has
639 several useful consequences:
640 \begin{itemize}
641 \item installers can override some of what you put in \file{setup.py} by
642 editing \file{setup.cfg}
643 \item you can provide non-standard defaults for options that are not
644 easily set in \file{setup.py}
645 \item installers can override anything in \file{setup.cfg} using the
646 command-line options to \file{setup.py}
647 \end{itemize}
649 The basic syntax of the configuration file is simple:
650 \begin{verbatim}
651 [command]
652 option=value
654 \end{verbatim}
655 where \var{command} is one of the Distutils commands (e.g.
656 \command{build\_py}, \command{install}), and \var{option} is one of the
657 options that command supports. Any number of options can be supplied
658 for each command, and any number of command sections can be included in
659 the file. Blank lines are ignored, as are comments (from a
660 \character{\#} character to end-of-line). Long option values can be
661 split across multiple lines simply by indenting the continuation lines.
663 You can find out the list of options supported by a particular command
664 with the universal \longprogramopt{help} option, e.g.
665 \begin{verbatim}
666 > python setup.py --help build_ext
667 [...]
668 Options for 'build_ext' command:
669 --build-lib (-b) directory for compiled extension modules
670 --build-temp (-t) directory for temporary files (build by-products)
671 --inplace (-i) ignore build-lib and put compiled extensions into the
672 source directory alongside your pure Python modules
673 --include-dirs (-I) list of directories to search for header files
674 --define (-D) C preprocessor macros to define
675 --undef (-U) C preprocessor macros to undefine
676 [...]
677 \end{verbatim}
678 Or consult section \ref{reference} of this document (the command
679 reference).
681 Note that an option spelled \longprogramopt{foo-bar} on the command-line
682 is spelled \option{foo\_bar} in configuration files.
684 For example, say you want your extensions to be built
685 ``in-place''---that is, you have an extension \module{pkg.ext}, and you
686 want the compiled extension file (\file{ext.so} on \UNIX, say) to be put
687 in the same source directory as your pure Python modules
688 \module{pkg.mod1} and \module{pkg.mod2}. You can always use the
689 \longprogramopt{inplace} option on the command-line to ensure this:
690 \begin{verbatim}
691 python setup.py build_ext --inplace
692 \end{verbatim}
693 But this requires that you always specify the \command{build\_ext}
694 command explicitly, and remember to provide \longprogramopt{inplace}.
695 An easier way is to ``set and forget'' this option, by encoding it in
696 \file{setup.cfg}, the configuration file for this distribution:
697 \begin{verbatim}
698 [build_ext]
699 inplace=1
700 \end{verbatim}
701 This will affect all builds of this module distribution, whether or not
702 you explcitly specify \command{build\_ext}. If you include
703 \file{setup.cfg} in your source distribution, it will also affect
704 end-user builds---which is probably a bad idea for this option, since
705 always building extensions in-place would break installation of the
706 module distribution. In certain peculiar cases, though, modules are
707 built right in their installation directory, so this is conceivably a
708 useful ability. (Distributing extensions that expect to be built in
709 their installation directory is almost always a bad idea, though.)
711 Another example: certain commands take a lot of options that don't
712 change from run-to-run; for example, \command{bdist\_rpm} needs to know
713 everything required to generate a ``spec'' file for creating an RPM
714 distribution. Some of this information comes from the setup script, and
715 some is automatically generated by the Distutils (such as the list of
716 files installed). But some of it has to be supplied as options to
717 \command{bdist\_rpm}, which would be very tedious to do on the
718 command-line for every run. Hence, here is a snippet from the
719 Distutils' own \file{setup.cfg}:
720 \begin{verbatim}
721 [bdist_rpm]
722 release = 1
723 packager = Greg Ward <gward@python.net>
724 doc_files = CHANGES.txt
725 README.txt
726 USAGE.txt
727 doc/
728 examples/
729 \end{verbatim}
730 Note that the \option{doc\_files} option is simply a
731 whitespace-separated string split across multiple lines for readability.
734 \section{Creating a Source Distribution}
735 \label{source-dist}
737 As shown in section~\ref{simple-example}, you use the
738 \command{sdist} command to create a source distribution. In the
739 simplest case,
740 \begin{verbatim}
741 python setup.py sdist
742 \end{verbatim}
743 (assuming you haven't specified any \command{sdist} options in the setup
744 script or config file), \command{sdist} creates the archive of the
745 default format for the current platform. The default format is gzip'ed
746 tar file (\file{.tar.gz}) on \UNIX, and ZIP file on Windows.
747 \XXX{no MacOS support here}
749 You can specify as many formats as you like using the
750 \longprogramopt{formats} option, for example:
751 \begin{verbatim}
752 python setup.py sdist --formats=gztar,zip
753 \end{verbatim}
754 to create a gzipped tarball and a zip file. The available formats are:
755 \begin{tableiii}{l|l|c}{code}%
756 {Format}{Description}{Notes}
757 \lineiii{zip}{zip file (\file{.zip})}{(1),(3)}
758 \lineiii{gztar}{gzip'ed tar file (\file{.tar.gz})}{(2),(4)}
759 \lineiii{bztar}{bzip2'ed tar file (\file{.tar.gz})}{(4)}
760 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(4)}
761 \lineiii{tar}{tar file (\file{.tar})}{(4)}
762 \end{tableiii}
764 \noindent Notes:
765 \begin{description}
766 \item[(1)] default on Windows
767 \item[(2)] default on \UNIX
768 \item[(3)] requires either external \program{zip} utility or
769 \module{zipfile} module (not part of the standard Python library)
770 \item[(4)] requires external utilities: \program{tar} and possibly one
771 of \program{gzip}, \program{bzip2}, or \program{compress}
772 \end{description}
776 \subsection{Specifying the files to distribute}
777 \label{manifest}
779 If you don't supply an explicit list of files (or instructions on how to
780 generate one), the \command{sdist} command puts a minimal default set
781 into the source distribution:
782 \begin{itemize}
783 \item all Python source files implied by the \option{py\_modules} and
784 \option{packages} options
785 \item all C source files mentioned in the \option{ext\_modules} or
786 \option{libraries} options (\XXX{getting C library sources currently
787 broken -- no get\_source\_files() method in build\_clib.py!})
788 \item anything that looks like a test script: \file{test/test*.py}
789 (currently, the Distutils don't do anything with test scripts except
790 include them in source distributions, but in the future there will be
791 a standard for testing Python module distributions)
792 \item \file{README.txt} (or \file{README}), \file{setup.py} (or whatever
793 you called your setup script), and \file{setup.cfg}
794 \end{itemize}
795 Sometimes this is enough, but usually you will want to specify
796 additional files to distribute. The typical way to do this is to write
797 a \emph{manifest template}, called \file{MANIFEST.in} by default. The
798 manifest template is just a list of instructions for how to generate
799 your manifest file, \file{MANIFEST}, which is the exact list of files to
800 include in your source distribution. The \command{sdist} command
801 processes this template and generates a manifest based on its
802 instructions and what it finds in the filesystem.
804 If you prefer to roll your own manifest file, the format is simple: one
805 filename per line, regular files (or symlinks to them) only. If you do
806 supply your own \file{MANIFEST}, you must specify everything: the
807 default set of files described above does not apply in this case.
809 The manifest template has one command per line, where each command
810 specifies a set of files to include or exclude from the source
811 distribution. For an example, again we turn to the Distutils' own
812 manifest template:
813 \begin{verbatim}
814 include *.txt
815 recursive-include examples *.txt *.py
816 prune examples/sample?/build
817 \end{verbatim}
818 The meanings should be fairly clear: include all files in the
819 distribution root matching \code{*.txt}, all files anywhere under the
820 \file{examples} directory matching \code{*.txt} or \code{*.py}, and
821 exclude all directories matching \code{examples/sample?/build}. All of
822 this is done \emph{after} the standard include set, so you can exclude
823 files from the standard set with explicit instructions in the manifest
824 template. (Or, you can use the \longprogramopt{no-defaults} option to
825 disable the standard set entirely.) There are several other commands
826 available in the manifest template mini-language; see
827 section~\ref{sdist-cmd}.
829 The order of commands in the manifest template matters: initially, we
830 have the list of default files as described above, and each command in
831 the template adds to or removes from that list of files. Once we have
832 fully processed the manifest template, we remove files that should not
833 be included in the source distribution:
834 \begin{itemize}
835 \item all files in the Distutils ``build'' tree (default \file{build/})
836 \item all files in directories named \file{RCS} or \file{CVS}
837 \end{itemize}
838 Now we have our complete list of files, which is written to the manifest
839 for future reference, and then used to build the source distribution
840 archive(s).
842 You can disable the default set of included files with the
843 \longprogramopt{no-defaults} option, and you can disable the standard
844 exclude set with \longprogramopt{no-prune}.
846 Following the Distutils' own manifest template, let's trace how the
847 \command{sdist} command builds the list of files to include in the
848 Distutils source distribution:
849 \begin{enumerate}
850 \item include all Python source files in the \file{distutils} and
851 \file{distutils/command} subdirectories (because packages
852 corresponding to those two directories were mentioned in the
853 \option{packages} option in the setup script---see
854 section~\ref{setup-script})
855 \item include \file{README.txt}, \file{setup.py}, and \file{setup.cfg}
856 (standard files)
857 \item include \file{test/test*.py} (standard files)
858 \item include \file{*.txt} in the distribution root (this will find
859 \file{README.txt} a second time, but such redundancies are weeded out
860 later)
861 \item include anything matching \file{*.txt} or \file{*.py} in the
862 sub-tree under \file{examples},
863 \item exclude all files in the sub-trees starting at directories
864 matching \file{examples/sample?/build}---this may exclude files
865 included by the previous two steps, so it's important that the
866 \code{prune} command in the manifest template comes after the
867 \code{recursive-include} command
868 \item exclude the entire \file{build} tree, and any \file{RCS} or
869 \file{CVS} directories
870 \end{enumerate}
871 Just like in the setup script, file and directory names in the manifest
872 template should always be slash-separated; the Distutils will take care
873 of converting them to the standard representation on your platform.
874 That way, the manifest template is portable across operating systems.
877 \subsection{Manifest-related options}
878 \label{manifest-options}
880 The normal course of operations for the \command{sdist} command is as
881 follows:
882 \begin{itemize}
883 \item if the manifest file, \file{MANIFEST} doesn't exist, read
884 \file{MANIFEST.in} and create the manifest
885 \item if neither \file{MANIFEST} nor \file{MANIFEST.in} exist, create a
886 manifest with just the default file set\footnote{In versions of the
887 Distutils up to and including 0.9.2 (Python 2.0b1), this feature was
888 broken; use the \programopt{-f} (\longprogramopt{force-manifest})
889 option to work around the bug.}
890 \item if either \file{MANIFEST.in} or the setup script (\file{setup.py})
891 are more recent than \file{MANIFEST}, recreate \file{MANIFEST} by
892 reading \file{MANIFEST.in}
893 \item use the list of files now in \file{MANIFEST} (either just
894 generated or read in) to create the source distribution archive(s)
895 \end{itemize}
896 There are a couple of options that modify this behaviour. First, use
897 the \longprogramopt{no-defaults} and \longprogramopt{no-prune} to
898 disable the standard ``include'' and ``exclude'' sets.\footnote{Note
899 that if you have no manifest template, no manifest, and use the
900 \longprogramopt{no-defaults}, you will get an empty manifest. Another
901 bug in Distutils 0.9.2 and earlier causes an uncaught exception in
902 this case. The workaround is: Don't Do That.}
904 Second, you might want to force the manifest to be regenerated---for
905 example, if you have added or removed files or directories that match an
906 existing pattern in the manifest template, you should regenerate the
907 manifest:
908 \begin{verbatim}
909 python setup.py sdist --force-manifest
910 \end{verbatim}
912 Or, you might just want to (re)generate the manifest, but not create a
913 source distribution:
914 \begin{verbatim}
915 python setup.py sdist --manifest-only
916 \end{verbatim}
917 \longprogramopt{manifest-only} implies \longprogramopt{force-manifest}.
918 \programopt{-o} is a shortcut for \longprogramopt{manifest-only}, and
919 \programopt{-f} for \longprogramopt{force-manifest}.
922 \section{Creating Built Distributions}
923 \label{built-dist}
925 A ``built distribution'' is what you're probably used to thinking of
926 either as a ``binary package'' or an ``installer'' (depending on your
927 background). It's not necessarily binary, though, because it might
928 contain only Python source code and/or byte-code; and we don't call it a
929 package, because that word is already spoken for in Python. (And
930 ``installer'' is a term specific to the Windows world. \XXX{do Mac
931 people use it?})
933 A built distribution is how you make life as easy as possible for
934 installers of your module distribution: for users of RPM-based Linux
935 systems, it's a binary RPM; for Windows users, it's an executable
936 installer; for Debian-based Linux users, it's a Debian package; and so
937 forth. Obviously, no one person will be able to create built
938 distributions for every platform under the sun, so the Distutils are
939 designed to enable module developers to concentrate on their
940 specialty---writing code and creating source distributions---while an
941 intermediary species of \emph{packager} springs up to turn source
942 distributions into built distributions for as many platforms as there
943 are packagers.
945 Of course, the module developer could be his own packager; or the
946 packager could be a volunteer ``out there'' somewhere who has access to
947 a platform which the original developer does not; or it could be
948 software periodically grabbing new source distributions and turning them
949 into built distributions for as many platforms as the software has
950 access to. Regardless of the nature of the beast, a packager uses the
951 setup script and the \command{bdist} command family to generate built
952 distributions.
954 As a simple example, if I run the following command in the Distutils
955 source tree:
956 \begin{verbatim}
957 python setup.py bdist
958 \end{verbatim}
959 then the Distutils builds my module distribution (the Distutils itself
960 in this case), does a ``fake'' installation (also in the \file{build}
961 directory), and creates the default type of built distribution for my
962 platform. The default format for built distributions is a ``dumb'' tar
963 file on \UNIX, and an simple executable installer on Windows. (That tar
964 file is considered ``dumb'' because it has to be unpacked in a specific
965 location to work.)
967 Thus, the above command on a \UNIX{} system creates
968 \file{Distutils-0.9.1.\filevar{plat}.tar.gz}; unpacking this tarball
969 from the right place installs the Distutils just as though you had
970 downloaded the source distribution and run \code{python setup.py
971 install}. (The ``right place'' is either the root of the filesystem or
972 Python's \filevar{prefix} directory, depending on the options given to
973 the \command{bdist\_dumb} command; the default is to make dumb
974 distributions relative to \filevar{prefix}.)
976 Obviously, for pure Python distributions, this isn't a huge win---but
977 for non-pure distributions, which include extensions that would need to
978 be compiled, it can mean the difference between someone being able to
979 use your extensions or not. And creating ``smart'' built distributions,
980 such as an RPM package or an executable installer for Windows, is a big
981 win for users even if your distribution doesn't include any extensions.
983 The \command{bdist} command has a \longprogramopt{formats} option,
984 similar to the \command{sdist} command, which you can use to select the
985 types of built distribution to generate: for example,
986 \begin{verbatim}
987 python setup.py bdist --format=zip
988 \end{verbatim}
989 would, when run on a \UNIX{} system, create
990 \file{Distutils-0.8.\filevar{plat}.zip}---again, this archive would be
991 unpacked from the root directory to install the Distutils.
993 The available formats for built distributions are:
994 \begin{tableiii}{l|l|c}{code}%
995 {Format}{Description}{Notes}
996 \lineiii{gztar}{gzipped tar file (\file{.tar.gz})}{(1),(3)}
997 \lineiii{ztar}{compressed tar file (\file{.tar.Z})}{(3)}
998 \lineiii{tar}{tar file (\file{.tar})}{(3)}
999 \lineiii{zip}{zip file (\file{.zip})}{(4)}
1000 \lineiii{rpm}{RPM}{(5)}
1001 \lineiii{srpm}{source RPM}{(5) \XXX{to do!}}
1002 \lineiii{wininst}{self-extracting ZIP file for Windows}{(2),(4)}
1003 \end{tableiii}
1005 \noindent Notes:
1006 \begin{description}
1007 \item[(1)] default on \UNIX
1008 \item[(2)] default on Windows \XXX{to-do!}
1009 \item[(3)] requires external utilities: \program{tar} and possibly one
1010 of \program{gzip}, \program{bzip2}, or \program{compress}
1011 \item[(4)] requires either external \program{zip} utility or
1012 \module{zipfile} module (not part of the standard Python library)
1013 \item[(5)] requires external \program{rpm} utility, version 3.0.4 or
1014 better (use \code{rpm --version} to find out which version you have)
1015 \end{description}
1017 You don't have to use the \command{bdist} command with the
1018 \longprogramopt{formats} option; you can also use the command that
1019 directly implements the format you're interested in. Some of these
1020 \command{bdist} ``sub-commands'' actually generate several similar
1021 formats; for instance, the \command{bdist\_dumb} command generates all
1022 the ``dumb'' archive formats (\code{tar}, \code{ztar}, \code{gztar}, and
1023 \code{zip}), and \command{bdist\_rpm} generates both binary and source
1024 RPMs. The \command{bdist} sub-commands, and the formats generated by
1025 each, are:
1026 \begin{tableii}{l|l}{command}%
1027 {Command}{Formats}
1028 \lineii{bdist\_dumb}{tar, ztar, gztar, zip}
1029 \lineii{bdist\_rpm}{rpm, srpm}
1030 \lineii{bdist\_wininst}{wininst}
1031 \end{tableii}
1033 The following sections give details on the individual \command{bdist\_*}
1034 commands.
1037 \subsection{Creating dumb built distributions}
1038 \label{creating-dumb}
1040 \XXX{Need to document absolute vs. prefix-relative packages here, but
1041 first I have to implement it!}
1044 \subsection{Creating RPM packages}
1045 \label{creating-rpms}
1047 The RPM format is used by many of popular Linux distributions, including
1048 Red Hat, SuSE, and Mandrake. If one of these (or any of the other
1049 RPM-based Linux distributions) is your usual environment, creating RPM
1050 packages for other users of that same distribution is trivial.
1051 Depending on the complexity of your module distribution and differences
1052 between Linux distributions, you may also be able to create RPMs that
1053 work on different RPM-based distributions.
1055 The usual way to create an RPM of your module distribution is to run the
1056 \command{bdist\_rpm} command:
1057 \begin{verbatim}
1058 python setup.py bdist_rpm
1059 \end{verbatim}
1060 or the \command{bdist} command with the \longprogramopt{format} option:
1061 \begin{verbatim}
1062 python setup.py bdist --formats=rpm
1063 \end{verbatim}
1064 The former allows you to specify RPM-specific options; the latter allows
1065 you to easily specify multiple formats in one run. If you need to do
1066 both, you can explicitly specify multiple \command{bdist\_*} commands
1067 and their options:
1068 \begin{verbatim}
1069 python setup.py bdist_rpm --packager="John Doe <jdoe@python.net>" \
1070 bdist_wininst --target_version="2.0"
1071 \end{verbatim}
1073 Creating RPM packages is driven by a \file{.spec} file, much as using
1074 the Distutils is driven by the setup script. To make your life easier,
1075 the \command{bdist\_rpm} command normally creates a \file{.spec} file
1076 based on the information you supply in the setup script, on the command
1077 line, and in any Distutils configuration files. Various options and
1078 sections in the \file{.spec} file are derived from options in the setup
1079 script as follows:
1080 \begin{tableii}{l|l}{textrm}%
1081 {RPM \file{.spec} file option or section}{Distutils setup script option}
1082 \lineii{Name}{\option{name}}
1083 \lineii{Summary (in preamble)}{\option{description}}
1084 \lineii{Version}{\option{version}}
1085 \lineii{Vendor}{\option{author} and \option{author\_email}, or \\&
1086 \option{maintainer} and \option{maintainer\_email}}
1087 \lineii{Copyright}{\option{licence}}
1088 \lineii{Url}{\option{url}}
1089 \lineii{\%description (section)}{\option{long\_description}}
1090 \end{tableii}
1092 Additionally, there many options in \file{.spec} files that don't have
1093 corresponding options in the setup script. Most of these are handled
1094 through options to the \command{bdist\_rpm} command as follows:
1095 \begin{tableiii}{l|l|l}{textrm}%
1096 {RPM \file{.spec} file option or section}%
1097 {\command{bdist\_rpm} option}%
1098 {default value}
1099 \lineiii{Release}{\option{release}}{``1''}
1100 \lineiii{Group}{\option{group}}{``Development/Libraries''}
1101 \lineiii{Vendor}{\option{vendor}}{(see above)}
1102 \lineiii{Packager}{\option{packager}}{(none)}
1103 \lineiii{Provides}{\option{provides}}{(none)}
1104 \lineiii{Requires}{\option{requires}}{(none)}
1105 \lineiii{Conflicts}{\option{conflicts}}{(none)}
1106 \lineiii{Obsoletes}{\option{obsoletes}}{(none)}
1107 \lineiii{Distribution}{\option{distribution\_name}}{(none)}
1108 \lineiii{BuildRequires}{\option{build\_requires}}{(none)}
1109 \lineiii{Icon}{\option{icon}}{(none)}
1110 \end{tableiii}
1111 Obviously, supplying even a few of these options on the command-line
1112 would be tedious and error-prone, so it's usually best to put them in
1113 the setup configuration file, \file{setup.cfg}---see
1114 section~\ref{setup-config}. If you distribute or package many Python
1115 module distributions, you might want to put options that apply to all of
1116 them in your personal Distutils configuration file
1117 (\file{\textasciitilde/.pydistutils.cfg}).
1119 There are three steps to building a binary RPM package, all of which are
1120 handled automatically by the Distutils:
1121 \begin{enumerate}
1122 \item create a \file{.spec} file, which describes the package (analogous
1123 to the Distutils setup script; in fact, much of the information in the
1124 setup script winds up in the \file{.spec} file)
1125 \item create the source RPM
1126 \item create the ``binary'' RPM (which may or may not contain binary
1127 code, depending on whether your module distribution contains Python
1128 extensions)
1129 \end{enumerate}
1130 Normally, RPM bundles the last two steps together; when you use the
1131 Distutils, all three steps are typically bundled together.
1133 If you wish, you can separate these three steps. You can use the
1134 \longprogramopt{spec-only} option to make \command{bdist\_rpm} just
1135 create the \file{.spec} file and exit; in this case, the \file{.spec}
1136 file will be written to the ``distribution directory''---normally
1137 \file{dist/}, but customizable with the \longprogramopt{dist-dir}
1138 option. (Normally, the \file{.spec} file winds up deep in the ``build
1139 tree,'' in a temporary directory created by \command{bdist\_rpm}.)
1141 \XXX{this isn't implemented yet---is it needed?!}
1142 You can also specify a custom \file{.spec} file with the
1143 \longprogramopt{spec-file} option; used in conjunction with
1144 \longprogramopt{spec-only}, this gives you an opportunity to customize
1145 the \file{.spec} file manually:
1146 \begin{verbatim}
1147 > python setup.py bdist_rpm --spec-only
1148 # ...edit dist/FooBar-1.0.spec
1149 > python setup.py bdist_rpm --spec-file=dist/FooBar-1.0.spec
1150 \end{verbatim}
1151 (Although a better way to do this is probably to override the standard
1152 \command{bdist\_rpm} command with one that writes whatever else you want
1153 to the \file{.spec} file; see section~\ref{extending} for information on
1154 extending the Distutils.)
1157 \subsection{Creating Windows installers}
1158 \label{creating-wininst}
1160 Executable Windows installers are the natural format for binary
1161 distributions on Windows. They display a nice GUI interface, display
1162 some information of the module distribution to be installed, taken
1163 from the meta-dada in the setup script, let the user select a few
1164 (currently maybe too few) options, and start or cancel the installation.
1166 Since the meta-data is taken from the setup script, creating
1167 Windows installers is usually as easy as running:
1168 \begin{verbatim}
1169 python setup.py bdist_wininst
1170 \end{verbatim}
1171 or the \command{bdist} command with the \longprogramopt{format} option:
1172 \begin{verbatim}
1173 python setup.py bdist --formats=wininst
1174 \end{verbatim}
1176 If you have a pure module distribution (only containing pure
1177 Python modules and packages), the resulting installer will be
1178 version independent and have a name like \file{Foo-1.0.win32.exe}.
1179 These installers can even be created on \UNIX{} or MacOS platforms.
1181 If you have a non-pure distribution, the extensions can only be
1182 created on a Windows platform, and will be Python version dependend.
1183 The installer filename will reflect this and now has the form
1184 \file{Foo-1.0.win32-py2.0.exe}. You have to create a separate installer
1185 for every Python version you want to support.
1187 The installer will try to compile pure modules into bytecode after
1188 installation on the target system in normal and optimizing mode.
1189 If you don't want this to happen for some reason, you can run
1190 the bdist_wininst command with the \longprogramopt{no-target-compile} and/or
1191 the \longprogramopt{no-target-optimize} option.
1193 \section{Examples}
1194 \label{examples}
1197 \subsection{Pure Python distribution (by module)}
1198 \label{pure-mod}
1201 \subsection{Pure Python distribution (by package)}
1202 \label{pure-pkg}
1205 \subsection{Single extension module}
1206 \label{single-ext}
1209 \subsection{Multiple extension modules}
1210 \label{multiple-ext}
1213 \subsection{Putting it all together}
1217 \section{Extending the Distutils}
1218 \label{extending}
1221 \subsection{Extending existing commands}
1222 \label{extend-existing}
1225 \subsection{Writing new commands}
1226 \label{new-commands}
1228 \XXX{Would an uninstall command be a good example here?}
1232 \section{Reference}
1233 \label{reference}
1236 \subsection{Building modules: the \protect\command{build} command family}
1237 \label{build-cmds}
1239 \subsubsection{\protect\command{build}}
1240 \label{build-cmd}
1242 \subsubsection{\protect\command{build\_py}}
1243 \label{build-py-cmd}
1245 \subsubsection{\protect\command{build\_ext}}
1246 \label{build-ext-cmd}
1248 \subsubsection{\protect\command{build\_clib}}
1249 \label{build-clib-cmd}
1252 \subsection{Installing modules: the \protect\command{install} command family}
1253 \label{install-cmd}
1255 The install command ensures that the build commands have been run and then
1256 runs the subcommands \command{install\_lib},
1257 \command{install\_data} and
1258 \command{install\_scripts}.
1260 \subsubsection{\protect\command{install\_lib}}
1261 \label{install-lib-cmd}
1263 \subsubsection{\protect\command{install\_data}}
1264 \label{install-data-cmd}
1265 This command installs all data files provided with the distribution.
1267 \subsubsection{\protect\command{install\_scripts}}
1268 \label{install-scripts-cmd}
1269 This command installs all (Python) scripts in the distribution.
1272 \subsection{Cleaning up: the \protect\command{clean} command}
1273 \label{clean-cmd}
1276 \subsection{Creating a source distribution: the
1277 \protect\command{sdist} command}
1278 \label{sdist-cmd}
1281 \XXX{fragment moved down from above: needs context!}
1283 The manifest template commands are:
1284 \begin{tableii}{ll}{command}{Command}{Description}
1285 \lineii{include \var{pat1} \var{pat2} ... }
1286 {include all files matching any of the listed patterns}
1287 \lineii{exclude \var{pat1} \var{pat2} ... }
1288 {exclude all files matching any of the listed patterns}
1289 \lineii{recursive-include \var{dir} \var{pat1} \var{pat2} ... }
1290 {include all files under \var{dir} matching any of the listed patterns}
1291 \lineii{recursive-exclude \var{dir} \var{pat1} \var{pat2} ...}
1292 {exclude all files under \var{dir} matching any of the listed patterns}
1293 \lineii{global-include \var{pat1} \var{pat2} ...}
1294 {include all files anywhere in the source tree matching\\&
1295 any of the listed patterns}
1296 \lineii{global-exclude \var{pat1} \var{pat2} ...}
1297 {exclude all files anywhere in the source tree matching\\&
1298 any of the listed patterns}
1299 \lineii{prune \var{dir}}{exclude all files under \var{dir}}
1300 \lineii{graft \var{dir}}{include all files under \var{dir}}
1301 \end{tableii}
1302 The patterns here are \UNIX-style ``glob'' patterns: \code{*} matches any
1303 sequence of regular filename characters, \code{?} matches any single
1304 regular filename character, and \code{[\var{range}]} matches any of the
1305 characters in \var{range} (e.g., \code{a-z}, \code{a-zA-Z},
1306 \code{a-f0-9\_.}). The definition of ``regular filename character'' is
1307 platform-specific: on \UNIX{} it is anything except slash; on Windows
1308 anything except backslash or colon; on MacOS anything except colon.
1310 \XXX{Windows and MacOS support not there yet}
1313 \subsection{Creating a ``built'' distribution: the
1314 \protect\command{bdist} command family}
1315 \label{bdist-cmds}
1318 \subsubsection{\protect\command{blib}}
1320 \subsubsection{\protect\command{blib\_dumb}}
1322 \subsubsection{\protect\command{blib\_rpm}}
1324 \subsubsection{\protect\command{blib\_wise}}
1333 \end{document}