Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 1 | \documentclass{howto} |
| 2 | \usepackage{ltxmarkup} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 3 | \usepackage{times} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 4 | \usepackage{distutils} |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 5 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 6 | \title{Distributing Python Modules} |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 7 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 8 | \author{Greg Ward} |
| 9 | \authoraddress{E-mail: \email{gward@python.net}} |
| 10 | |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 11 | |
| 12 | \newcommand{\XXX}[1]{\textbf{**#1**}} |
| 13 | |
| 14 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 15 | \begin{document} |
| 16 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 17 | \maketitle |
| 18 | \tableofcontents |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 19 | |
| 20 | \section{Introduction} |
| 21 | \label{sec:intro} |
| 22 | |
| 23 | In the past, Python module developers have not had much infrastructure |
| 24 | support for distributing modules, nor have Python users had much support |
| 25 | for installing and maintaining third-party modules. With the |
| 26 | introduction of the Python Distribution Utilities (Distutils for short) |
| 27 | in Python 1.6, this situation should start to improve. |
| 28 | |
| 29 | This document only covers using the Distutils to distribute your Python |
| 30 | modules. Using the Distutils does not tie you to Python 1.6, though: |
| 31 | the Distutils work just fine with Python 1.5, and it is reasonable (and |
| 32 | expected to become commonplace) to expect users of Python 1.5 to |
| 33 | download and install the Distutils separately before they can install |
| 34 | your modules. Python 1.6 users, of course, won't have to add anything |
| 35 | to their Python installation in order to use the Distutils to install |
| 36 | third-party modules. |
| 37 | |
| 38 | This document concentrates on the role of developer/distributor: if |
| 39 | you're looking for information on installing Python modules, you should |
| 40 | refer to the ``Installing Python Modules'' manual. |
| 41 | |
| 42 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 43 | \section{Concepts \& Terminology} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 44 | \label{sec:concepts} |
| 45 | |
| 46 | Using the Distutils is quite simple, both for module developers and for |
| 47 | users/administrators installing third-party modules. As a developer, |
| 48 | your responsibilites (apart from writing solid, well-documented and |
| 49 | well-tested code, of course!) are: |
| 50 | \begin{itemize} |
| 51 | \item write a setup script (\file{setup.py} by convention) |
| 52 | \item (optional) write a setup configuration file |
| 53 | \item create a source distribution |
| 54 | \item (optional) create one or more built (binary) distributions |
| 55 | \end{itemize} |
| 56 | Each of these tasks is covered in this document. |
| 57 | |
| 58 | Not all module developers have access to a multitude of platforms, so |
| 59 | it's not always feasible to expect them to create a multitude of built |
| 60 | distributions. It is hoped that a class of intermediaries, called |
| 61 | \emph{packagers}, will arise to take address this need. Packagers will |
| 62 | take source distributions released by module developers, build them on |
| 63 | one or more platforms, and release the resulting built distributions. |
| 64 | Thus, users on the most popular platforms will be able to install most |
| 65 | popular Python module distributions in the most natural way for their |
| 66 | platform, without having to run a single setup script or compile a line |
| 67 | of code. |
| 68 | |
| 69 | |
| 70 | \subsection{A simple example} |
| 71 | \label{sec:simple-example} |
| 72 | |
| 73 | The setup script is usually quite simple, although since it's written in |
| 74 | Python, there are no arbitrary limits to what you can do. If all you |
| 75 | want to do is distribute a module called \module{foo}, contained in a |
| 76 | file \file{foo.py}, then you can get away with as little as this: |
| 77 | \begin{verbatim} |
| 78 | from distutils.core import setup |
| 79 | setup (name = "foo", |
| 80 | version = "1.0", |
| 81 | py_modules = ["foo"]) |
| 82 | \end{verbatim} |
| 83 | Some observations: |
| 84 | \begin{itemize} |
| 85 | \item all information that you supply to the Distutils is supplied as |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 86 | keyword arguments to the \function{setup()} function |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 87 | \item those keyword arguments fall into two categories: package |
| 88 | meta-data (name, version number) and information about what's in the |
| 89 | package (list of pure modules, in this case) |
| 90 | \item modules are specified by module name, not filename (the same will |
| 91 | hold true for packages and extensions) |
| 92 | \item it's recommended that you supply a little more meta-data, in |
| 93 | particular your name, email address and a URL for the project |
| 94 | \end{itemize} |
| 95 | |
| 96 | To create a source distribution for this module, you would run |
| 97 | \begin{verbatim} |
| 98 | python setup.py sdist |
| 99 | \end{verbatim} |
| 100 | which will create an archive file (e.g., tarball on Unix, zip file on |
| 101 | Windows) containing your setup script, \file{setup.py}, and your module, |
| 102 | \file{foo.py}. The archive file will be named \file{Foo-1.0.tar.gz} (or |
| 103 | \file{.zip}), and will unpack into a directory \file{Foo-1.0}. |
| 104 | |
| 105 | If an end-user wishes to install your \module{foo} module, all she has |
| 106 | to do is download \file{Foo-1.0.tar.gz}) (or \file{.zip}), unpack it, |
| 107 | and---from the \file{Foo-1.0} directory---run |
| 108 | \begin{verbatim} |
| 109 | python setup.py install |
| 110 | \end{verbatim} |
| 111 | which will ultimately copy \file{foo.py} to the appropriate directory |
| 112 | for third-party modules in their Python installation. |
| 113 | |
| 114 | This simple example demonstrates some fundamental concepts of the |
| 115 | Distutils: first, both developers and installers have the same basic |
| 116 | user interface, i.e. the setup script. The difference is which |
| 117 | Distutils \emph{commands} they use: the \command{sdist} command is |
| 118 | almost exclusively for module developers, while \command{install} is |
| 119 | more often for installers (although most developers will want to install |
| 120 | their own code occasionally). |
| 121 | |
| 122 | \XXX{only partially implemented}% |
| 123 | If you want to make things really easy for your users, you can create |
| 124 | one or more built distributions for them. For instance, if you are |
| 125 | running on a Windows machine, and want to make things easy for other |
| 126 | Windows users, you can create an executable installer (the most |
| 127 | appropriate type of built distribution for this platform) with the |
| 128 | \command{bdist\_wise} command. (Wise is the installation tool used to |
| 129 | create Windows installers for Python itself, so we have adopted it for |
| 130 | use by any Python module distribution. You'll need to have version XXX |
| 131 | of Wise installed on your system for the \command{bdist\_wise} to work; |
| 132 | it's available from \url{http://foo/bar/baz}. For example: |
| 133 | \begin{verbatim} |
| 134 | python setup.py bdist_wise |
| 135 | \end{verbatim} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 136 | will create an executable installer, \file{Foo-1\_0.exe}, in the current |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 137 | directory. |
| 138 | |
| 139 | \XXX{not implemented yet} |
| 140 | Other \command{bdist\_*} commands exist for RPM-based Linux systems |
| 141 | (\command{bdist\_rpm}), Debian-based Linux systems |
| 142 | (\command{bdist\_deb}), ... |
| 143 | |
| 144 | |
| 145 | \subsection{General Python terminology} |
| 146 | \label{sec:python-terms} |
| 147 | |
| 148 | If you're reading this document, you probably have a good idea of what |
| 149 | modules, extensions, and so forth are. Nevertheless, just to be sure |
| 150 | that everyone is operating from a common starting point, we offer the |
| 151 | following glossary of common Python terms: |
| 152 | \begin{description} |
| 153 | \item[module] the basic unit of code reusability in Python: a block of |
| 154 | code imported by some other code. There are three types of modules |
| 155 | that concern us here: pure Python modules, extension modules, and |
| 156 | packages. |
| 157 | \item[pure Python module] a module written in Python and contained in a |
| 158 | single \file{.py} file (and possibly associated \file{.pyc} and/or |
| 159 | \file{.pyo} files). Sometimes referred to as a ``pure module.'' |
| 160 | \item[extension module] a module written in the low-level language of |
| 161 | the Python implemention: C/C++ for CPython, Java for JPython. |
| 162 | Typically contained in a single dynamically loadable pre-compiled |
| 163 | file, e.g. a shared object (\file{.so}) file for CPython extensions on |
| 164 | Unix, a DLL (given the \file{.pyd} extension) for CPython extensions |
| 165 | on Windows, or a Java class file for JPython extensions. |
| 166 | \item[package] a module that contains other modules; typically contained |
| 167 | in a directory in the filesystem and distinguished from other |
| 168 | directories by the presence of a file \file{\_\_init\_\_.py}. |
| 169 | \end{description} |
| 170 | |
| 171 | |
| 172 | \subsection{Distutils-specific terminology} |
| 173 | \label{sec:distutils-term} |
| 174 | |
| 175 | The following terms apply more specifically to the domain of |
| 176 | distributing Python modules using the Distutils: |
| 177 | \begin{description} |
| 178 | \item[module distribution] a collection of Python modules distributed |
| 179 | together as a single downloadable resource and meant to be installed |
| 180 | \emph{en masse}. Examples of some well-known module distributions are |
| 181 | Numeric Python, PyXML, PIL (the Python Imaging Library), or |
| 182 | mxDateTime. (This would be called a \emph{package}, except that term |
| 183 | is already spoken for in the Python context: a single module |
| 184 | distribution may contain zero, one, or many Python packages.) |
| 185 | \item[pure module distribution] a module distribution that contains only |
| 186 | pure Python modules and packages. Sometimes referred to as a ``pure |
| 187 | distribution.'' |
| 188 | \item[non-pure module distribution] a module distribution that contains |
| 189 | at least one extension module. Sometimes referred to as a ``non-pure |
| 190 | distribution.'' |
| 191 | \item[distribution root] the top-level directory of your source tree (or |
| 192 | source distribution); the directory where \file{setup.py} exists and |
| 193 | is run from |
| 194 | \end{description} |
| 195 | |
| 196 | |
| 197 | \section{Writing the Setup Script} |
| 198 | \label{sec:setup-script} |
| 199 | |
| 200 | The setup script is the centre of all activity in building, |
| 201 | distributing, and installing modules using the Distutils. The main |
| 202 | purpose of the setup script is to describe your module distribution to |
| 203 | the Distutils, so that the various commands that operate on your modules |
| 204 | do the right thing. As we saw in section~\ref{sec:simple-example} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 205 | above, the setup script consists mainly of a call to \function{setup()}, and |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 206 | all information supplied to the Distutils is suppled as keyword |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 207 | arguments to \function{setup()}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 208 | |
| 209 | Here's a slightly more involved example, which we'll follow for the next |
| 210 | couple of sections: the Distutils' own setup script. (Keep in mind that |
| 211 | although the Distutils are included with Python 1.6, they also have an |
| 212 | independent existence so that Python 1.5 users can use them to install |
| 213 | other module distributions.) |
| 214 | |
| 215 | \begin{verbatim} |
| 216 | #!/usr/bin/env python |
| 217 | |
| 218 | from distutils.core import setup |
| 219 | |
| 220 | setup (name = "Distutils", |
| 221 | version = "1.0", |
| 222 | description = "Python Module Distribution Utilities", |
| 223 | author = "Greg Ward", |
| 224 | author_email = "gward@python.net", |
| 225 | url = "http://www.python.org/sigs/distutils-sig/", |
| 226 | |
| 227 | packages = ['distutils', 'distutils.command'], |
| 228 | ) |
| 229 | \end{verbatim} |
| 230 | There are only two differences between this and the trivial one-file |
| 231 | distribution presented in section~\ref{sec:simple-example}: more |
| 232 | meta-data, and the specification of pure Python modules by package, |
| 233 | rather than by module. This is important since the Distutils consist of |
| 234 | a couple of dozen modules split into (so far) two packages; an explicit |
| 235 | list of every module would be tedious to generate and difficult to |
| 236 | maintain. |
| 237 | |
| 238 | |
| 239 | \subsection{Package directories} |
| 240 | \label{sec:package-dirs} |
| 241 | |
| 242 | The \option{packages} option tells the Distutils to process (build, |
| 243 | distribute, install, etc.) all pure Python modules found in each package |
| 244 | mentioned in the \option{packages} list. In order to do this, of |
| 245 | course, there has to be a correspondence between package names and |
| 246 | directories in the filesystem. The default correspondence is the most |
| 247 | obvious one, i.e. package \package{distutils} is found in the directory |
| 248 | \file{distutils} relative to the distribution root. Thus, when you say |
| 249 | \code{packages = ['foo']} in your setup script, you are promising that |
| 250 | the Distutils will find a file \file{foo/\_\_init\_\_.py} (which might |
| 251 | be spelled differently on your system, but you get the idea) relative to |
| 252 | the directory where your setup script lives. (If you break this |
| 253 | promise, the Distutils will issue a warning but process the broken |
| 254 | package anyways.) |
| 255 | |
| 256 | If you use a different convention to lay out your source directory, |
| 257 | that's no problem: you just have to supply the \option{package\_dir} |
| 258 | option to tell the Distutils about your convention. For example, say |
| 259 | you keep all Python source under \file{lib}, so that modules not in any |
| 260 | package are right in \file{lib}, modules in the \package{foo} package |
| 261 | are in \file{lib/foo}, and so forth. Then you would put |
| 262 | \begin{verbatim} |
| 263 | package_dir = {'': 'lib'} |
| 264 | \end{verbatim} |
| 265 | in your setup script. (The keys to this dictionary are package names, |
| 266 | and an empty package name stands for the ``root package,'' i.e. no |
| 267 | package at all. The values are directory names relative to your |
| 268 | distribution root.) In this case, when you say |
| 269 | \code{packages = ['foo']}, you are promising that the file |
| 270 | \file{lib/foo/\_\_init\_\_.py} exists. |
| 271 | |
| 272 | Another possible convention is to put the \package{foo} package right in |
| 273 | \file{lib}, the \package{foo.bar} package in \file{lib/bar}, etc. This |
| 274 | would be written in the setup script as |
| 275 | \begin{verbatim} |
| 276 | package_dir = {'foo': 'lib'} |
| 277 | \end{verbatim} |
| 278 | Note that a \code{\var{package}: \var{dir}} entry in the |
| 279 | \option{package\_dir} option implicitly applies to all packages below |
| 280 | \var{package}, so the \package{foo.bar} case is automatically handled |
| 281 | here. In this example, having \code{packages = ['foo', 'foo.bar']} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 282 | tells the Distutils to look for \file{lib/\_\_init\_\_.py} and |
| 283 | \file{lib/bar/\_\_init\_\_.py}. |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 284 | |
| 285 | |
| 286 | \subsection{Listing individual modules} |
| 287 | \label{sec:listing-modules} |
| 288 | |
| 289 | For a small module distribution, you might prefer to list all modules |
| 290 | rather than listing packages---especially the case of a single module |
| 291 | that goes in the ``root package'' (i.e., no package at all). This |
| 292 | simplest case was shown in section~\ref{sec:simple-example}; here is a |
| 293 | slightly more involved example: |
| 294 | \begin{verbatim} |
| 295 | py_modules = ['mod1', 'pkg.mod2'] |
| 296 | \end{verbatim} |
| 297 | This describes two modules, one of them in the ``root'' package, the |
| 298 | other in the \package{pkg} package. Again, the default |
| 299 | package/directory layout implies that these two modules can be found in |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 300 | \file{mod1.py} and \file{pkg/mod2.py}, and that \file{pkg/\_\_init\_\_.py} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 301 | exists as well. And again, you can override the package/directory |
| 302 | layout using the \option{package\_dir} option. \XXX{not sure if this is |
| 303 | actually true---must check!} |
| 304 | |
| 305 | |
| 306 | \section{Writing the Setup Configuration File} |
| 307 | \label{sec:setup-config} |
| 308 | |
| 309 | \XXX{not implemented yet!} |
| 310 | |
| 311 | Often, it's not possible to write down everything needed to build a |
| 312 | distribution \emph{a priori}. You need to get some information from the |
| 313 | user, or from the user's system, in order to proceed. For example, you |
| 314 | might include an optional extension module that provides an interface to |
| 315 | a particular C library. If that library is installed on the user's |
| 316 | system, then you can build your optional extension---but you need to |
| 317 | know where to find the header and library file. If it's not installed, |
| 318 | you need to know this so you can omit your optional extension. |
| 319 | |
| 320 | The preferred way to do this, of course, would be for you to tell the |
| 321 | Distutils which optional features (C libraries, system calls, external |
| 322 | utilities, etc.) you're looking for, and it would inspect the user's |
| 323 | system and try to find them. This functionality may appear in a future |
| 324 | version of the Distutils, but it isn't there now. So, for the time |
| 325 | being, we rely on the user building and installing your software to |
| 326 | provide the necessary information. The vehicle for doing so is the |
| 327 | setup configuration file, \file{setup.cfg}. |
| 328 | |
| 329 | \XXX{need more here!} |
| 330 | |
| 331 | |
| 332 | \section{Creating a Source Distribution} |
| 333 | \label{sec:source-dist} |
| 334 | |
| 335 | As shown in section~\ref{sec:simple-example}, you use the |
| 336 | \command{sdist} command to create a source distribution. In the |
| 337 | simplest case, |
| 338 | \begin{verbatim} |
| 339 | python setup.py sdist |
| 340 | \end{verbatim} |
| 341 | (assuming you haven't specified any \command{sdist} options in the setup |
| 342 | script or config file), \command{sdist} creates the the archive of the |
| 343 | default format for the current platform. The default formats are: |
| 344 | \begin{tableii}{ll}{textrm}% |
| 345 | {Platform}{Default archive format for source distributions} |
| 346 | \lineii{Unix}{gzipped tar file (\file{.tar.gz})} |
| 347 | \lineii{Windows}{zip file} |
| 348 | \end{tableii} |
| 349 | You can specify as many formats as you like using the \option{--formats} |
| 350 | option, for example: |
| 351 | \begin{verbatim} |
| 352 | python setup.py sdist --formats=gztar,zip |
| 353 | \end{verbatim} |
| 354 | to create a gzipped tarball and a zip file. The available formats are: |
| 355 | \begin{tableii}{ll}{textrm}% |
| 356 | {Format}{Description} |
| 357 | \lineii{zip}{zip file (\file{.zip})} |
| 358 | \lineii{gztar}{gzipped tar file (\file{.tar.gz})} |
| 359 | \lineii{ztar}{compressed tar file (\file{.tar.Z})} |
| 360 | \lineii{tar}{tar file (\file{.tar})} |
| 361 | \end{tableii} |
| 362 | |
| 363 | |
| 364 | \subsection{The manifest and manifest template} |
| 365 | \label{sec:manifest} |
| 366 | |
| 367 | Without any additional information, the \command{sdist} command puts a |
| 368 | minimal set of files into the source distribution: |
| 369 | \begin{itemize} |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 370 | \item all Python source files implied by the \option{py\_modules} and |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 371 | \option{packages} options |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 372 | \item all C source files mentioned in the \option{ext\_modules} or |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 373 | \option{libraries} options (\XXX{getting C library sources currently |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 374 | broken -- no get\_source\_files() method in build\_clib.py!}) |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 375 | \item anything that looks like a test script: \file{test/test*.py} |
| 376 | (currently, the Distutils don't do anything with test scripts except |
| 377 | include them in source distributions, but in the future there will be |
| 378 | a standard for testing Python module distributions) |
| 379 | \item \file{README.txt} (or \file{README}) and \file{setup.py} |
| 380 | \end{itemize} |
| 381 | Sometimes this is enough, but usually you will want to specify |
| 382 | additional files to distribute. The typical way to do this is to write |
| 383 | a \emph{manifest template}, called \file{MANIFEST.in} by default. The |
| 384 | \command{sdist} command processes this template and generates a manifest |
| 385 | file, \file{MANIFEST}. (If you prefer, you can skip the manifest |
| 386 | template and generate the manifest yourself: it just lists one file per |
| 387 | line.) |
| 388 | |
| 389 | The manifest template has one command per line, where each command |
| 390 | specifies a set of files to include or exclude from the source |
| 391 | distribution. For an example, again we turn to the Distutils' own |
| 392 | manifest template: |
| 393 | \begin{verbatim} |
| 394 | include *.txt |
| 395 | recursive-include examples *.txt |
| 396 | recursive-include examples *.py |
| 397 | prune examples/sample?/build |
| 398 | \end{verbatim} |
| 399 | The meanings should be fairly clear: include all files in the |
| 400 | distribution root matching \code{*.txt}, all files anywhere under the |
| 401 | \file{examples} directory matching \code{*.txt} or \code{*.py}, and |
| 402 | exclude all directories matching \code{examples/sample?/build}. There |
| 403 | are several other commands available in the manifest template |
| 404 | mini-language; see section~\ref{sec:sdist-cmd}. |
| 405 | |
| 406 | The order of commands in the manifest template very much matters: |
| 407 | initially, we have the list of default files as described above, and |
| 408 | each command in the template adds to or removes from that list of files. |
| 409 | When we have fully processed the manifest template, we have our complete |
| 410 | list of files. This list is written to the manifest for future |
| 411 | reference, and then used to build the source distribution archive(s). |
| 412 | |
| 413 | We can now see how the \command{sdist} command will build the list of |
| 414 | files to include in the Distutils source distribution: |
| 415 | \begin{enumerate} |
| 416 | \item include all Python source files in the \file{distutils} and |
| 417 | \file{distutils/command} subdirectories (because packages |
| 418 | corresponding to those two directories were mentioned in the |
| 419 | \option{packages} option in the setup script) |
| 420 | \item include \file{test/test*.py} (always included) |
| 421 | \item include \file{README.txt} and \file{setup.py} (always included) |
| 422 | \item include \file{*.txt} in the distribution root (this will find |
| 423 | \file{README.txt} a second time, but such redundancies are weeded out |
| 424 | later) |
| 425 | \item in the sub-tree under \file{examples}, include anything matching |
| 426 | \file{*.txt} |
| 427 | \item in the sub-tree under \file{examples}, include anything matching |
| 428 | \file{*.py} |
| 429 | \item remove all files in the sub-trees starting at directories matching |
| 430 | \file{examples/sample?/build}---this may exclude files included by the |
| 431 | previous two steps, so it's important that the \code{prune} command in |
| 432 | the manifest template comes after the two \code{recursive-include} |
| 433 | commands |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 434 | \end{enumerate} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 435 | |
| 436 | |
| 437 | \subsection{Manifest-related options} |
| 438 | \label{sec:manifest-options} |
| 439 | |
| 440 | The normal course of operations for the \command{sdist} command is as |
| 441 | follows: |
| 442 | \begin{itemize} |
| 443 | \item if \file{MANIFEST.in} is more recent than \file{MANIFEST}, or |
| 444 | \file{MANIFEST} doesn't exist at all, recreate \file{MANIFEST} by |
| 445 | processing \file{MANIFEST.in} |
| 446 | \item use the list of files now in \file{MANIFEST} (either just |
| 447 | generated or read in) to create the source distribution archive(s) |
| 448 | \end{itemize} |
| 449 | There are a couple of options that modify this behaviour. |
| 450 | |
| 451 | First, you might want to force the manifest to be regenerated---for |
| 452 | example, if you have added or removed files or directories that match an |
| 453 | existing pattern in the manifest template, you should regenerate the |
| 454 | manifest: |
| 455 | \begin{verbatim} |
| 456 | python setup.py sdist --force-manifest |
| 457 | \end{verbatim} |
| 458 | \XXX{this is stupid, but is there a better way to do it without |
| 459 | reprocessing MANIFEST.in every single bloody time?} |
| 460 | |
| 461 | Or, you might just want to (re)generate the manifest, but not create a |
| 462 | source distribution: |
| 463 | \begin{verbatim} |
| 464 | python setup.py sdist --manifest-only |
| 465 | \end{verbatim} |
| 466 | (\option{--manifest-only} implies \option{--force-manifest}.) |
| 467 | |
| 468 | If you don't want to use the default file set, you can supply the |
| 469 | \option{--no-defaults} option. If you use \option{--no-defaults} and |
| 470 | don't supply a manifest template (or it's empty, or nothing matches the |
| 471 | patterns in it), then your source distribution will be empty. |
| 472 | |
| 473 | |
| 474 | \section{Creating Built Distributions} |
| 475 | \label{sec:built-dist} |
| 476 | |
| 477 | |
| 478 | |
| 479 | \section{Examples} |
| 480 | \label{sec:examples} |
| 481 | |
| 482 | |
| 483 | \subsection{Pure Python distribution (by module)} |
| 484 | \label{sec:pure-mod} |
| 485 | |
| 486 | |
| 487 | \subsection{Pure Python distribution (by package)} |
| 488 | \label{sec:pure-pkg} |
| 489 | |
| 490 | |
| 491 | \subsection{Single extension module} |
| 492 | \label{sec:single-ext} |
| 493 | |
| 494 | |
| 495 | \subsection{Multiple extension modules} |
| 496 | \label{sec:multiple-ext} |
| 497 | |
| 498 | |
| 499 | \subsection{Putting it all together} |
| 500 | |
| 501 | |
| 502 | \section{Reference} |
| 503 | \label{sec:ref} |
| 504 | |
| 505 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 506 | \subsection{Building modules: the \protect\command{build} command family} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 507 | \label{sec:build-cmds} |
| 508 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 509 | \subsubsection{\protect\command{build}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 510 | \label{sec:build-cmd} |
| 511 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 512 | \subsubsection{\protect\command{build\_py}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 513 | \label{sec:build-py-cmd} |
| 514 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 515 | \subsubsection{\protect\command{build\_ext}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 516 | \label{sec:build-ext-cmd} |
| 517 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 518 | \subsubsection{\protect\command{build\_clib}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 519 | \label{sec:build-clib-cmd} |
| 520 | |
| 521 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 522 | \subsection{Installing modules: the \protect\command{install} command family} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 523 | \label{sec:install-cmd} |
| 524 | |
| 525 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 526 | \subsection{Cleaning up: the \protect\command{clean} command} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 527 | \label{sec:clean-cmd} |
| 528 | |
| 529 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 530 | \subsection{Creating a source distribution: the \protect\command{sdist} command} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 531 | \label{sec:sdist-cmd} |
| 532 | |
| 533 | |
| 534 | \XXX{fragment moved down from above: needs context!} |
| 535 | The manifest template commands are: |
| 536 | \begin{tableii}{ll}{command}{Command}{Description} |
| 537 | \lineii{include \var{pat}}{include all files matching \var{pat}} |
| 538 | \lineii{exclude \var{pat}}{exclude all files matching \var{pat}} |
| 539 | \lineii{recursive-include \var{dir} \var{pat}} |
| 540 | {include all files under \var{dir} matching \var{pat}} |
| 541 | \lineii{recursive-exclude \var{dir} \var{pat}} |
| 542 | {exclude all files under \var{dir} matching \var{pat}} |
| 543 | \lineii{global-include \var{pat}} |
| 544 | {include all files anywhere in the source tree matching \var{pat}} |
| 545 | \lineii{global-exclude \var{pat}} |
| 546 | {exclude all files anywhere in the source tree matching \var{pat}} |
| 547 | \lineii{prune \var{dir}}{exclude all files under \var{dir}} |
| 548 | \lineii{graft \var{dir}}{include all files under \var{dir}} |
| 549 | \end{tableii} |
| 550 | The patterns here are Unix-style ``glob'' patterns: \code{*} matches any |
| 551 | sequence of regular filename characters, \code{?} matches any single |
| 552 | regular filename character, and \code{[\var{range}]} matches any of the |
| 553 | characters in \var{range} (e.g., \code{a-z}, \code{a-zA-Z}, |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 554 | \code{a-f0-9\_.}). The definition of ``regular filename character'' is |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 555 | platform-specific: on Unix it is anything except slash; on Windows |
| 556 | anything except backslash or colon; on Mac OS anything except colon. |
| 557 | \XXX{Windows and Mac OS support not there yet} |
| 558 | |
| 559 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 560 | \subsection{Creating a ``built'' distribution: the \protect\command{bdist} command |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 561 | family} |
| 562 | \label{sec:bdist-cmds} |
| 563 | |
| 564 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 565 | \subsubsection{\protect\command{blib}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 566 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 567 | \subsubsection{\protect\command{blib\_dumb}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 568 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 569 | \subsubsection{\protect\command{blib\_rpm}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 570 | |
Greg Ward | facb8db | 2000-04-09 04:32:40 +0000 | [diff] [blame^] | 571 | \subsubsection{\protect\command{blib\_wise}} |
Greg Ward | 16aafcd | 2000-04-09 04:06:44 +0000 | [diff] [blame] | 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
Greg Ward | abc5216 | 2000-02-26 00:52:48 +0000 | [diff] [blame] | 580 | \end{document} |