blob: ac0feb7092d9929902742dca672bc94bda512205 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
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
9This module provides some utility functions to support installing Python
10libraries. These functions compile Python source files in a directory tree,
11allowing users without permission to write to the libraries to take advantage of
12cached byte-code files.
13
Georg Brandl8ec7f652007-08-15 14:28:01 +000014
Éric Araujoa8132ec2010-12-16 03:53:53 +000015Command-line use
16----------------
17
18This module can work as a script (using :program:`python -m compileall`) to
19compile 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
57Public functions
58----------------
Georg Brandl8ec7f652007-08-15 14:28:01 +000059
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 Brandl8ec7f652007-08-15 14:28:01 +000075.. 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
82To force a recompile of all the :file:`.py` files in the :file:`Lib/`
83subdirectory 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.