Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 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 | The source file for this module may also be used as a script to compile Python |
| 15 | sources in directories named on the command line or in ``sys.path``. |
| 16 | |
| 17 | |
| 18 | .. function:: compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]]) |
| 19 | |
| 20 | Recursively descend the directory tree named by *dir*, compiling all :file:`.py` |
| 21 | files along the way. The *maxlevels* parameter is used to limit the depth of |
| 22 | the recursion; it defaults to ``10``. If *ddir* is given, it is used as the |
| 23 | base path from which the filenames used in error messages will be generated. |
| 24 | If *force* is true, modules are re-compiled even if the timestamps are up to |
| 25 | date. |
| 26 | |
| 27 | If *rx* is given, it specifies a regular expression of file names to exclude |
| 28 | from the search; that expression is searched for in the full path. |
| 29 | |
| 30 | If *quiet* is true, nothing is printed to the standard output in normal |
| 31 | operation. |
| 32 | |
| 33 | |
| 34 | .. function:: compile_path([skip_curdir[, maxlevels[, force]]]) |
| 35 | |
| 36 | Byte-compile all the :file:`.py` files found along ``sys.path``. If |
| 37 | *skip_curdir* is true (the default), the current directory is not included in |
| 38 | the search. The *maxlevels* and *force* parameters default to ``0`` and are |
| 39 | passed to the :func:`compile_dir` function. |
| 40 | |
| 41 | To force a recompile of all the :file:`.py` files in the :file:`Lib/` |
| 42 | subdirectory and all its subdirectories:: |
| 43 | |
| 44 | import compileall |
| 45 | |
| 46 | compileall.compile_dir('Lib/', force=True) |
| 47 | |
| 48 | # Perform same compilation, excluding files in .svn directories. |
| 49 | import re |
| 50 | compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True) |
| 51 | |
| 52 | |
| 53 | .. seealso:: |
| 54 | |
| 55 | Module :mod:`py_compile` |
| 56 | Byte-compile a single source file. |
| 57 | |