Changeset 391 for python/trunk/Doc/library/compileall.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/library/compileall.rst
r2 r391 1 2 1 :mod:`compileall` --- Byte-compile Python libraries 3 2 =================================================== … … 8 7 9 8 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. 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. 21 13 22 14 23 .. function:: compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]]) 15 Command-line use 16 ---------------- 17 18 This module can work as a script (using :program:`python -m compileall`) to 19 compile Python sources. 20 21 .. program:: compileall 22 23 .. cmdoption:: [directory|file]... 24 25 Positional arguments are files to compile or directories that contain 26 source files, traversed recursively. If no argument is given, behave as if 27 the command line was ``-l <directories from sys.path>``. 28 29 .. cmdoption:: -l 30 31 Do not recurse into subdirectories, only compile source code files directly 32 contained in the named or implied directories. 33 34 .. cmdoption:: -f 35 36 Force rebuild even if timestamps are up-to-date. 37 38 .. cmdoption:: -q 39 40 Do not print the list of files compiled, print only error messages. 41 42 .. cmdoption:: -d destdir 43 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. 49 50 .. cmdoption:: -x regex 51 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. 54 55 .. cmdoption:: -i list 56 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``. 60 61 .. versionchanged:: 2.7 62 Added the ``-i`` option. 63 64 65 Public functions 66 ---------------- 67 68 .. function:: compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]]) 24 69 25 70 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. 71 files along the way. 72 73 The *maxlevels* parameter is used to limit the depth of the recursion; it 74 defaults to ``10``. 75 76 If *ddir* is given, it is prepended to the path to each file being compiled 77 for use in compilation time tracebacks, and is also compiled in to the 78 byte-code file, where it will be used in tracebacks and other messages in 79 cases where the source file does not exist at the time the byte-code file is 80 executed. 81 29 82 If *force* is true, modules are re-compiled even if the timestamps are up to 30 83 date. 31 84 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. 85 If *rx* is given, its search method is called on the complete path to each 86 file considered for compilation, and if it returns a true value, the file 87 is skipped. 34 88 35 If *quiet* is true, nothing is printed to the standard output in normal 36 operation. 89 If *quiet* is true, nothing is printed to the standard output unless errors 90 occur. 91 92 93 .. function:: compile_file(fullname[, ddir[, force[, rx[, quiet]]]]) 94 95 Compile the file with path *fullname*. 96 97 If *ddir* is given, it is prepended to the path to the file being compiled 98 for use in compilation time tracebacks, and is also compiled in to the 99 byte-code file, where it will be used in tracebacks and other messages in 100 cases where the source file does not exist at the time the byte-code file is 101 executed. 102 103 If *rx* is given, its search method is passed the full path name to the 104 file being compiled, and if it returns a true value, the file is not 105 compiled and ``True`` is returned. 106 107 If *quiet* is true, nothing is printed to the standard output unless errors 108 occur. 109 110 .. versionadded:: 2.7 37 111 38 112 … … 40 114 41 115 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. 116 *skip_curdir* is true (the default), the current directory is not included 117 in the search. All other parameters are passed to the :func:`compile_dir` 118 function. Note that unlike the other compile functions, ``maxlevels`` 119 defaults to ``0``. 45 120 46 121 To force a recompile of all the :file:`.py` files in the :file:`Lib/` … … 53 128 # Perform same compilation, excluding files in .svn directories. 54 129 import re 55 compileall.compile_dir('Lib/', rx=re.compile( '/[.]svn'), force=True)130 compileall.compile_dir('Lib/', rx=re.compile(r'[/\\][.]svn'), force=True) 56 131 57 132 … … 60 135 Module :mod:`py_compile` 61 136 Byte-compile a single source file. 62
Note:
See TracChangeset
for help on using the changeset viewer.