Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 1 | \section{\module{compileall} --- |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 2 | Byte-compile Python libraries} |
Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 3 | |
| 4 | \declaremodule{standard}{compileall} |
Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 5 | \modulesynopsis{Tools for byte-compiling all Python source files in a |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 6 | directory tree.} |
Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 7 | |
| 8 | |
| 9 | This module provides some utility functions to support installing |
| 10 | Python libraries. These functions compile Python source files in a |
| 11 | directory tree, allowing users without permission to write to the |
| 12 | libraries to take advantage of cached byte-code files. |
| 13 | |
| 14 | The source file for this module may also be used as a script to |
| 15 | compile Python sources in directories named on the command line or in |
| 16 | \code{sys.path}. |
| 17 | |
| 18 | |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 19 | \begin{funcdesc}{compile_dir}{dir\optional{, maxlevels\optional{, |
Martin v. Löwis | 5c137c2 | 2002-03-18 12:44:08 +0000 | [diff] [blame] | 20 | ddir\optional{, force\optional{, |
| 21 | rx\optional{, quiet}}}}}} |
Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 22 | Recursively descend the directory tree named by \var{dir}, compiling |
| 23 | all \file{.py} files along the way. The \var{maxlevels} parameter |
| 24 | is used to limit the depth of the recursion; it defaults to |
| 25 | \code{10}. If \var{ddir} is given, it is used as the base path from |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 26 | which the filenames used in error messages will be generated. If |
| 27 | \var{force} is true, modules are re-compiled even if the timestamps |
Martin v. Löwis | 5c137c2 | 2002-03-18 12:44:08 +0000 | [diff] [blame] | 28 | are up to date. |
| 29 | |
| 30 | If \var{rx} is given, it specifies a regular expression of file |
| 31 | names to exclude from the search; that expression is searched for in |
| 32 | the full path. |
| 33 | |
| 34 | If \var{quiet} is true, nothing is printed to the standard output |
| 35 | in normal operation. |
Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 36 | \end{funcdesc} |
| 37 | |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 38 | \begin{funcdesc}{compile_path}{\optional{skip_curdir\optional{, |
| 39 | maxlevels\optional{, force}}}} |
Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 40 | Byte-compile all the \file{.py} files found along \code{sys.path}. |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 41 | If \var{skip_curdir} is true (the default), the current directory is |
| 42 | not included in the search. The \var{maxlevels} and |
| 43 | \var{force} parameters default to \code{0} and are passed to the |
| 44 | \function{compile_dir()} function. |
Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 45 | \end{funcdesc} |
| 46 | |
Andrew M. Kuchling | 35f64c1 | 2006-07-29 13:56:48 +0000 | [diff] [blame^] | 47 | To force a recompile of all the \file{.py} files in the \file{Lib/} |
| 48 | subdirectory and all its subdirectories: |
| 49 | |
| 50 | \begin{verbatim} |
| 51 | import compileall |
| 52 | |
| 53 | compileall.compile_dir('Lib/', force=True) |
| 54 | |
| 55 | # Perform same compilation, excluding files in .svn directories. |
| 56 | import re |
| 57 | compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True) |
| 58 | \end{verbatim} |
| 59 | |
Fred Drake | e72e1e0 | 1998-08-11 15:46:42 +0000 | [diff] [blame] | 60 | |
| 61 | \begin{seealso} |
| 62 | \seemodule[pycompile]{py_compile}{Byte-compile a single source file.} |
| 63 | \end{seealso} |