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 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 14 | |
Éric Araujo | a8132ec | 2010-12-16 03:53:53 +0000 | [diff] [blame^] | 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. |
| 32 | |
| 33 | .. cmdoption:: -f |
| 34 | |
| 35 | Force rebuild even if timestamps are up-to-date. |
| 36 | |
| 37 | .. cmdoption:: -q |
| 38 | |
| 39 | Do not print the list of files compiled. |
| 40 | |
| 41 | .. cmdoption:: -d destdir |
| 42 | |
| 43 | Purported directory name for error messages. |
| 44 | |
| 45 | .. cmdoption:: -x regex |
| 46 | |
| 47 | Skip files with a full path that matches given regular expression. |
| 48 | |
| 49 | .. cmdoption:: -i list |
| 50 | |
| 51 | Expand list with its content (file and directory names). |
| 52 | |
| 53 | .. versionadded:: 2.7 |
| 54 | The ``-i`` option. |
| 55 | |
| 56 | |
| 57 | Public functions |
| 58 | ---------------- |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 59 | |
| 60 | .. function:: compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]]) |
| 61 | |
| 62 | Recursively descend the directory tree named by *dir*, compiling all :file:`.py` |
| 63 | files along the way. The *maxlevels* parameter is used to limit the depth of |
| 64 | the recursion; it defaults to ``10``. If *ddir* is given, it is used as the |
| 65 | base path from which the filenames used in error messages will be generated. |
| 66 | If *force* is true, modules are re-compiled even if the timestamps are up to |
| 67 | date. |
| 68 | |
| 69 | If *rx* is given, it specifies a regular expression of file names to exclude |
| 70 | from the search; that expression is searched for in the full path. |
| 71 | |
| 72 | If *quiet* is true, nothing is printed to the standard output in normal |
| 73 | operation. |
| 74 | |
Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 75 | .. function:: compile_path([skip_curdir[, maxlevels[, force]]]) |
| 76 | |
| 77 | Byte-compile all the :file:`.py` files found along ``sys.path``. If |
| 78 | *skip_curdir* is true (the default), the current directory is not included in |
| 79 | the search. The *maxlevels* and *force* parameters default to ``0`` and are |
| 80 | passed to the :func:`compile_dir` function. |
| 81 | |
| 82 | To force a recompile of all the :file:`.py` files in the :file:`Lib/` |
| 83 | subdirectory and all its subdirectories:: |
| 84 | |
| 85 | import compileall |
| 86 | |
| 87 | compileall.compile_dir('Lib/', force=True) |
| 88 | |
| 89 | # Perform same compilation, excluding files in .svn directories. |
| 90 | import re |
| 91 | compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True) |
| 92 | |
| 93 | |
| 94 | .. seealso:: |
| 95 | |
| 96 | Module :mod:`py_compile` |
| 97 | Byte-compile a single source file. |