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