66
77
88This module provides some utility functions to support installing Python
9- libraries. These functions compile Python source files in a directory tree,
10- allowing users without permission to write to the libraries to take advantage of
11- cached byte-code files.
9+ libraries. These functions compile Python source files in a directory tree.
10+ This module can be used to create the cached byte-code files at library
11+ installation time, which makes them available for use even by users who don't
12+ have write permission to the library directories.
1213
1314
1415Command-line use
@@ -27,32 +28,42 @@ compile Python sources.
2728
2829.. cmdoption :: -l
2930
30- Do not recurse.
31+ Do not recurse into subdirectories, only compile source code files directly
32+ contained in the named or implied directories.
3133
3234.. cmdoption :: -f
3335
3436 Force rebuild even if timestamps are up-to-date.
3537
3638.. cmdoption :: -q
3739
38- Do not print the list of files compiled.
40+ Do not print the list of files compiled, print only error messages .
3941
4042.. cmdoption :: -d destdir
4143
42- Purported directory name for error messages.
44+ Directory prepended to the path to each file being compiled. This will
45+ appear in compilation time tracebacks, and is also compiled in to the
46+ byte-code file, where it will be used in tracebacks and other messages in
47+ cases where the source file does not exist at the time the byte-code file is
48+ executed.
4349
4450.. cmdoption :: -x regex
4551
46- Skip files with a full path that matches given regular expression.
52+ regex is used to search the full path to each file considered for
53+ compilation, and if the regex produces a match, the file is skipped.
4754
4855.. cmdoption :: -i list
4956
50- Expand list with its content (file and directory names).
57+ Read the file ``list `` and add each line that it contains to the list of
58+ files and directories to compile. If ``list `` is ``- ``, read lines from
59+ ``stdin ``.
5160
5261.. cmdoption :: -b
5362
54- Write legacy ``.pyc `` file path names. Default is to write :pep: `3147 `-style
55- byte-compiled path names.
63+ Write the byte-code files to their legacy locations and names, which may
64+ overwrite byte-code files created by another version of Python. The default
65+ is to write files to their :pep: `3147 ` locations and names, which allows
66+ byte-code files from multiple versions of Python to coexist.
5667
5768.. versionchanged :: 3.2
5869 Added the ``-i ``, ``-b `` and ``-h `` options.
@@ -64,20 +75,32 @@ Public functions
6475.. function :: compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None, quiet=False, legacy=False, optimize=-1)
6576
6677 Recursively descend the directory tree named by *dir *, compiling all :file: `.py `
67- files along the way. The *maxlevels * parameter is used to limit the depth of
68- the recursion; it defaults to ``10 ``. If *ddir * is given, it is used as the
69- base path from which the filenames used in error messages will be generated.
78+ files along the way.
79+
80+ The *maxlevels * parameter is used to limit the depth of the recursion; it
81+ defaults to ``10 ``.
82+
83+ If *ddir * is given, it is prepended to the path to each file being compiled
84+ for use in compilation time tracebacks, and is also compiled in to the
85+ byte-code file, where it will be used in tracebacks and other messages in
86+ cases where the source file does not exist at the time the byte-code file is
87+ executed.
88+
7089 If *force * is true, modules are re-compiled even if the timestamps are up to
7190 date.
7291
73- If *rx * is given, it specifies a regular expression of file names to exclude
74- from the search; that expression is searched for in the full path.
92+ If *rx * is given, its search method is called on the complete path to each
93+ file considered for compilation, and if it returns a true value, the file
94+ is skipped.
7595
76- If *quiet * is true, nothing is printed to the standard output in normal
77- operation .
96+ If *quiet * is true, nothing is printed to the standard output unless errors
97+ occur .
7898
79- If *legacy * is true, old-style ``.pyc `` file path names are written,
80- otherwise (the default), :pep: `3147 `-style path names are written.
99+ If *legacy * is true, byte-code files are written to their legacy locations
100+ and names, which may overwrite byte-code files created by another version of
101+ Python. The default is to write files to their :pep: `3147 ` locations and
102+ names, which allows byte-code files from multiple versions of Python to
103+ coexist.
81104
82105 *optimize * specifies the optimization level for the compiler. It is passed to
83106 the built-in :func: `compile ` function.
@@ -88,19 +111,26 @@ Public functions
88111
89112.. function :: compile_file(fullname, ddir=None, force=False, rx=None, quiet=False, legacy=False, optimize=-1)
90113
91- Compile the file with path *fullname *. If *ddir * is given, it is used as the
92- base path from which the filename used in error messages will be generated.
93- If *force * is true, modules are re-compiled even if the timestamp is up to
94- date.
114+ Compile the file with path *fullname *.
115+
116+ If *ddir * is given, it is prepended to the path to the file being compiled
117+ for use in compilation time tracebacks, and is also compiled in to the
118+ byte-code file, where it will be used in tracebacks and other messages in
119+ cases where the source file does not exist at the time the byte-code file is
120+ executed.
95121
96- If *rx * is given, it specifies a regular expression which, if matched, will
97- prevent compilation; that expression is searched for in the full path.
122+ If *ra * is given, its search method is passed the full path name to the
123+ file being compiled, and if it returns a true value, the file is not
124+ compiled and ``True `` is returned.
98125
99- If *quiet * is true, nothing is printed to the standard output in normal
100- operation .
126+ If *quiet * is true, nothing is printed to the standard output unless errors
127+ occur .
101128
102- If *legacy * is true, old-style ``.pyc `` file path names are written,
103- otherwise (the default), :pep: `3147 `-style path names are written.
129+ If *legacy * is true, byte-code files are written to their legacy locations
130+ and names, which may overwrite byte-code files created by another version of
131+ Python. The default is to write files to their :pep: `3147 ` locations and
132+ names, which allows byte-code files from multiple versions of Python to
133+ coexist.
104134
105135 *optimize * specifies the optimization level for the compiler. It is passed to
106136 the built-in :func: `compile ` function.
@@ -111,9 +141,10 @@ Public functions
111141.. function :: compile_path(skip_curdir=True, maxlevels=0, force=False, legacy=False, optimize=-1)
112142
113143 Byte-compile all the :file: `.py ` files found along ``sys.path ``. If
114- *skip_curdir * is true (the default), the current directory is not included in
115- the search. All other parameters are passed to the :func: `compile_dir `
116- function.
144+ *skip_curdir * is true (the default), the current directory is not included
145+ in the search. All other parameters are passed to the :func: `compile_dir `
146+ function. Note that unlike the other compile functions, ``maxlevels ``
147+ defaults to ``0 ``.
117148
118149 .. versionchanged :: 3.2
119150 Added the *legacy * and *optimize * parameter.
0 commit comments