|
1 |
|
2 :mod:`compileall` --- Byte-compile Python libraries |
|
3 =================================================== |
|
4 |
|
5 .. module:: compileall |
|
6 :synopsis: Tools for byte-compiling all Python source files in a directory tree. |
|
7 |
|
8 |
|
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. |
|
13 |
|
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. |
|
21 |
|
22 |
|
23 .. function:: compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]]) |
|
24 |
|
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 |
|
30 date. |
|
31 |
|
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. |
|
34 |
|
35 If *quiet* is true, nothing is printed to the standard output in normal |
|
36 operation. |
|
37 |
|
38 |
|
39 .. function:: compile_path([skip_curdir[, maxlevels[, force]]]) |
|
40 |
|
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. |
|
45 |
|
46 To force a recompile of all the :file:`.py` files in the :file:`Lib/` |
|
47 subdirectory and all its subdirectories:: |
|
48 |
|
49 import compileall |
|
50 |
|
51 compileall.compile_dir('Lib/', force=True) |
|
52 |
|
53 # Perform same compilation, excluding files in .svn directories. |
|
54 import re |
|
55 compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True) |
|
56 |
|
57 |
|
58 .. seealso:: |
|
59 |
|
60 Module :mod:`py_compile` |
|
61 Byte-compile a single source file. |
|
62 |