2007-08-15 11:28:22 -03:00
|
|
|
:mod:`compileall` --- Byte-compile Python libraries
|
|
|
|
===================================================
|
|
|
|
|
|
|
|
.. module:: compileall
|
|
|
|
:synopsis: Tools for byte-compiling all Python source files in a directory tree.
|
|
|
|
|
|
|
|
|
|
|
|
This module provides some utility functions to support installing Python
|
|
|
|
libraries. These functions compile Python source files in a directory tree,
|
|
|
|
allowing users without permission to write to the libraries to take advantage of
|
|
|
|
cached byte-code files.
|
|
|
|
|
Merged revisions 66457-66459,66465-66468,66483-66485,66487-66491 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r66457 | antoine.pitrou | 2008-09-13 15:30:30 -0500 (Sat, 13 Sep 2008) | 5 lines
Issue #3850: Misc/find_recursionlimit.py was broken.
Reviewed by A.M. Kuchling.
........
r66458 | benjamin.peterson | 2008-09-13 17:54:43 -0500 (Sat, 13 Sep 2008) | 1 line
fix a name issue; note all doc files should be encoded in utf8
........
r66459 | benjamin.peterson | 2008-09-14 11:02:22 -0500 (Sun, 14 Sep 2008) | 1 line
clarify that radix for int is not 'guessed'
........
r66465 | skip.montanaro | 2008-09-14 21:03:05 -0500 (Sun, 14 Sep 2008) | 3 lines
Review usage. Fix a mistake in the new-style class definition. Add a
couple new definitions (CPython and virtual machine).
........
r66466 | skip.montanaro | 2008-09-14 21:19:53 -0500 (Sun, 14 Sep 2008) | 2 lines
Pick up a few more definitions from the glossary on the wiki.
........
r66467 | benjamin.peterson | 2008-09-14 21:53:23 -0500 (Sun, 14 Sep 2008) | 1 line
mention that object.__init__ no longer takes arbitrary args and kwargs
........
r66468 | andrew.kuchling | 2008-09-15 08:08:32 -0500 (Mon, 15 Sep 2008) | 1 line
Rewrite item a bit
........
r66483 | georg.brandl | 2008-09-16 05:17:45 -0500 (Tue, 16 Sep 2008) | 2 lines
Fix typo.
........
r66484 | benjamin.peterson | 2008-09-16 16:20:28 -0500 (Tue, 16 Sep 2008) | 2 lines
be less wordy
........
r66485 | georg.brandl | 2008-09-17 03:45:54 -0500 (Wed, 17 Sep 2008) | 2 lines
#3888: add some deprecated modules in whatsnew.
........
r66487 | skip.montanaro | 2008-09-17 06:50:36 -0500 (Wed, 17 Sep 2008) | 2 lines
usage
........
r66488 | andrew.kuchling | 2008-09-17 07:57:04 -0500 (Wed, 17 Sep 2008) | 1 line
Markup fixes
........
r66489 | andrew.kuchling | 2008-09-17 07:58:22 -0500 (Wed, 17 Sep 2008) | 2 lines
Remove comment about improvement: pystone is about the same, and
the improvements seem to be difficult to quantify
........
r66490 | andrew.kuchling | 2008-09-17 08:04:53 -0500 (Wed, 17 Sep 2008) | 1 line
Note sqlite3 version; move item
........
r66491 | benjamin.peterson | 2008-09-17 16:54:56 -0500 (Wed, 17 Sep 2008) | 1 line
document compileall command flags
........
2008-09-17 19:25:09 -03:00
|
|
|
This module may also be used as a script (using the :option:`-m` Python flag) to
|
|
|
|
compile Python sources. Directories to recursively traverse (passing
|
|
|
|
:option:`-l` stops the recursive behavior) for sources are listed on the command
|
|
|
|
line. If no arguments are given, the invocation is equivalent to ``-l
|
|
|
|
sys.path``. Printing lists of the files compiled can be disabled with the
|
|
|
|
:option:`-q` flag. In addition, the :option:`-x` option takes a regular
|
|
|
|
expression argument. All files that match the expression will be skipped.
|
2010-04-16 21:19:56 -03:00
|
|
|
The :option:`-b` flag may be given to write legacy ``.pyc`` file path names,
|
|
|
|
otherwise :pep:`3147` style byte-compiled path names are written.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2010-04-16 21:19:56 -03:00
|
|
|
.. function:: compile_dir(dir, maxlevels=10, ddir=None, force=False, rx=None, quiet=False, legacy=False)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Recursively descend the directory tree named by *dir*, compiling all :file:`.py`
|
|
|
|
files along the way. The *maxlevels* parameter is used to limit the depth of
|
|
|
|
the recursion; it defaults to ``10``. If *ddir* is given, it is used as the
|
|
|
|
base path from which the filenames used in error messages will be generated.
|
|
|
|
If *force* is true, modules are re-compiled even if the timestamps are up to
|
|
|
|
date.
|
|
|
|
|
|
|
|
If *rx* is given, it specifies a regular expression of file names to exclude
|
|
|
|
from the search; that expression is searched for in the full path.
|
|
|
|
|
|
|
|
If *quiet* is true, nothing is printed to the standard output in normal
|
|
|
|
operation.
|
|
|
|
|
2010-04-16 21:19:56 -03:00
|
|
|
If *legacy* is true, old-style ``.pyc`` file path names are written,
|
|
|
|
otherwise (the default), :pep:`3147` style path names are written.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-04-16 21:19:56 -03:00
|
|
|
|
|
|
|
.. function:: compile_path(skip_curdir=True, maxlevels=0, force=False, legacy=False)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Byte-compile all the :file:`.py` files found along ``sys.path``. If
|
|
|
|
*skip_curdir* is true (the default), the current directory is not included in
|
2010-04-16 21:19:56 -03:00
|
|
|
the search. The *maxlevels* parameter defaults to ``0``, and the *force*
|
|
|
|
and *legacy* parameters default to ``False``. All are
|
2007-08-15 11:28:22 -03:00
|
|
|
passed to the :func:`compile_dir` function.
|
|
|
|
|
|
|
|
To force a recompile of all the :file:`.py` files in the :file:`Lib/`
|
|
|
|
subdirectory and all its subdirectories::
|
|
|
|
|
|
|
|
import compileall
|
|
|
|
|
|
|
|
compileall.compile_dir('Lib/', force=True)
|
|
|
|
|
|
|
|
# Perform same compilation, excluding files in .svn directories.
|
|
|
|
import re
|
|
|
|
compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True)
|
|
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
Module :mod:`py_compile`
|
|
|
|
Byte-compile a single source file.
|
|
|
|
|