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