blob: 1381afc652d6ca6ebf38643b71e6a9a3a44aff9a [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001.. _api-reference:
2
3*************
4API Reference
5*************
6
7
8:mod:`distutils.core` --- Core Distutils functionality
9======================================================
10
11.. module:: distutils.core
12 :synopsis: The core Distutils functionality
13
14
15The :mod:`distutils.core` module is the only module that needs to be installed
16to use the Distutils. It provides the :func:`setup` (which is called from the
17setup script). Indirectly provides the :class:`distutils.dist.Distribution` and
18:class:`distutils.cmd.Command` class.
19
20
21.. function:: setup(arguments)
22
23 The basic do-everything function that does most everything you could ever ask
Éric Araujo000893f2011-05-29 00:14:45 +020024 for from a Distutils method.
Georg Brandl116aa622007-08-15 14:28:22 +000025
26 The setup function takes a large number of arguments. These are laid out in the
27 following table.
28
29 +--------------------+--------------------------------+-------------------------------------------------------------+
30 | argument name | value | type |
31 +====================+================================+=============================================================+
32 | *name* | The name of the package | a string |
33 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020034 | *version* | The version number of the | a string |
35 | | package; see | |
36 | | :mod:`distutils.version` | |
Georg Brandl116aa622007-08-15 14:28:22 +000037 +--------------------+--------------------------------+-------------------------------------------------------------+
38 | *description* | A single line describing the | a string |
39 | | package | |
40 +--------------------+--------------------------------+-------------------------------------------------------------+
41 | *long_description* | Longer description of the | a string |
42 | | package | |
43 +--------------------+--------------------------------+-------------------------------------------------------------+
44 | *author* | The name of the package author | a string |
45 +--------------------+--------------------------------+-------------------------------------------------------------+
46 | *author_email* | The email address of the | a string |
47 | | package author | |
48 +--------------------+--------------------------------+-------------------------------------------------------------+
49 | *maintainer* | The name of the current | a string |
50 | | maintainer, if different from | |
Petri Lehtinen905b6482013-02-23 21:05:27 +010051 | | the author. Note that if | |
52 | | the maintainer is provided, | |
53 | | distutils will use it as the | |
54 | | author in :file:`PKG-INFO` | |
Georg Brandl116aa622007-08-15 14:28:22 +000055 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020056 | *maintainer_email* | The email address of the | a string |
Georg Brandl116aa622007-08-15 14:28:22 +000057 | | current maintainer, if | |
58 | | different from the author | |
59 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020060 | *url* | A URL for the package | a string |
Georg Brandl116aa622007-08-15 14:28:22 +000061 | | (homepage) | |
62 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020063 | *download_url* | A URL to download the package | a string |
Georg Brandl116aa622007-08-15 14:28:22 +000064 +--------------------+--------------------------------+-------------------------------------------------------------+
65 | *packages* | A list of Python packages that | a list of strings |
66 | | distutils will manipulate | |
67 +--------------------+--------------------------------+-------------------------------------------------------------+
68 | *py_modules* | A list of Python modules that | a list of strings |
69 | | distutils will manipulate | |
70 +--------------------+--------------------------------+-------------------------------------------------------------+
71 | *scripts* | A list of standalone script | a list of strings |
72 | | files to be built and | |
73 | | installed | |
74 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020075 | *ext_modules* | A list of Python extensions to | a list of instances of |
Georg Brandl116aa622007-08-15 14:28:22 +000076 | | be built | :class:`distutils.core.Extension` |
77 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020078 | *classifiers* | A list of categories for the | a list of strings; valid classifiers are listed on `PyPI |
79 | | package | <http://pypi.python.org/pypi?:action=list_classifiers>`_. |
Georg Brandl116aa622007-08-15 14:28:22 +000080 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020081 | *distclass* | the :class:`Distribution` | a subclass of |
Georg Brandl116aa622007-08-15 14:28:22 +000082 | | class to use | :class:`distutils.core.Distribution` |
83 +--------------------+--------------------------------+-------------------------------------------------------------+
84 | *script_name* | The name of the setup.py | a string |
85 | | script - defaults to | |
86 | | ``sys.argv[0]`` | |
87 +--------------------+--------------------------------+-------------------------------------------------------------+
88 | *script_args* | Arguments to supply to the | a list of strings |
89 | | setup script | |
90 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020091 | *options* | default options for the setup | a dictionary |
Georg Brandl116aa622007-08-15 14:28:22 +000092 | | script | |
93 +--------------------+--------------------------------+-------------------------------------------------------------+
Benjamin Peterson75edad02009-01-01 15:05:06 +000094 | *license* | The license for the package | a string |
Georg Brandl116aa622007-08-15 14:28:22 +000095 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020096 | *keywords* | Descriptive meta-data, see | a list of strings or a comma-separated string |
Georg Brandl116aa622007-08-15 14:28:22 +000097 | | :pep:`314` | |
98 +--------------------+--------------------------------+-------------------------------------------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +020099 | *platforms* | | a list of strings or a comma-separated string |
Georg Brandl116aa622007-08-15 14:28:22 +0000100 +--------------------+--------------------------------+-------------------------------------------------------------+
101 | *cmdclass* | A mapping of command names to | a dictionary |
102 | | :class:`Command` subclasses | |
103 +--------------------+--------------------------------+-------------------------------------------------------------+
Benjamin Peterson75edad02009-01-01 15:05:06 +0000104 | *data_files* | A list of data files to | a list |
105 | | install | |
106 +--------------------+--------------------------------+-------------------------------------------------------------+
107 | *package_dir* | A mapping of package to | a dictionary |
108 | | directory names | |
109 +--------------------+--------------------------------+-------------------------------------------------------------+
Georg Brandl48310cd2009-01-03 21:18:54 +0000110
Georg Brandl116aa622007-08-15 14:28:22 +0000111
112
113.. function:: run_setup(script_name[, script_args=None, stop_after='run'])
114
115 Run a setup script in a somewhat controlled environment, and return the
116 :class:`distutils.dist.Distribution` instance that drives things. This is
117 useful if you need to find out the distribution meta-data (passed as keyword
118 args from *script* to :func:`setup`), or the contents of the config files or
119 command-line.
120
121 *script_name* is a file that will be read and run with :func:`exec`. ``sys.argv[0]``
122 will be replaced with *script* for the duration of the call. *script_args* is a
123 list of strings; if supplied, ``sys.argv[1:]`` will be replaced by *script_args*
124 for the duration of the call.
125
126 *stop_after* tells :func:`setup` when to stop processing; possible values:
127
128 +---------------+---------------------------------------------+
129 | value | description |
130 +===============+=============================================+
131 | *init* | Stop after the :class:`Distribution` |
132 | | instance has been created and populated |
133 | | with the keyword arguments to :func:`setup` |
134 +---------------+---------------------------------------------+
135 | *config* | Stop after config files have been parsed |
136 | | (and their data stored in the |
137 | | :class:`Distribution` instance) |
138 +---------------+---------------------------------------------+
139 | *commandline* | Stop after the command-line |
140 | | (``sys.argv[1:]`` or *script_args*) have |
141 | | been parsed (and the data stored in the |
142 | | :class:`Distribution` instance.) |
143 +---------------+---------------------------------------------+
144 | *run* | Stop after all commands have been run (the |
145 | | same as if :func:`setup` had been called |
146 | | in the usual way). This is the default |
147 | | value. |
148 +---------------+---------------------------------------------+
149
150In addition, the :mod:`distutils.core` module exposed a number of classes that
151live elsewhere.
152
Georg Brandl4009c9e2010-10-06 08:26:09 +0000153* :class:`~distutils.extension.Extension` from :mod:`distutils.extension`
Georg Brandl116aa622007-08-15 14:28:22 +0000154
Georg Brandl4009c9e2010-10-06 08:26:09 +0000155* :class:`~distutils.cmd.Command` from :mod:`distutils.cmd`
Georg Brandl116aa622007-08-15 14:28:22 +0000156
Georg Brandl4009c9e2010-10-06 08:26:09 +0000157* :class:`~distutils.dist.Distribution` from :mod:`distutils.dist`
Georg Brandl116aa622007-08-15 14:28:22 +0000158
159A short description of each of these follows, but see the relevant module for
160the full reference.
161
162
163.. class:: Extension
164
165 The Extension class describes a single C or C++extension module in a setup
Éric Araujob008d3d2011-08-26 01:23:20 +0200166 script. It accepts the following keyword arguments in its constructor:
Georg Brandl116aa622007-08-15 14:28:22 +0000167
168 +------------------------+--------------------------------+---------------------------+
169 | argument name | value | type |
170 +========================+================================+===========================+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200171 | *name* | the full name of the | a string |
Georg Brandl116aa622007-08-15 14:28:22 +0000172 | | extension, including any | |
173 | | packages --- ie. *not* a | |
174 | | filename or pathname, but | |
175 | | Python dotted name | |
176 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200177 | *sources* | list of source filenames, | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000178 | | relative to the distribution | |
179 | | root (where the setup script | |
180 | | lives), in Unix form (slash- | |
181 | | separated) for portability. | |
182 | | Source files may be C, C++, | |
183 | | SWIG (.i), platform-specific | |
184 | | resource files, or whatever | |
185 | | else is recognized by the | |
186 | | :command:`build_ext` command | |
187 | | as source for a Python | |
188 | | extension. | |
189 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200190 | *include_dirs* | list of directories to search | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000191 | | for C/C++ header files (in | |
192 | | Unix form for portability) | |
193 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200194 | *define_macros* | list of macros to define; each | a list of tuples |
195 | | macro is defined using a | |
Georg Brandl1f01deb2009-01-03 22:47:39 +0000196 | | 2-tuple ``(name, value)``, | |
197 | | where *value* is | |
Georg Brandl116aa622007-08-15 14:28:22 +0000198 | | either the string to define it | |
199 | | to or ``None`` to define it | |
200 | | without a particular value | |
201 | | (equivalent of ``#define FOO`` | |
202 | | in source or :option:`-DFOO` | |
203 | | on Unix C compiler command | |
204 | | line) | |
205 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200206 | *undef_macros* | list of macros to undefine | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000207 | | explicitly | |
208 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200209 | *library_dirs* | list of directories to search | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000210 | | for C/C++ libraries at link | |
211 | | time | |
212 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200213 | *libraries* | list of library names (not | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000214 | | filenames or paths) to link | |
215 | | against | |
216 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200217 | *runtime_library_dirs* | list of directories to search | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000218 | | for C/C++ libraries at run | |
219 | | time (for shared extensions, | |
220 | | this is when the extension is | |
221 | | loaded) | |
222 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200223 | *extra_objects* | list of extra files to link | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000224 | | with (eg. object files not | |
225 | | implied by 'sources', static | |
226 | | library that must be | |
227 | | explicitly specified, binary | |
228 | | resource files, etc.) | |
229 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200230 | *extra_compile_args* | any extra platform- and | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000231 | | compiler-specific information | |
232 | | to use when compiling the | |
233 | | source files in 'sources'. For | |
234 | | platforms and compilers where | |
235 | | a command line makes sense, | |
236 | | this is typically a list of | |
237 | | command-line arguments, but | |
238 | | for other platforms it could | |
239 | | be anything. | |
240 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200241 | *extra_link_args* | any extra platform- and | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000242 | | compiler-specific information | |
243 | | to use when linking object | |
244 | | files together to create the | |
245 | | extension (or to create a new | |
246 | | static Python interpreter). | |
247 | | Similar interpretation as for | |
248 | | 'extra_compile_args'. | |
249 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200250 | *export_symbols* | list of symbols to be exported | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000251 | | from a shared extension. Not | |
252 | | used on all platforms, and not | |
253 | | generally necessary for Python | |
254 | | extensions, which typically | |
255 | | export exactly one symbol: | |
256 | | ``init`` + extension_name. | |
257 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200258 | *depends* | list of files that the | a list of strings |
Georg Brandl116aa622007-08-15 14:28:22 +0000259 | | extension depends on | |
260 +------------------------+--------------------------------+---------------------------+
Éric Araujo3f5e9582011-08-26 00:44:37 +0200261 | *language* | extension language (i.e. | a string |
Georg Brandl116aa622007-08-15 14:28:22 +0000262 | | ``'c'``, ``'c++'``, | |
263 | | ``'objc'``). Will be detected | |
264 | | from the source extensions if | |
265 | | not provided. | |
266 +------------------------+--------------------------------+---------------------------+
Éric Araujo77443822011-08-26 00:45:18 +0200267 | *optional* | specifies that a build failure | a boolean |
268 | | in the extension should not | |
269 | | abort the build process, but | |
270 | | simply skip the extension. | |
271 +------------------------+--------------------------------+---------------------------+
Georg Brandl116aa622007-08-15 14:28:22 +0000272
273
274.. class:: Distribution
275
276 A :class:`Distribution` describes how to build, install and package up a Python
277 software package.
278
279 See the :func:`setup` function for a list of keyword arguments accepted by the
280 Distribution constructor. :func:`setup` creates a Distribution instance.
281
282
283.. class:: Command
284
285 A :class:`Command` class (or rather, an instance of one of its subclasses)
286 implement a single distutils command.
287
288
289:mod:`distutils.ccompiler` --- CCompiler base class
290===================================================
291
292.. module:: distutils.ccompiler
293 :synopsis: Abstract CCompiler class
294
295
296This module provides the abstract base class for the :class:`CCompiler`
297classes. A :class:`CCompiler` instance can be used for all the compile and
298link steps needed to build a single project. Methods are provided to set
299options for the compiler --- macro definitions, include directories, link path,
300libraries and the like.
301
302This module provides the following functions.
303
304
305.. function:: gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries)
306
307 Generate linker options for searching library directories and linking with
308 specific libraries. *libraries* and *library_dirs* are, respectively, lists of
309 library names (not filenames!) and search directories. Returns a list of
310 command-line options suitable for use with some compiler (depending on the two
311 format strings passed in).
312
313
314.. function:: gen_preprocess_options(macros, include_dirs)
315
316 Generate C pre-processor options (:option:`-D`, :option:`-U`, :option:`-I`) as
317 used by at least two types of compilers: the typical Unix compiler and Visual
318 C++. *macros* is the usual thing, a list of 1- or 2-tuples, where ``(name,)``
319 means undefine (:option:`-U`) macro *name*, and ``(name, value)`` means define
320 (:option:`-D`) macro *name* to *value*. *include_dirs* is just a list of
321 directory names to be added to the header file search path (:option:`-I`).
322 Returns a list of command-line options suitable for either Unix compilers or
323 Visual C++.
324
325
326.. function:: get_default_compiler(osname, platform)
327
328 Determine the default compiler to use for the given platform.
329
330 *osname* should be one of the standard Python OS names (i.e. the ones returned
331 by ``os.name``) and *platform* the common value returned by ``sys.platform`` for
332 the platform in question.
333
334 The default values are ``os.name`` and ``sys.platform`` in case the parameters
335 are not given.
336
337
338.. function:: new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0)
339
340 Factory function to generate an instance of some CCompiler subclass for the
341 supplied platform/compiler combination. *plat* defaults to ``os.name`` (eg.
342 ``'posix'``, ``'nt'``), and *compiler* defaults to the default compiler for
343 that platform. Currently only ``'posix'`` and ``'nt'`` are supported, and the
344 default compilers are "traditional Unix interface" (:class:`UnixCCompiler`
Georg Brandlc575c902008-09-13 17:46:05 +0000345 class) and Visual C++ (:class:`MSVCCompiler` class). Note that it's perfectly
Georg Brandl116aa622007-08-15 14:28:22 +0000346 possible to ask for a Unix compiler object under Windows, and a Microsoft
347 compiler object under Unix---if you supply a value for *compiler*, *plat* is
348 ignored.
349
350 .. % Is the posix/nt only thing still true? Mac OS X seems to work, and
351 .. % returns a UnixCCompiler instance. How to document this... hmm.
352
353
354.. function:: show_compilers()
355
356 Print list of available compilers (used by the :option:`--help-compiler` options
357 to :command:`build`, :command:`build_ext`, :command:`build_clib`).
358
359
360.. class:: CCompiler([verbose=0, dry_run=0, force=0])
361
362 The abstract base class :class:`CCompiler` defines the interface that must be
363 implemented by real compiler classes. The class also has some utility methods
364 used by several compiler classes.
365
366 The basic idea behind a compiler abstraction class is that each instance can be
367 used for all the compile/link steps in building a single project. Thus,
368 attributes common to all of those compile and link steps --- include
369 directories, macros to define, libraries to link against, etc. --- are
370 attributes of the compiler instance. To allow for variability in how individual
371 files are treated, most of those attributes may be varied on a per-compilation
372 or per-link basis.
373
374 The constructor for each subclass creates an instance of the Compiler object.
375 Flags are *verbose* (show verbose output), *dry_run* (don't actually execute the
376 steps) and *force* (rebuild everything, regardless of dependencies). All of
377 these flags default to ``0`` (off). Note that you probably don't want to
378 instantiate :class:`CCompiler` or one of its subclasses directly - use the
379 :func:`distutils.CCompiler.new_compiler` factory function instead.
380
381 The following methods allow you to manually alter compiler options for the
382 instance of the Compiler class.
383
384
385 .. method:: CCompiler.add_include_dir(dir)
386
387 Add *dir* to the list of directories that will be searched for header files.
388 The compiler is instructed to search directories in the order in which they are
389 supplied by successive calls to :meth:`add_include_dir`.
390
391
392 .. method:: CCompiler.set_include_dirs(dirs)
393
394 Set the list of directories that will be searched to *dirs* (a list of strings).
395 Overrides any preceding calls to :meth:`add_include_dir`; subsequent calls to
396 :meth:`add_include_dir` add to the list passed to :meth:`set_include_dirs`.
397 This does not affect any list of standard include directories that the compiler
398 may search by default.
399
400
401 .. method:: CCompiler.add_library(libname)
402
403 Add *libname* to the list of libraries that will be included in all links driven
404 by this compiler object. Note that *libname* should \*not\* be the name of a
405 file containing a library, but the name of the library itself: the actual
406 filename will be inferred by the linker, the compiler, or the compiler class
407 (depending on the platform).
408
409 The linker will be instructed to link against libraries in the order they were
410 supplied to :meth:`add_library` and/or :meth:`set_libraries`. It is perfectly
411 valid to duplicate library names; the linker will be instructed to link against
412 libraries as many times as they are mentioned.
413
414
415 .. method:: CCompiler.set_libraries(libnames)
416
417 Set the list of libraries to be included in all links driven by this compiler
418 object to *libnames* (a list of strings). This does not affect any standard
419 system libraries that the linker may include by default.
420
421
422 .. method:: CCompiler.add_library_dir(dir)
423
424 Add *dir* to the list of directories that will be searched for libraries
425 specified to :meth:`add_library` and :meth:`set_libraries`. The linker will be
426 instructed to search for libraries in the order they are supplied to
427 :meth:`add_library_dir` and/or :meth:`set_library_dirs`.
428
429
430 .. method:: CCompiler.set_library_dirs(dirs)
431
432 Set the list of library search directories to *dirs* (a list of strings). This
433 does not affect any standard library search path that the linker may search by
434 default.
435
436
437 .. method:: CCompiler.add_runtime_library_dir(dir)
438
439 Add *dir* to the list of directories that will be searched for shared libraries
440 at runtime.
441
442
443 .. method:: CCompiler.set_runtime_library_dirs(dirs)
444
445 Set the list of directories to search for shared libraries at runtime to *dirs*
446 (a list of strings). This does not affect any standard search path that the
447 runtime linker may search by default.
448
449
450 .. method:: CCompiler.define_macro(name[, value=None])
451
452 Define a preprocessor macro for all compilations driven by this compiler object.
453 The optional parameter *value* should be a string; if it is not supplied, then
454 the macro will be defined without an explicit value and the exact outcome
Éric Araujo9cff4272012-01-15 02:25:31 +0100455 depends on the compiler used.
456
457 .. XXX true? does ANSI say anything about this?
Georg Brandl116aa622007-08-15 14:28:22 +0000458
459
460 .. method:: CCompiler.undefine_macro(name)
461
462 Undefine a preprocessor macro for all compilations driven by this compiler
463 object. If the same macro is defined by :meth:`define_macro` and
464 undefined by :meth:`undefine_macro` the last call takes precedence
465 (including multiple redefinitions or undefinitions). If the macro is
466 redefined/undefined on a per-compilation basis (ie. in the call to
467 :meth:`compile`), then that takes precedence.
468
469
470 .. method:: CCompiler.add_link_object(object)
471
472 Add *object* to the list of object files (or analogues, such as explicitly named
473 library files or the output of "resource compilers") to be included in every
474 link driven by this compiler object.
475
476
477 .. method:: CCompiler.set_link_objects(objects)
478
479 Set the list of object files (or analogues) to be included in every link to
480 *objects*. This does not affect any standard object files that the linker may
481 include by default (such as system libraries).
482
483 The following methods implement methods for autodetection of compiler options,
484 providing some functionality similar to GNU :program:`autoconf`.
485
486
487 .. method:: CCompiler.detect_language(sources)
488
489 Detect the language of a given file, or list of files. Uses the instance
490 attributes :attr:`language_map` (a dictionary), and :attr:`language_order` (a
491 list) to do the job.
492
493
494 .. method:: CCompiler.find_library_file(dirs, lib[, debug=0])
495
496 Search the specified list of directories for a static or shared library file
497 *lib* and return the full path to that file. If *debug* is true, look for a
498 debugging version (if that makes sense on the current platform). Return
499 ``None`` if *lib* wasn't found in any of the specified directories.
500
501
502 .. method:: CCompiler.has_function(funcname [, includes=None, include_dirs=None, libraries=None, library_dirs=None])
503
504 Return a boolean indicating whether *funcname* is supported on the current
505 platform. The optional arguments can be used to augment the compilation
506 environment by providing additional include files and paths and libraries and
507 paths.
508
509
510 .. method:: CCompiler.library_dir_option(dir)
511
512 Return the compiler option to add *dir* to the list of directories searched for
513 libraries.
514
515
516 .. method:: CCompiler.library_option(lib)
517
518 Return the compiler option to add *dir* to the list of libraries linked into the
519 shared library or executable.
520
521
522 .. method:: CCompiler.runtime_library_dir_option(dir)
523
524 Return the compiler option to add *dir* to the list of directories searched for
525 runtime libraries.
526
527
528 .. method:: CCompiler.set_executables(**args)
529
530 Define the executables (and options for them) that will be run to perform the
531 various stages of compilation. The exact set of executables that may be
532 specified here depends on the compiler class (via the 'executables' class
533 attribute), but most will have:
534
535 +--------------+------------------------------------------+
536 | attribute | description |
537 +==============+==========================================+
538 | *compiler* | the C/C++ compiler |
539 +--------------+------------------------------------------+
540 | *linker_so* | linker used to create shared objects and |
541 | | libraries |
542 +--------------+------------------------------------------+
543 | *linker_exe* | linker used to create binary executables |
544 +--------------+------------------------------------------+
545 | *archiver* | static library creator |
546 +--------------+------------------------------------------+
547
548 On platforms with a command-line (Unix, DOS/Windows), each of these is a string
549 that will be split into executable name and (optional) list of arguments.
550 (Splitting the string is done similarly to how Unix shells operate: words are
551 delimited by spaces, but quotes and backslashes can override this. See
552 :func:`distutils.util.split_quoted`.)
553
554 The following methods invoke stages in the build process.
555
556
557 .. method:: CCompiler.compile(sources[, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, depends=None])
558
559 Compile one or more source files. Generates object files (e.g. transforms a
560 :file:`.c` file to a :file:`.o` file.)
561
562 *sources* must be a list of filenames, most likely C/C++ files, but in reality
563 anything that can be handled by a particular compiler and compiler class (eg.
564 :class:`MSVCCompiler` can handle resource files in *sources*). Return a list of
565 object filenames, one per source filename in *sources*. Depending on the
566 implementation, not all source files will necessarily be compiled, but all
567 corresponding object filenames will be returned.
568
569 If *output_dir* is given, object files will be put under it, while retaining
570 their original path component. That is, :file:`foo/bar.c` normally compiles to
571 :file:`foo/bar.o` (for a Unix implementation); if *output_dir* is *build*, then
572 it would compile to :file:`build/foo/bar.o`.
573
574 *macros*, if given, must be a list of macro definitions. A macro definition is
575 either a ``(name, value)`` 2-tuple or a ``(name,)`` 1-tuple. The former defines
576 a macro; if the value is ``None``, the macro is defined without an explicit
577 value. The 1-tuple case undefines a macro. Later
578 definitions/redefinitions/undefinitions take precedence.
579
580 *include_dirs*, if given, must be a list of strings, the directories to add to
581 the default include file search path for this compilation only.
582
583 *debug* is a boolean; if true, the compiler will be instructed to output debug
584 symbols in (or alongside) the object file(s).
585
586 *extra_preargs* and *extra_postargs* are implementation-dependent. On platforms
587 that have the notion of a command-line (e.g. Unix, DOS/Windows), they are most
588 likely lists of strings: extra command-line arguments to prepend/append to the
589 compiler command line. On other platforms, consult the implementation class
590 documentation. In any event, they are intended as an escape hatch for those
591 occasions when the abstract compiler framework doesn't cut the mustard.
592
593 *depends*, if given, is a list of filenames that all targets depend on. If a
594 source file is older than any file in depends, then the source file will be
595 recompiled. This supports dependency tracking, but only at a coarse
596 granularity.
597
598 Raises :exc:`CompileError` on failure.
599
600
601 .. method:: CCompiler.create_static_lib(objects, output_libname[, output_dir=None, debug=0, target_lang=None])
602
603 Link a bunch of stuff together to create a static library file. The "bunch of
604 stuff" consists of the list of object files supplied as *objects*, the extra
605 object files supplied to :meth:`add_link_object` and/or
606 :meth:`set_link_objects`, the libraries supplied to :meth:`add_library` and/or
607 :meth:`set_libraries`, and the libraries supplied as *libraries* (if any).
608
609 *output_libname* should be a library name, not a filename; the filename will be
610 inferred from the library name. *output_dir* is the directory where the library
Éric Araujo9cff4272012-01-15 02:25:31 +0100611 file will be put.
612
613 .. XXX defaults to what?
Georg Brandl116aa622007-08-15 14:28:22 +0000614
615 *debug* is a boolean; if true, debugging information will be included in the
616 library (note that on most platforms, it is the compile step where this matters:
617 the *debug* flag is included here just for consistency).
618
619 *target_lang* is the target language for which the given objects are being
620 compiled. This allows specific linkage time treatment of certain languages.
621
622 Raises :exc:`LibError` on failure.
623
624
625 .. method:: CCompiler.link(target_desc, objects, output_filename[, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None])
626
627 Link a bunch of stuff together to create an executable or shared library file.
628
629 The "bunch of stuff" consists of the list of object files supplied as *objects*.
630 *output_filename* should be a filename. If *output_dir* is supplied,
631 *output_filename* is relative to it (i.e. *output_filename* can provide
632 directory components if needed).
633
634 *libraries* is a list of libraries to link against. These are library names,
635 not filenames, since they're translated into filenames in a platform-specific
636 way (eg. *foo* becomes :file:`libfoo.a` on Unix and :file:`foo.lib` on
637 DOS/Windows). However, they can include a directory component, which means the
638 linker will look in that specific directory rather than searching all the normal
639 locations.
640
641 *library_dirs*, if supplied, should be a list of directories to search for
642 libraries that were specified as bare library names (ie. no directory
643 component). These are on top of the system default and those supplied to
644 :meth:`add_library_dir` and/or :meth:`set_library_dirs`. *runtime_library_dirs*
645 is a list of directories that will be embedded into the shared library and used
646 to search for other shared libraries that \*it\* depends on at run-time. (This
647 may only be relevant on Unix.)
648
649 *export_symbols* is a list of symbols that the shared library will export.
650 (This appears to be relevant only on Windows.)
651
652 *debug* is as for :meth:`compile` and :meth:`create_static_lib`, with the
653 slight distinction that it actually matters on most platforms (as opposed to
654 :meth:`create_static_lib`, which includes a *debug* flag mostly for form's
655 sake).
656
657 *extra_preargs* and *extra_postargs* are as for :meth:`compile` (except of
658 course that they supply command-line arguments for the particular linker being
659 used).
660
661 *target_lang* is the target language for which the given objects are being
662 compiled. This allows specific linkage time treatment of certain languages.
663
664 Raises :exc:`LinkError` on failure.
665
666
667 .. method:: CCompiler.link_executable(objects, output_progname[, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, debug=0, extra_preargs=None, extra_postargs=None, target_lang=None])
668
669 Link an executable. *output_progname* is the name of the file executable, while
670 *objects* are a list of object filenames to link in. Other arguments are as for
671 the :meth:`link` method.
672
673
674 .. method:: CCompiler.link_shared_lib(objects, output_libname[, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None])
675
676 Link a shared library. *output_libname* is the name of the output library,
677 while *objects* is a list of object filenames to link in. Other arguments are
678 as for the :meth:`link` method.
679
680
681 .. method:: CCompiler.link_shared_object(objects, output_filename[, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None])
682
683 Link a shared object. *output_filename* is the name of the shared object that
684 will be created, while *objects* is a list of object filenames to link in.
685 Other arguments are as for the :meth:`link` method.
686
687
688 .. method:: CCompiler.preprocess(source[, output_file=None, macros=None, include_dirs=None, extra_preargs=None, extra_postargs=None])
689
690 Preprocess a single C/C++ source file, named in *source*. Output will be written
691 to file named *output_file*, or *stdout* if *output_file* not supplied.
692 *macros* is a list of macro definitions as for :meth:`compile`, which will
693 augment the macros set with :meth:`define_macro` and :meth:`undefine_macro`.
694 *include_dirs* is a list of directory names that will be added to the default
695 list, in the same way as :meth:`add_include_dir`.
696
697 Raises :exc:`PreprocessError` on failure.
698
699 The following utility methods are defined by the :class:`CCompiler` class, for
700 use by the various concrete subclasses.
701
702
703 .. method:: CCompiler.executable_filename(basename[, strip_dir=0, output_dir=''])
704
705 Returns the filename of the executable for the given *basename*. Typically for
706 non-Windows platforms this is the same as the basename, while Windows will get
707 a :file:`.exe` added.
708
709
710 .. method:: CCompiler.library_filename(libname[, lib_type='static', strip_dir=0, output_dir=''])
711
712 Returns the filename for the given library name on the current platform. On Unix
713 a library with *lib_type* of ``'static'`` will typically be of the form
714 :file:`liblibname.a`, while a *lib_type* of ``'dynamic'`` will be of the form
715 :file:`liblibname.so`.
716
717
718 .. method:: CCompiler.object_filenames(source_filenames[, strip_dir=0, output_dir=''])
719
720 Returns the name of the object files for the given source files.
721 *source_filenames* should be a list of filenames.
722
723
724 .. method:: CCompiler.shared_object_filename(basename[, strip_dir=0, output_dir=''])
725
726 Returns the name of a shared object file for the given file name *basename*.
727
728
729 .. method:: CCompiler.execute(func, args[, msg=None, level=1])
730
731 Invokes :func:`distutils.util.execute` This method invokes a Python function
732 *func* with the given arguments *args*, after logging and taking into account
Éric Araujo9cff4272012-01-15 02:25:31 +0100733 the *dry_run* flag.
Georg Brandl116aa622007-08-15 14:28:22 +0000734
735
736 .. method:: CCompiler.spawn(cmd)
737
738 Invokes :func:`distutils.util.spawn`. This invokes an external process to run
Éric Araujo9cff4272012-01-15 02:25:31 +0100739 the given command.
Georg Brandl116aa622007-08-15 14:28:22 +0000740
741
742 .. method:: CCompiler.mkpath(name[, mode=511])
743
744 Invokes :func:`distutils.dir_util.mkpath`. This creates a directory and any
Éric Araujo9cff4272012-01-15 02:25:31 +0100745 missing ancestor directories.
Georg Brandl116aa622007-08-15 14:28:22 +0000746
747
748 .. method:: CCompiler.move_file(src, dst)
749
Éric Araujo9cff4272012-01-15 02:25:31 +0100750 Invokes :meth:`distutils.file_util.move_file`. Renames *src* to *dst*.
Georg Brandl116aa622007-08-15 14:28:22 +0000751
752
753 .. method:: CCompiler.announce(msg[, level=1])
754
Éric Araujo9cff4272012-01-15 02:25:31 +0100755 Write a message using :func:`distutils.log.debug`.
Georg Brandl116aa622007-08-15 14:28:22 +0000756
757
758 .. method:: CCompiler.warn(msg)
759
760 Write a warning message *msg* to standard error.
761
762
763 .. method:: CCompiler.debug_print(msg)
764
765 If the *debug* flag is set on this :class:`CCompiler` instance, print *msg* to
766 standard output, otherwise do nothing.
767
768.. % \subsection{Compiler-specific modules}
Georg Brandl48310cd2009-01-03 21:18:54 +0000769.. %
Georg Brandl116aa622007-08-15 14:28:22 +0000770.. % The following modules implement concrete subclasses of the abstract
771.. % \class{CCompiler} class. They should not be instantiated directly, but should
772.. % be created using \function{distutils.ccompiler.new_compiler()} factory
773.. % function.
774
775
776:mod:`distutils.unixccompiler` --- Unix C Compiler
777==================================================
778
779.. module:: distutils.unixccompiler
780 :synopsis: UNIX C Compiler
781
782
783This module provides the :class:`UnixCCompiler` class, a subclass of
784:class:`CCompiler` that handles the typical Unix-style command-line C compiler:
785
786* macros defined with :option:`-Dname[=value]`
787
788* macros undefined with :option:`-Uname`
789
790* include search directories specified with :option:`-Idir`
791
792* libraries specified with :option:`-llib`
793
794* library search directories specified with :option:`-Ldir`
795
796* compile handled by :program:`cc` (or similar) executable with :option:`-c`
797 option: compiles :file:`.c` to :file:`.o`
798
799* link static library handled by :program:`ar` command (possibly with
800 :program:`ranlib`)
801
802* link shared library handled by :program:`cc` :option:`-shared`
803
804
805:mod:`distutils.msvccompiler` --- Microsoft Compiler
806====================================================
807
808.. module:: distutils.msvccompiler
809 :synopsis: Microsoft Compiler
810
811
812This module provides :class:`MSVCCompiler`, an implementation of the abstract
813:class:`CCompiler` class for Microsoft Visual Studio. Typically, extension
814modules need to be compiled with the same compiler that was used to compile
815Python. For Python 2.3 and earlier, the compiler was Visual Studio 6. For Python
8162.4 and 2.5, the compiler is Visual Studio .NET 2003. The AMD64 and Itanium
817binaries are created using the Platform SDK.
818
819:class:`MSVCCompiler` will normally choose the right compiler, linker etc. on
820its own. To override this choice, the environment variables *DISTUTILS_USE_SDK*
821and *MSSdk* must be both set. *MSSdk* indicates that the current environment has
822been setup by the SDK's ``SetEnv.Cmd`` script, or that the environment variables
823had been registered when the SDK was installed; *DISTUTILS_USE_SDK* indicates
824that the distutils user has made an explicit choice to override the compiler
825selection by :class:`MSVCCompiler`.
826
827
828:mod:`distutils.bcppcompiler` --- Borland Compiler
829==================================================
830
831.. module:: distutils.bcppcompiler
832
833
834This module provides :class:`BorlandCCompiler`, an subclass of the abstract
835:class:`CCompiler` class for the Borland C++ compiler.
836
837
838:mod:`distutils.cygwincompiler` --- Cygwin Compiler
839===================================================
840
841.. module:: distutils.cygwinccompiler
842
843
844This module provides the :class:`CygwinCCompiler` class, a subclass of
845:class:`UnixCCompiler` that handles the Cygwin port of the GNU C compiler to
846Windows. It also contains the Mingw32CCompiler class which handles the mingw32
847port of GCC (same as cygwin in no-cygwin mode).
848
849
850:mod:`distutils.emxccompiler` --- OS/2 EMX Compiler
851===================================================
852
853.. module:: distutils.emxccompiler
854 :synopsis: OS/2 EMX Compiler support
855
856
857This module provides the EMXCCompiler class, a subclass of
858:class:`UnixCCompiler` that handles the EMX port of the GNU C compiler to OS/2.
859
860
Georg Brandl116aa622007-08-15 14:28:22 +0000861:mod:`distutils.archive_util` --- Archiving utilities
862======================================================
863
864.. module:: distutils.archive_util
865 :synopsis: Utility functions for creating archive files (tarballs, zip files, ...)
866
867
868This module provides a few functions for creating archive files, such as
869tarballs or zipfiles.
870
871
872.. function:: make_archive(base_name, format[, root_dir=None, base_dir=None, verbose=0, dry_run=0])
873
874 Create an archive file (eg. ``zip`` or ``tar``). *base_name* is the name of
875 the file to create, minus any format-specific extension; *format* is the
876 archive format: one of ``zip``, ``tar``, ``ztar``, or ``gztar``. *root_dir* is
877 a directory that will be the root directory of the archive; ie. we typically
878 ``chdir`` into *root_dir* before creating the archive. *base_dir* is the
879 directory where we start archiving from; ie. *base_dir* will be the common
880 prefix of all files and directories in the archive. *root_dir* and *base_dir*
881 both default to the current directory. Returns the name of the archive file.
882
Georg Brandl116aa622007-08-15 14:28:22 +0000883
884.. function:: make_tarball(base_name, base_dir[, compress='gzip', verbose=0, dry_run=0])
885
886 'Create an (optional compressed) archive as a tar file from all files in and
887 under *base_dir*. *compress* must be ``'gzip'`` (the default), ``'compress'``,
888 ``'bzip2'``, or ``None``. Both :program:`tar` and the compression utility named
889 by *compress* must be on the default program search path, so this is probably
890 Unix-specific. The output tar file will be named :file:`base_dir.tar`,
891 possibly plus the appropriate compression extension (:file:`.gz`, :file:`.bz2`
892 or :file:`.Z`). Return the output filename.
893
Georg Brandl116aa622007-08-15 14:28:22 +0000894
895.. function:: make_zipfile(base_name, base_dir[, verbose=0, dry_run=0])
896
897 Create a zip file from all files in and under *base_dir*. The output zip file
Éric Araujo4433a5f2010-12-15 20:26:30 +0000898 will be named *base_name* + :file:`.zip`. Uses either the :mod:`zipfile` Python
Georg Brandl116aa622007-08-15 14:28:22 +0000899 module (if available) or the InfoZIP :file:`zip` utility (if installed and
900 found on the default search path). If neither tool is available, raises
901 :exc:`DistutilsExecError`. Returns the name of the output zip file.
902
903
904:mod:`distutils.dep_util` --- Dependency checking
905=================================================
906
907.. module:: distutils.dep_util
908 :synopsis: Utility functions for simple dependency checking
909
910
911This module provides functions for performing simple, timestamp-based
912dependency of files and groups of files; also, functions based entirely on such
913timestamp dependency analysis.
914
915
916.. function:: newer(source, target)
917
918 Return true if *source* exists and is more recently modified than *target*, or
919 if *source* exists and *target* doesn't. Return false if both exist and *target*
920 is the same age or newer than *source*. Raise :exc:`DistutilsFileError` if
921 *source* does not exist.
922
923
924.. function:: newer_pairwise(sources, targets)
925
926 Walk two filename lists in parallel, testing if each source is newer than its
927 corresponding target. Return a pair of lists (*sources*, *targets*) where
928 source is newer than target, according to the semantics of :func:`newer`
929
930 .. % % equivalent to a listcomp...
931
932
933.. function:: newer_group(sources, target[, missing='error'])
934
935 Return true if *target* is out-of-date with respect to any file listed in
936 *sources* In other words, if *target* exists and is newer than every file in
937 *sources*, return false; otherwise return true. *missing* controls what we do
938 when a source file is missing; the default (``'error'``) is to blow up with an
939 :exc:`OSError` from inside :func:`os.stat`; if it is ``'ignore'``, we silently
940 drop any missing source files; if it is ``'newer'``, any missing source files
941 make us assume that *target* is out-of-date (this is handy in "dry-run" mode:
942 it'll make you pretend to carry out commands that wouldn't work because inputs
943 are missing, but that doesn't matter because you're not actually going to run
944 the commands).
945
946
947:mod:`distutils.dir_util` --- Directory tree operations
948=======================================================
949
950.. module:: distutils.dir_util
951 :synopsis: Utility functions for operating on directories and directory trees
952
953
954This module provides functions for operating on directories and trees of
955directories.
956
957
Georg Brandlf4a41232008-05-26 17:55:52 +0000958.. function:: mkpath(name[, mode=0o777, verbose=0, dry_run=0])
Georg Brandl116aa622007-08-15 14:28:22 +0000959
960 Create a directory and any missing ancestor directories. If the directory
961 already exists (or if *name* is the empty string, which means the current
962 directory, which of course exists), then do nothing. Raise
963 :exc:`DistutilsFileError` if unable to create some directory along the way (eg.
964 some sub-path exists, but is a file rather than a directory). If *verbose* is
965 true, print a one-line summary of each mkdir to stdout. Return the list of
966 directories actually created.
967
968
Georg Brandlf4a41232008-05-26 17:55:52 +0000969.. function:: create_tree(base_dir, files[, mode=0o777, verbose=0, dry_run=0])
Georg Brandl116aa622007-08-15 14:28:22 +0000970
971 Create all the empty directories under *base_dir* needed to put *files* there.
972 *base_dir* is just the a name of a directory which doesn't necessarily exist
973 yet; *files* is a list of filenames to be interpreted relative to *base_dir*.
974 *base_dir* + the directory portion of every file in *files* will be created if
975 it doesn't already exist. *mode*, *verbose* and *dry_run* flags are as for
976 :func:`mkpath`.
977
978
979.. function:: copy_tree(src, dst[, preserve_mode=1, preserve_times=1, preserve_symlinks=0, update=0, verbose=0, dry_run=0])
980
981 Copy an entire directory tree *src* to a new location *dst*. Both *src* and
982 *dst* must be directory names. If *src* is not a directory, raise
983 :exc:`DistutilsFileError`. If *dst* does not exist, it is created with
984 :func:`mkpath`. The end result of the copy is that every file in *src* is
985 copied to *dst*, and directories under *src* are recursively copied to *dst*.
986 Return the list of files that were copied or might have been copied, using their
987 output name. The return value is unaffected by *update* or *dry_run*: it is
988 simply the list of all files under *src*, with the names changed to be under
989 *dst*.
990
991 *preserve_mode* and *preserve_times* are the same as for :func:`copy_file` in
992 :mod:`distutils.file_util`; note that they only apply to regular files, not to
993 directories. If *preserve_symlinks* is true, symlinks will be copied as
994 symlinks (on platforms that support them!); otherwise (the default), the
995 destination of the symlink will be copied. *update* and *verbose* are the same
996 as for :func:`copy_file`.
997
Éric Araujo3e4a3dc2012-12-08 14:21:51 -0500998 Files in *src* that begin with :file:`.nfs` are skipped (more information on
999 these files is available in answer D2 of the `NFS FAQ page
1000 <http://nfs.sourceforge.net/#section_d>`_.
1001
Éric Araujo3f7c0e42012-12-08 22:53:43 -05001002 .. versionchanged:: 3.3.1
Éric Araujo3e4a3dc2012-12-08 14:21:51 -05001003 NFS files are ignored.
Georg Brandl116aa622007-08-15 14:28:22 +00001004
1005.. function:: remove_tree(directory[, verbose=0, dry_run=0])
1006
1007 Recursively remove *directory* and all files and directories underneath it. Any
1008 errors are ignored (apart from being reported to ``sys.stdout`` if *verbose* is
1009 true).
1010
Georg Brandl116aa622007-08-15 14:28:22 +00001011
1012:mod:`distutils.file_util` --- Single file operations
1013=====================================================
1014
1015.. module:: distutils.file_util
1016 :synopsis: Utility functions for operating on single files
1017
1018
1019This module contains some utility functions for operating on individual files.
1020
1021
1022.. function:: copy_file(src, dst[, preserve_mode=1, preserve_times=1, update=0, link=None, verbose=0, dry_run=0])
1023
1024 Copy file *src* to *dst*. If *dst* is a directory, then *src* is copied there
1025 with the same name; otherwise, it must be a filename. (If the file exists, it
1026 will be ruthlessly clobbered.) If *preserve_mode* is true (the default), the
1027 file's mode (type and permission bits, or whatever is analogous on the
1028 current platform) is copied. If *preserve_times* is true (the default), the
1029 last-modified and last-access times are copied as well. If *update* is true,
1030 *src* will only be copied if *dst* does not exist, or if *dst* does exist but
1031 is older than *src*.
1032
1033 *link* allows you to make hard links (using :func:`os.link`) or symbolic links
1034 (using :func:`os.symlink`) instead of copying: set it to ``'hard'`` or
1035 ``'sym'``; if it is ``None`` (the default), files are copied. Don't set *link*
1036 on systems that don't support it: :func:`copy_file` doesn't check if hard or
1037 symbolic linking is available. It uses :func:`_copy_file_contents` to copy file
1038 contents.
1039
1040 Return a tuple ``(dest_name, copied)``: *dest_name* is the actual name of the
1041 output file, and *copied* is true if the file was copied (or would have been
1042 copied, if *dry_run* true).
1043
1044 .. % XXX if the destination file already exists, we clobber it if
1045 .. % copying, but blow up if linking. Hmmm. And I don't know what
1046 .. % macostools.copyfile() does. Should definitely be consistent, and
1047 .. % should probably blow up if destination exists and we would be
1048 .. % changing it (ie. it's not already a hard/soft link to src OR
1049 .. % (not update) and (src newer than dst)).
1050
1051
1052.. function:: move_file(src, dst[, verbose, dry_run])
1053
1054 Move file *src* to *dst*. If *dst* is a directory, the file will be moved into
1055 it with the same name; otherwise, *src* is just renamed to *dst*. Returns the
1056 new full name of the file.
1057
1058 .. warning::
1059
Benjamin Petersond23f8222009-04-05 19:13:16 +00001060 Handles cross-device moves on Unix using :func:`copy_file`. What about
1061 other systems?
Georg Brandl116aa622007-08-15 14:28:22 +00001062
1063
1064.. function:: write_file(filename, contents)
1065
1066 Create a file called *filename* and write *contents* (a sequence of strings
1067 without line terminators) to it.
1068
1069
1070:mod:`distutils.util` --- Miscellaneous other utility functions
1071===============================================================
1072
1073.. module:: distutils.util
1074 :synopsis: Miscellaneous other utility functions
1075
1076
1077This module contains other assorted bits and pieces that don't fit into any
1078other utility module.
1079
1080
1081.. function:: get_platform()
1082
1083 Return a string that identifies the current platform. This is used mainly to
1084 distinguish platform-specific build directories and platform-specific built
1085 distributions. Typically includes the OS name and version and the architecture
1086 (as supplied by 'os.uname()'), although the exact information included depends
1087 on the OS; eg. for IRIX the architecture isn't particularly important (IRIX only
1088 runs on SGI hardware), but for Linux the kernel version isn't particularly
1089 important.
1090
1091 Examples of returned values:
1092
1093 * ``linux-i586``
1094 * ``linux-alpha``
1095 * ``solaris-2.6-sun4u``
1096 * ``irix-5.3``
1097 * ``irix64-6.2``
1098
1099 For non-POSIX platforms, currently just returns ``sys.platform``.
1100
Benjamin Petersond23f8222009-04-05 19:13:16 +00001101 For Mac OS X systems the OS version reflects the minimal version on which
Benjamin Petersonc39d7622008-12-30 17:56:45 +00001102 binaries will run (that is, the value of ``MACOSX_DEPLOYMENT_TARGET``
Georg Brandl48310cd2009-01-03 21:18:54 +00001103 during the build of Python), not the OS version of the current system.
Benjamin Petersonc39d7622008-12-30 17:56:45 +00001104
Benjamin Petersond23f8222009-04-05 19:13:16 +00001105 For universal binary builds on Mac OS X the architecture value reflects
Benjamin Petersonc39d7622008-12-30 17:56:45 +00001106 the univeral binary status instead of the architecture of the current
Georg Brandl48310cd2009-01-03 21:18:54 +00001107 processor. For 32-bit universal binaries the architecture is ``fat``,
1108 for 64-bit universal binaries the architecture is ``fat64``, and
Ronald Oussorenbea37ae2009-09-15 19:16:02 +00001109 for 4-way universal binaries the architecture is ``universal``. Starting
1110 from Python 2.7 and Python 3.2 the architecture ``fat3`` is used for
1111 a 3-way universal build (ppc, i386, x86_64) and ``intel`` is used for
1112 a univeral build with the i386 and x86_64 architectures
Benjamin Petersonc39d7622008-12-30 17:56:45 +00001113
Benjamin Petersond23f8222009-04-05 19:13:16 +00001114 Examples of returned values on Mac OS X:
Benjamin Petersonc39d7622008-12-30 17:56:45 +00001115
1116 * ``macosx-10.3-ppc``
1117
1118 * ``macosx-10.3-fat``
1119
1120 * ``macosx-10.5-universal``
1121
Ronald Oussorenbea37ae2009-09-15 19:16:02 +00001122 * ``macosx-10.6-intel``
1123
Georg Brandl116aa622007-08-15 14:28:22 +00001124
1125.. function:: convert_path(pathname)
1126
1127 Return 'pathname' as a name that will work on the native filesystem, i.e. split
1128 it on '/' and put it back together again using the current directory separator.
1129 Needed because filenames in the setup script are always supplied in Unix style,
1130 and have to be converted to the local convention before we can actually use them
1131 in the filesystem. Raises :exc:`ValueError` on non-Unix-ish systems if
1132 *pathname* either starts or ends with a slash.
1133
1134
1135.. function:: change_root(new_root, pathname)
1136
1137 Return *pathname* with *new_root* prepended. If *pathname* is relative, this is
1138 equivalent to ``os.path.join(new_root,pathname)`` Otherwise, it requires making
1139 *pathname* relative and then joining the two, which is tricky on DOS/Windows.
1140
1141
1142.. function:: check_environ()
1143
1144 Ensure that 'os.environ' has all the environment variables we guarantee that
1145 users can use in config files, command-line options, etc. Currently this
1146 includes:
1147
1148 * :envvar:`HOME` - user's home directory (Unix only)
1149 * :envvar:`PLAT` - description of the current platform, including hardware and
1150 OS (see :func:`get_platform`)
1151
1152
1153.. function:: subst_vars(s, local_vars)
1154
1155 Perform shell/Perl-style variable substitution on *s*. Every occurrence of
1156 ``$`` followed by a name is considered a variable, and variable is substituted
1157 by the value found in the *local_vars* dictionary, or in ``os.environ`` if it's
1158 not in *local_vars*. *os.environ* is first checked/augmented to guarantee that
1159 it contains certain values: see :func:`check_environ`. Raise :exc:`ValueError`
1160 for any variables not found in either *local_vars* or ``os.environ``.
1161
1162 Note that this is not a fully-fledged string interpolation function. A valid
1163 ``$variable`` can consist only of upper and lower case letters, numbers and an
1164 underscore. No { } or ( ) style quoting is available.
1165
1166
1167.. function:: grok_environment_error(exc[, prefix='error: '])
1168
Antoine Pitrou771dea72011-10-12 18:35:18 +02001169 Generate a useful error message from an :exc:`OSError` exception object.
1170 Handles Python 1.5.1 and later styles, and does what it can to deal with
1171 exception objects that don't have a filename (which happens when the error
1172 is due to a two-file operation, such as :func:`rename` or :func:`link`).
1173 Returns the error message as a string prefixed with *prefix*.
Georg Brandl116aa622007-08-15 14:28:22 +00001174
1175
1176.. function:: split_quoted(s)
1177
1178 Split a string up according to Unix shell-like rules for quotes and backslashes.
1179 In short: words are delimited by spaces, as long as those spaces are not escaped
1180 by a backslash, or inside a quoted string. Single and double quotes are
1181 equivalent, and the quote characters can be backslash-escaped. The backslash is
1182 stripped from any two-character escape sequence, leaving only the escaped
1183 character. The quote characters are stripped from any quoted string. Returns a
1184 list of words.
1185
1186 .. % Should probably be moved into the standard library.
1187
1188
1189.. function:: execute(func, args[, msg=None, verbose=0, dry_run=0])
1190
1191 Perform some action that affects the outside world (for instance, writing to the
1192 filesystem). Such actions are special because they are disabled by the
1193 *dry_run* flag. This method takes care of all that bureaucracy for you; all
1194 you have to do is supply the function to call and an argument tuple for it (to
1195 embody the "external action" being performed), and an optional message to print.
1196
1197
1198.. function:: strtobool(val)
1199
1200 Convert a string representation of truth to true (1) or false (0).
1201
1202 True values are ``y``, ``yes``, ``t``, ``true``, ``on`` and ``1``; false values
1203 are ``n``, ``no``, ``f``, ``false``, ``off`` and ``0``. Raises
1204 :exc:`ValueError` if *val* is anything else.
1205
1206
1207.. function:: byte_compile(py_files[, optimize=0, force=0, prefix=None, base_dir=None, verbose=1, dry_run=0, direct=None])
1208
1209 Byte-compile a collection of Python source files to either :file:`.pyc` or
Éric Araujo47a45212011-10-08 00:34:13 +02001210 :file:`.pyo` files in a :file:`__pycache__` subdirectory (see :pep:`3147`).
1211 *py_files* is a list of files to compile; any files that don't end in
1212 :file:`.py` are silently skipped. *optimize* must be one of the following:
Georg Brandl116aa622007-08-15 14:28:22 +00001213
1214 * ``0`` - don't optimize (generate :file:`.pyc`)
1215 * ``1`` - normal optimization (like ``python -O``)
1216 * ``2`` - extra optimization (like ``python -OO``)
1217
1218 If *force* is true, all files are recompiled regardless of timestamps.
1219
Georg Brandl9afde1c2007-11-01 20:32:30 +00001220 The source filename encoded in each :term:`bytecode` file defaults to the filenames
Georg Brandl116aa622007-08-15 14:28:22 +00001221 listed in *py_files*; you can modify these with *prefix* and *basedir*.
1222 *prefix* is a string that will be stripped off of each source filename, and
1223 *base_dir* is a directory name that will be prepended (after *prefix* is
1224 stripped). You can supply either or both (or neither) of *prefix* and
1225 *base_dir*, as you wish.
1226
1227 If *dry_run* is true, doesn't actually do anything that would affect the
1228 filesystem.
1229
1230 Byte-compilation is either done directly in this interpreter process with the
1231 standard :mod:`py_compile` module, or indirectly by writing a temporary script
1232 and executing it. Normally, you should let :func:`byte_compile` figure out to
1233 use direct compilation or not (see the source for details). The *direct* flag
1234 is used by the script generated in indirect mode; unless you know what you're
1235 doing, leave it set to ``None``.
1236
Éric Araujo47a45212011-10-08 00:34:13 +02001237 .. versionchanged:: 3.2.3
1238 Create ``.pyc`` or ``.pyo`` files with an :func:`import magic tag
1239 <imp.get_tag>` in their name, in a :file:`__pycache__` subdirectory
1240 instead of files without tag in the current directory.
1241
Georg Brandl116aa622007-08-15 14:28:22 +00001242
1243.. function:: rfc822_escape(header)
1244
1245 Return a version of *header* escaped for inclusion in an :rfc:`822` header, by
1246 ensuring there are 8 spaces space after each newline. Note that it does no other
1247 modification of the string.
1248
1249 .. % this _can_ be replaced
1250
1251.. % \subsection{Distutils objects}
1252
1253
1254:mod:`distutils.dist` --- The Distribution class
1255================================================
1256
1257.. module:: distutils.dist
1258 :synopsis: Provides the Distribution class, which represents the module distribution being
1259 built/installed/distributed
1260
1261
1262This module provides the :class:`Distribution` class, which represents the
1263module distribution being built/installed/distributed.
1264
1265
1266:mod:`distutils.extension` --- The Extension class
1267==================================================
1268
1269.. module:: distutils.extension
1270 :synopsis: Provides the Extension class, used to describe C/C++ extension modules in setup
1271 scripts
1272
1273
1274This module provides the :class:`Extension` class, used to describe C/C++
1275extension modules in setup scripts.
1276
1277.. % \subsection{Ungrouped modules}
1278.. % The following haven't been moved into a more appropriate section yet.
1279
1280
1281:mod:`distutils.debug` --- Distutils debug mode
1282===============================================
1283
1284.. module:: distutils.debug
1285 :synopsis: Provides the debug flag for distutils
1286
1287
1288This module provides the DEBUG flag.
1289
1290
1291:mod:`distutils.errors` --- Distutils exceptions
1292================================================
1293
1294.. module:: distutils.errors
1295 :synopsis: Provides standard distutils exceptions
1296
1297
1298Provides exceptions used by the Distutils modules. Note that Distutils modules
1299may raise standard exceptions; in particular, SystemExit is usually raised for
1300errors that are obviously the end-user's fault (eg. bad command-line arguments).
1301
1302This module is safe to use in ``from ... import *`` mode; it only exports
1303symbols whose names start with ``Distutils`` and end with ``Error``.
1304
1305
1306:mod:`distutils.fancy_getopt` --- Wrapper around the standard getopt module
1307===========================================================================
1308
1309.. module:: distutils.fancy_getopt
1310 :synopsis: Additional getopt functionality
1311
1312
1313This module provides a wrapper around the standard :mod:`getopt` module that
1314provides the following additional features:
1315
1316* short and long options are tied together
1317
1318* options have help strings, so :func:`fancy_getopt` could potentially create a
1319 complete usage summary
1320
1321* options set attributes of a passed-in object
1322
1323* boolean options can have "negative aliases" --- eg. if :option:`--quiet` is
1324 the "negative alias" of :option:`--verbose`, then :option:`--quiet` on the
1325 command line sets *verbose* to false.
1326
Georg Brandl116aa622007-08-15 14:28:22 +00001327.. function:: fancy_getopt(options, negative_opt, object, args)
1328
1329 Wrapper function. *options* is a list of ``(long_option, short_option,
1330 help_string)`` 3-tuples as described in the constructor for
1331 :class:`FancyGetopt`. *negative_opt* should be a dictionary mapping option names
1332 to option names, both the key and value should be in the *options* list.
1333 *object* is an object which will be used to store values (see the :meth:`getopt`
1334 method of the :class:`FancyGetopt` class). *args* is the argument list. Will use
1335 ``sys.argv[1:]`` if you pass ``None`` as *args*.
1336
1337
1338.. function:: wrap_text(text, width)
1339
1340 Wraps *text* to less than *width* wide.
1341
Georg Brandl116aa622007-08-15 14:28:22 +00001342
1343.. class:: FancyGetopt([option_table=None])
1344
1345 The option_table is a list of 3-tuples: ``(long_option, short_option,
1346 help_string)``
1347
1348 If an option takes an argument, its *long_option* should have ``'='`` appended;
1349 *short_option* should just be a single character, no ``':'`` in any case.
1350 *short_option* should be ``None`` if a *long_option* doesn't have a
1351 corresponding *short_option*. All option tuples must have long options.
1352
1353The :class:`FancyGetopt` class provides the following methods:
1354
1355
1356.. method:: FancyGetopt.getopt([args=None, object=None])
1357
1358 Parse command-line options in args. Store as attributes on *object*.
1359
1360 If *args* is ``None`` or not supplied, uses ``sys.argv[1:]``. If *object* is
1361 ``None`` or not supplied, creates a new :class:`OptionDummy` instance, stores
1362 option values there, and returns a tuple ``(args, object)``. If *object* is
1363 supplied, it is modified in place and :func:`getopt` just returns *args*; in
1364 both cases, the returned *args* is a modified copy of the passed-in *args* list,
1365 which is left untouched.
1366
1367 .. % and args returned are?
1368
1369
1370.. method:: FancyGetopt.get_option_order()
1371
1372 Returns the list of ``(option, value)`` tuples processed by the previous run of
1373 :meth:`getopt` Raises :exc:`RuntimeError` if :meth:`getopt` hasn't been called
1374 yet.
1375
1376
1377.. method:: FancyGetopt.generate_help([header=None])
1378
1379 Generate help text (a list of strings, one per suggested line of output) from
1380 the option table for this :class:`FancyGetopt` object.
1381
1382 If supplied, prints the supplied *header* at the top of the help.
1383
1384
1385:mod:`distutils.filelist` --- The FileList class
1386================================================
1387
1388.. module:: distutils.filelist
Georg Brandl3221dc92009-04-27 16:23:47 +00001389 :synopsis: The FileList class, used for poking about the file system and
1390 building lists of files.
Georg Brandl116aa622007-08-15 14:28:22 +00001391
1392
1393This module provides the :class:`FileList` class, used for poking about the
1394filesystem and building lists of files.
1395
1396
1397:mod:`distutils.log` --- Simple PEP 282-style logging
1398=====================================================
1399
1400.. module:: distutils.log
1401 :synopsis: A simple logging mechanism, 282-style
1402
1403
Georg Brandl116aa622007-08-15 14:28:22 +00001404:mod:`distutils.spawn` --- Spawn a sub-process
1405==============================================
1406
1407.. module:: distutils.spawn
1408 :synopsis: Provides the spawn() function
1409
1410
1411This module provides the :func:`spawn` function, a front-end to various
1412platform-specific functions for launching another program in a sub-process.
1413Also provides :func:`find_executable` to search the path for a given executable
1414name.
1415
1416
1417:mod:`distutils.sysconfig` --- System configuration information
1418===============================================================
1419
1420.. module:: distutils.sysconfig
1421 :synopsis: Low-level access to configuration information of the Python interpreter.
1422.. moduleauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
1423.. moduleauthor:: Greg Ward <gward@python.net>
1424.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
1425
1426
1427The :mod:`distutils.sysconfig` module provides access to Python's low-level
1428configuration information. The specific configuration variables available
1429depend heavily on the platform and configuration. The specific variables depend
1430on the build process for the specific version of Python being run; the variables
1431are those found in the :file:`Makefile` and configuration header that are
1432installed with Python on Unix systems. The configuration header is called
1433:file:`pyconfig.h` for Python versions starting with 2.2, and :file:`config.h`
1434for earlier versions of Python.
1435
1436Some additional functions are provided which perform some useful manipulations
1437for other parts of the :mod:`distutils` package.
1438
1439
1440.. data:: PREFIX
1441
1442 The result of ``os.path.normpath(sys.prefix)``.
1443
1444
1445.. data:: EXEC_PREFIX
1446
1447 The result of ``os.path.normpath(sys.exec_prefix)``.
1448
1449
1450.. function:: get_config_var(name)
1451
1452 Return the value of a single variable. This is equivalent to
1453 ``get_config_vars().get(name)``.
1454
1455
1456.. function:: get_config_vars(...)
1457
1458 Return a set of variable definitions. If there are no arguments, this returns a
1459 dictionary mapping names of configuration variables to values. If arguments are
1460 provided, they should be strings, and the return value will be a sequence giving
1461 the associated values. If a given name does not have a corresponding value,
1462 ``None`` will be included for that variable.
1463
1464
1465.. function:: get_config_h_filename()
1466
1467 Return the full path name of the configuration header. For Unix, this will be
1468 the header generated by the :program:`configure` script; for other platforms the
1469 header will have been supplied directly by the Python source distribution. The
1470 file is a platform-specific text file.
1471
1472
1473.. function:: get_makefile_filename()
1474
1475 Return the full path name of the :file:`Makefile` used to build Python. For
1476 Unix, this will be a file generated by the :program:`configure` script; the
1477 meaning for other platforms will vary. The file is a platform-specific text
1478 file, if it exists. This function is only useful on POSIX platforms.
1479
1480
1481.. function:: get_python_inc([plat_specific[, prefix]])
1482
1483 Return the directory for either the general or platform-dependent C include
1484 files. If *plat_specific* is true, the platform-dependent include directory is
1485 returned; if false or omitted, the platform-independent directory is returned.
1486 If *prefix* is given, it is used as either the prefix instead of
1487 :const:`PREFIX`, or as the exec-prefix instead of :const:`EXEC_PREFIX` if
1488 *plat_specific* is true.
1489
1490
1491.. function:: get_python_lib([plat_specific[, standard_lib[, prefix]]])
1492
1493 Return the directory for either the general or platform-dependent library
1494 installation. If *plat_specific* is true, the platform-dependent include
1495 directory is returned; if false or omitted, the platform-independent directory
1496 is returned. If *prefix* is given, it is used as either the prefix instead of
1497 :const:`PREFIX`, or as the exec-prefix instead of :const:`EXEC_PREFIX` if
1498 *plat_specific* is true. If *standard_lib* is true, the directory for the
1499 standard library is returned rather than the directory for the installation of
1500 third-party extensions.
1501
1502The following function is only intended for use within the :mod:`distutils`
1503package.
1504
1505
1506.. function:: customize_compiler(compiler)
1507
1508 Do any platform-specific customization of a
1509 :class:`distutils.ccompiler.CCompiler` instance.
1510
1511 This function is only needed on Unix at this time, but should be called
1512 consistently to support forward-compatibility. It inserts the information that
1513 varies across Unix flavors and is stored in Python's :file:`Makefile`. This
1514 information includes the selected compiler, compiler and linker options, and the
1515 extension used by the linker for shared objects.
1516
1517This function is even more special-purpose, and should only be used from
1518Python's own build procedures.
1519
1520
1521.. function:: set_python_build()
1522
1523 Inform the :mod:`distutils.sysconfig` module that it is being used as part of
1524 the build process for Python. This changes a lot of relative locations for
1525 files, allowing them to be located in the build area rather than in an installed
1526 Python.
1527
1528
1529:mod:`distutils.text_file` --- The TextFile class
1530=================================================
1531
1532.. module:: distutils.text_file
1533 :synopsis: provides the TextFile class, a simple interface to text files
1534
1535
1536This module provides the :class:`TextFile` class, which gives an interface to
1537text files that (optionally) takes care of stripping comments, ignoring blank
1538lines, and joining lines with backslashes.
1539
1540
1541.. class:: TextFile([filename=None, file=None, **options])
1542
1543 This class provides a file-like object that takes care of all the things you
1544 commonly want to do when processing a text file that has some line-by-line
1545 syntax: strip comments (as long as ``#`` is your comment character), skip blank
1546 lines, join adjacent lines by escaping the newline (ie. backslash at end of
1547 line), strip leading and/or trailing whitespace. All of these are optional and
1548 independently controllable.
1549
1550 The class provides a :meth:`warn` method so you can generate warning messages
1551 that report physical line number, even if the logical line in question spans
1552 multiple physical lines. Also provides :meth:`unreadline` for implementing
1553 line-at-a-time lookahead.
1554
1555 :class:`TextFile` instances are create with either *filename*, *file*, or both.
1556 :exc:`RuntimeError` is raised if both are ``None``. *filename* should be a
1557 string, and *file* a file object (or something that provides :meth:`readline`
1558 and :meth:`close` methods). It is recommended that you supply at least
1559 *filename*, so that :class:`TextFile` can include it in warning messages. If
1560 *file* is not supplied, :class:`TextFile` creates its own using the
1561 :func:`open` built-in function.
1562
1563 The options are all boolean, and affect the values returned by :meth:`readline`
1564
1565 +------------------+--------------------------------+---------+
1566 | option name | description | default |
1567 +==================+================================+=========+
1568 | *strip_comments* | strip from ``'#'`` to end-of- | true |
1569 | | line, as well as any | |
1570 | | whitespace leading up to the | |
1571 | | ``'#'``\ ---unless it is | |
1572 | | escaped by a backslash | |
1573 +------------------+--------------------------------+---------+
1574 | *lstrip_ws* | strip leading whitespace from | false |
1575 | | each line before returning it | |
1576 +------------------+--------------------------------+---------+
1577 | *rstrip_ws* | strip trailing whitespace | true |
1578 | | (including line terminator!) | |
1579 | | from each line before | |
1580 | | returning it. | |
1581 +------------------+--------------------------------+---------+
1582 | *skip_blanks* | skip lines that are empty | true |
1583 | | \*after\* stripping comments | |
1584 | | and whitespace. (If both | |
1585 | | lstrip_ws and rstrip_ws are | |
1586 | | false, then some lines may | |
1587 | | consist of solely whitespace: | |
1588 | | these will \*not\* be skipped, | |
1589 | | even if *skip_blanks* is | |
1590 | | true.) | |
1591 +------------------+--------------------------------+---------+
1592 | *join_lines* | if a backslash is the last | false |
1593 | | non-newline character on a | |
1594 | | line after stripping comments | |
1595 | | and whitespace, join the | |
1596 | | following line to it to form | |
1597 | | one logical line; if N | |
1598 | | consecutive lines end with a | |
1599 | | backslash, then N+1 physical | |
1600 | | lines will be joined to form | |
1601 | | one logical line. | |
1602 +------------------+--------------------------------+---------+
1603 | *collapse_join* | strip leading whitespace from | false |
1604 | | lines that are joined to their | |
1605 | | predecessor; only matters if | |
1606 | | ``(join_lines and not | |
1607 | | lstrip_ws)`` | |
1608 +------------------+--------------------------------+---------+
1609
1610 Note that since *rstrip_ws* can strip the trailing newline, the semantics of
Georg Brandl22b34312009-07-26 14:54:51 +00001611 :meth:`readline` must differ from those of the built-in file object's
Georg Brandl116aa622007-08-15 14:28:22 +00001612 :meth:`readline` method! In particular, :meth:`readline` returns ``None`` for
1613 end-of-file: an empty string might just be a blank line (or an all-whitespace
1614 line), if *rstrip_ws* is true but *skip_blanks* is not.
1615
1616
1617 .. method:: TextFile.open(filename)
1618
Georg Brandl22b34312009-07-26 14:54:51 +00001619 Open a new file *filename*. This overrides any *file* or *filename*
1620 constructor arguments.
Georg Brandl116aa622007-08-15 14:28:22 +00001621
1622
1623 .. method:: TextFile.close()
1624
1625 Close the current file and forget everything we know about it (including the
1626 filename and the current line number).
1627
1628
1629 .. method:: TextFile.warn(msg[,line=None])
1630
1631 Print (to stderr) a warning message tied to the current logical line in the
1632 current file. If the current logical line in the file spans multiple physical
1633 lines, the warning refers to the whole range, such as ``"lines 3-5"``. If
1634 *line* is supplied, it overrides the current line number; it may be a list or
1635 tuple to indicate a range of physical lines, or an integer for a single
1636 physical line.
1637
1638
1639 .. method:: TextFile.readline()
1640
1641 Read and return a single logical line from the current file (or from an internal
1642 buffer if lines have previously been "unread" with :meth:`unreadline`). If the
1643 *join_lines* option is true, this may involve reading multiple physical lines
1644 concatenated into a single string. Updates the current line number, so calling
1645 :meth:`warn` after :meth:`readline` emits a warning about the physical line(s)
1646 just read. Returns ``None`` on end-of-file, since the empty string can occur
1647 if *rstrip_ws* is true but *strip_blanks* is not.
1648
1649
1650 .. method:: TextFile.readlines()
1651
1652 Read and return the list of all logical lines remaining in the current file.
1653 This updates the current line number to the last line of the file.
1654
1655
1656 .. method:: TextFile.unreadline(line)
1657
1658 Push *line* (a string) onto an internal buffer that will be checked by future
1659 :meth:`readline` calls. Handy for implementing a parser with line-at-a-time
1660 lookahead. Note that lines that are "unread" with :meth:`unreadline` are not
1661 subsequently re-cleansed (whitespace stripped, or whatever) when read with
1662 :meth:`readline`. If multiple calls are made to :meth:`unreadline` before a call
1663 to :meth:`readline`, the lines will be returned most in most recent first order.
1664
1665
1666:mod:`distutils.version` --- Version number classes
1667===================================================
1668
1669.. module:: distutils.version
1670 :synopsis: implements classes that represent module version numbers.
1671
1672
1673.. % todo
1674.. % \section{Distutils Commands}
Georg Brandl48310cd2009-01-03 21:18:54 +00001675.. %
Georg Brandl116aa622007-08-15 14:28:22 +00001676.. % This part of Distutils implements the various Distutils commands, such
1677.. % as \code{build}, \code{install} \&c. Each command is implemented as a
1678.. % separate module, with the command name as the name of the module.
1679
1680
1681:mod:`distutils.cmd` --- Abstract base class for Distutils commands
1682===================================================================
1683
1684.. module:: distutils.cmd
Georg Brandl4009c9e2010-10-06 08:26:09 +00001685 :synopsis: This module provides the abstract base class Command. This class
1686 is subclassed by the modules in the distutils.command subpackage.
Georg Brandl116aa622007-08-15 14:28:22 +00001687
1688
1689This module supplies the abstract base class :class:`Command`.
1690
1691
1692.. class:: Command(dist)
1693
1694 Abstract base class for defining command classes, the "worker bees" of the
1695 Distutils. A useful analogy for command classes is to think of them as
Georg Brandl4009c9e2010-10-06 08:26:09 +00001696 subroutines with local variables called *options*. The options are declared
1697 in :meth:`initialize_options` and defined (given their final values) in
1698 :meth:`finalize_options`, both of which must be defined by every command
1699 class. The distinction between the two is necessary because option values
1700 might come from the outside world (command line, config file, ...), and any
1701 options dependent on other options must be computed after these outside
1702 influences have been processed --- hence :meth:`finalize_options`. The body
1703 of the subroutine, where it does all its work based on the values of its
1704 options, is the :meth:`run` method, which must also be implemented by every
1705 command class.
Georg Brandl116aa622007-08-15 14:28:22 +00001706
Georg Brandl4009c9e2010-10-06 08:26:09 +00001707 The class constructor takes a single argument *dist*, a :class:`Distribution`
Georg Brandl116aa622007-08-15 14:28:22 +00001708 instance.
1709
1710
Georg Brandl4009c9e2010-10-06 08:26:09 +00001711Creating a new Distutils command
1712================================
1713
1714This section outlines the steps to create a new Distutils command.
1715
1716A new command lives in a module in the :mod:`distutils.command` package. There
1717is a sample template in that directory called :file:`command_template`. Copy
1718this file to a new module with the same name as the new command you're
1719implementing. This module should implement a class with the same name as the
1720module (and the command). So, for instance, to create the command
1721``peel_banana`` (so that users can run ``setup.py peel_banana``), you'd copy
1722:file:`command_template` to :file:`distutils/command/peel_banana.py`, then edit
1723it so that it's implementing the class :class:`peel_banana`, a subclass of
1724:class:`distutils.cmd.Command`.
1725
1726Subclasses of :class:`Command` must define the following methods.
1727
1728.. method:: Command.initialize_options()
1729
1730 Set default values for all the options that this command supports. Note that
1731 these defaults may be overridden by other commands, by the setup script, by
1732 config files, or by the command-line. Thus, this is not the place to code
1733 dependencies between options; generally, :meth:`initialize_options`
1734 implementations are just a bunch of ``self.foo = None`` assignments.
1735
1736
1737.. method:: Command.finalize_options()
1738
1739 Set final values for all the options that this command supports. This is
1740 always called as late as possible, ie. after any option assignments from the
1741 command-line or from other commands have been done. Thus, this is the place
Ezio Melottie130a522011-10-19 10:58:56 +03001742 to code option dependencies: if *foo* depends on *bar*, then it is safe to
Georg Brandl4009c9e2010-10-06 08:26:09 +00001743 set *foo* from *bar* as long as *foo* still has the same value it was
1744 assigned in :meth:`initialize_options`.
1745
1746
1747.. method:: Command.run()
1748
1749 A command's raison d'etre: carry out the action it exists to perform, controlled
1750 by the options initialized in :meth:`initialize_options`, customized by other
1751 commands, the setup script, the command-line, and config files, and finalized in
1752 :meth:`finalize_options`. All terminal output and filesystem interaction should
1753 be done by :meth:`run`.
1754
1755
1756.. attribute:: Command.sub_commands
1757
1758 *sub_commands* formalizes the notion of a "family" of commands,
1759 e.g. ``install`` as the parent with sub-commands ``install_lib``,
1760 ``install_headers``, etc. The parent of a family of commands defines
1761 *sub_commands* as a class attribute; it's a list of 2-tuples ``(command_name,
1762 predicate)``, with *command_name* a string and *predicate* a function, a
1763 string or ``None``. *predicate* is a method of the parent command that
1764 determines whether the corresponding command is applicable in the current
Éric Araujo000893f2011-05-29 00:14:45 +02001765 situation. (E.g. ``install_headers`` is only applicable if we have any C
Georg Brandl4009c9e2010-10-06 08:26:09 +00001766 header files to install.) If *predicate* is ``None``, that command is always
1767 applicable.
1768
1769 *sub_commands* is usually defined at the *end* of a class, because
1770 predicates can be methods of the class, so they must already have been
1771 defined. The canonical example is the :command:`install` command.
1772
1773
Georg Brandl116aa622007-08-15 14:28:22 +00001774:mod:`distutils.command` --- Individual Distutils commands
1775==========================================================
1776
1777.. module:: distutils.command
1778 :synopsis: This subpackage contains one module for each standard Distutils command.
1779
1780
1781.. % \subsubsection{Individual Distutils commands}
1782.. % todo
1783
1784
1785:mod:`distutils.command.bdist` --- Build a binary installer
1786===========================================================
1787
1788.. module:: distutils.command.bdist
1789 :synopsis: Build a binary installer for a package
1790
1791
1792.. % todo
1793
1794
1795:mod:`distutils.command.bdist_packager` --- Abstract base class for packagers
1796=============================================================================
1797
1798.. module:: distutils.command.bdist_packager
1799 :synopsis: Abstract base class for packagers
1800
1801
1802.. % todo
1803
1804
1805:mod:`distutils.command.bdist_dumb` --- Build a "dumb" installer
1806================================================================
1807
1808.. module:: distutils.command.bdist_dumb
1809 :synopsis: Build a "dumb" installer - a simple archive of files
1810
1811
1812.. % todo
1813
1814
1815:mod:`distutils.command.bdist_msi` --- Build a Microsoft Installer binary package
1816=================================================================================
1817
1818.. module:: distutils.command.bdist_msi
1819 :synopsis: Build a binary distribution as a Windows MSI file
1820
Éric Araujo5864b9f2011-05-31 21:50:38 +02001821.. class:: bdist_msi
Georg Brandl116aa622007-08-15 14:28:22 +00001822
Benjamin Petersond23f8222009-04-05 19:13:16 +00001823 Builds a `Windows Installer`_ (.msi) binary package.
1824
1825 .. _Windows Installer: http://msdn.microsoft.com/en-us/library/cc185688(VS.85).aspx
1826
1827 In most cases, the ``bdist_msi`` installer is a better choice than the
1828 ``bdist_wininst`` installer, because it provides better support for
1829 Win64 platforms, allows administrators to perform non-interactive
1830 installations, and allows installation through group policies.
Georg Brandl116aa622007-08-15 14:28:22 +00001831
1832
1833:mod:`distutils.command.bdist_rpm` --- Build a binary distribution as a Redhat RPM and SRPM
1834===========================================================================================
1835
1836.. module:: distutils.command.bdist_rpm
1837 :synopsis: Build a binary distribution as a Redhat RPM and SRPM
1838
1839
1840.. % todo
1841
1842
1843:mod:`distutils.command.bdist_wininst` --- Build a Windows installer
1844====================================================================
1845
1846.. module:: distutils.command.bdist_wininst
1847 :synopsis: Build a Windows installer
1848
1849
1850.. % todo
1851
1852
1853:mod:`distutils.command.sdist` --- Build a source distribution
1854==============================================================
1855
1856.. module:: distutils.command.sdist
1857 :synopsis: Build a source distribution
1858
1859
1860.. % todo
1861
1862
1863:mod:`distutils.command.build` --- Build all files of a package
1864===============================================================
1865
1866.. module:: distutils.command.build
1867 :synopsis: Build all files of a package
1868
1869
1870.. % todo
1871
1872
1873:mod:`distutils.command.build_clib` --- Build any C libraries in a package
1874==========================================================================
1875
1876.. module:: distutils.command.build_clib
1877 :synopsis: Build any C libraries in a package
1878
1879
1880.. % todo
1881
1882
1883:mod:`distutils.command.build_ext` --- Build any extensions in a package
1884========================================================================
1885
1886.. module:: distutils.command.build_ext
1887 :synopsis: Build any extensions in a package
1888
1889
1890.. % todo
1891
1892
1893:mod:`distutils.command.build_py` --- Build the .py/.pyc files of a package
1894===========================================================================
1895
1896.. module:: distutils.command.build_py
1897 :synopsis: Build the .py/.pyc files of a package
1898
1899
Éric Araujo5864b9f2011-05-31 21:50:38 +02001900.. class:: build_py
Martin v. Löwis73a22f02008-03-22 00:35:10 +00001901
Éric Araujo5864b9f2011-05-31 21:50:38 +02001902.. class:: build_py_2to3
Martin v. Löwis73a22f02008-03-22 00:35:10 +00001903
1904 Alternative implementation of build_py which also runs the
1905 2to3 conversion library on each .py file that is going to be
1906 installed. To use this in a setup.py file for a distribution
1907 that is designed to run with both Python 2.x and 3.x, add::
1908
1909 try:
1910 from distutils.command.build_py import build_py_2to3 as build_py
1911 except ImportError:
1912 from distutils.command.build_py import build_py
1913
1914 to your setup.py, and later::
1915
Georg Brandl682d7e02010-10-06 10:26:05 +00001916 cmdclass = {'build_py': build_py}
Martin v. Löwis73a22f02008-03-22 00:35:10 +00001917
1918 to the invocation of setup().
Georg Brandl116aa622007-08-15 14:28:22 +00001919
1920
1921:mod:`distutils.command.build_scripts` --- Build the scripts of a package
1922=========================================================================
1923
1924.. module:: distutils.command.build_scripts
1925 :synopsis: Build the scripts of a package
1926
1927
1928.. % todo
1929
1930
1931:mod:`distutils.command.clean` --- Clean a package build area
1932=============================================================
1933
1934.. module:: distutils.command.clean
1935 :synopsis: Clean a package build area
1936
1937
1938.. % todo
1939
1940
1941:mod:`distutils.command.config` --- Perform package configuration
1942=================================================================
1943
1944.. module:: distutils.command.config
1945 :synopsis: Perform package configuration
1946
1947
1948.. % todo
1949
1950
1951:mod:`distutils.command.install` --- Install a package
1952======================================================
1953
1954.. module:: distutils.command.install
1955 :synopsis: Install a package
1956
1957
1958.. % todo
1959
1960
1961:mod:`distutils.command.install_data` --- Install data files from a package
1962===========================================================================
1963
1964.. module:: distutils.command.install_data
1965 :synopsis: Install data files from a package
1966
1967
1968.. % todo
1969
1970
1971:mod:`distutils.command.install_headers` --- Install C/C++ header files from a package
1972======================================================================================
1973
1974.. module:: distutils.command.install_headers
1975 :synopsis: Install C/C++ header files from a package
1976
1977
1978.. % todo
1979
1980
1981:mod:`distutils.command.install_lib` --- Install library files from a package
1982=============================================================================
1983
1984.. module:: distutils.command.install_lib
1985 :synopsis: Install library files from a package
1986
1987
1988.. % todo
1989
1990
1991:mod:`distutils.command.install_scripts` --- Install script files from a package
1992================================================================================
1993
1994.. module:: distutils.command.install_scripts
1995 :synopsis: Install script files from a package
1996
1997
1998.. % todo
1999
2000
2001:mod:`distutils.command.register` --- Register a module with the Python Package Index
2002=====================================================================================
2003
2004.. module:: distutils.command.register
2005 :synopsis: Register a module with the Python Package Index
2006
2007
2008The ``register`` command registers the package with the Python Package Index.
2009This is described in more detail in :pep:`301`.
2010
2011.. % todo
Tarek Ziadé96c45a92010-07-31 09:10:51 +00002012
Éric Araujo4b8f6652011-05-29 18:05:53 +02002013
Tarek Ziadé96c45a92010-07-31 09:10:51 +00002014:mod:`distutils.command.check` --- Check the meta-data of a package
2015===================================================================
2016
2017.. module:: distutils.command.check
2018 :synopsis: Check the metadata of a package
2019
2020
2021The ``check`` command performs some tests on the meta-data of a package.
2022For example, it verifies that all required meta-data are provided as
2023the arguments passed to the :func:`setup` function.
2024
2025.. % todo