2 :mod:`compileall` --- Byte-compile Python libraries
3 ===================================================
6 :synopsis: Tools for byte-compiling all Python source files in a directory tree.
9 This module provides some utility functions to support installing Python
10 libraries. These functions compile Python source files in a directory tree,
11 allowing users without permission to write to the libraries to take advantage of
12 cached byte-code files.
14 This module may also be used as a script (using the :option:`-m` Python flag) to
15 compile Python sources. Directories to recursively traverse (passing
16 :option:`-l` stops the recursive behavior) for sources are listed on the command
17 line. If no arguments are given, the invocation is equivalent to ``-l
18 sys.path``. Printing lists of the files compiled can be disabled with the
19 :option:`-q` flag. In addition, the :option:`-x` option takes a regular
20 expression argument. All files that match the expression will be skipped.
23 .. function:: compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]])
25 Recursively descend the directory tree named by *dir*, compiling all :file:`.py`
26 files along the way. The *maxlevels* parameter is used to limit the depth of
27 the recursion; it defaults to ``10``. If *ddir* is given, it is used as the
28 base path from which the filenames used in error messages will be generated.
29 If *force* is true, modules are re-compiled even if the timestamps are up to
32 If *rx* is given, it specifies a regular expression of file names to exclude
33 from the search; that expression is searched for in the full path.
35 If *quiet* is true, nothing is printed to the standard output in normal
39 .. function:: compile_path([skip_curdir[, maxlevels[, force]]])
41 Byte-compile all the :file:`.py` files found along ``sys.path``. If
42 *skip_curdir* is true (the default), the current directory is not included in
43 the search. The *maxlevels* and *force* parameters default to ``0`` and are
44 passed to the :func:`compile_dir` function.
46 To force a recompile of all the :file:`.py` files in the :file:`Lib/`
47 subdirectory and all its subdirectories::
51 compileall.compile_dir('Lib/', force=True)
53 # Perform same compilation, excluding files in .svn directories.
55 compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True)
60 Module :mod:`py_compile`
61 Byte-compile a single source file.