blob: 83e418d30c5161959d89644182e9cf3158a75a22 [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001:mod:`compileall` --- Byte-compile Python libraries
2===================================================
3
4.. module:: compileall
5 :synopsis: Tools for byte-compiling all Python source files in a directory tree.
6
7
8This module provides some utility functions to support installing Python
9libraries. These functions compile Python source files in a directory tree,
10allowing users without permission to write to the libraries to take advantage of
11cached byte-code files.
12
Benjamin Peterson5478b472008-09-17 22:25:09 +000013This module may also be used as a script (using the :option:`-m` Python flag) to
14compile Python sources. Directories to recursively traverse (passing
15:option:`-l` stops the recursive behavior) for sources are listed on the command
16line. If no arguments are given, the invocation is equivalent to ``-l
17sys.path``. Printing lists of the files compiled can be disabled with the
18:option:`-q` flag. In addition, the :option:`-x` option takes a regular
19expression argument. All files that match the expression will be skipped.
Georg Brandl116aa622007-08-15 14:28:22 +000020
21
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000022.. function:: compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None, quiet=False)
Georg Brandl116aa622007-08-15 14:28:22 +000023
24 Recursively descend the directory tree named by *dir*, compiling all :file:`.py`
25 files along the way. The *maxlevels* parameter is used to limit the depth of
26 the recursion; it defaults to ``10``. If *ddir* is given, it is used as the
27 base path from which the filenames used in error messages will be generated.
28 If *force* is true, modules are re-compiled even if the timestamps are up to
29 date.
30
31 If *rx* is given, it specifies a regular expression of file names to exclude
32 from the search; that expression is searched for in the full path.
33
34 If *quiet* is true, nothing is printed to the standard output in normal
35 operation.
36
37
Georg Brandlc2a4f4f2009-04-10 09:03:43 +000038.. function:: compile_path(skip_curdir=True, maxlevels=0, force=False)
Georg Brandl116aa622007-08-15 14:28:22 +000039
40 Byte-compile all the :file:`.py` files found along ``sys.path``. If
41 *skip_curdir* is true (the default), the current directory is not included in
42 the search. The *maxlevels* and *force* parameters default to ``0`` and are
43 passed to the :func:`compile_dir` function.
44
45To force a recompile of all the :file:`.py` files in the :file:`Lib/`
46subdirectory and all its subdirectories::
47
48 import compileall
49
50 compileall.compile_dir('Lib/', force=True)
51
52 # Perform same compilation, excluding files in .svn directories.
53 import re
54 compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True)
55
56
57.. seealso::
58
59 Module :mod:`py_compile`
60 Byte-compile a single source file.
61