/Doc/library/compileall.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 62 lines · 41 code · 21 blank · 0 comment · 0 complexity · 7e6a23cffba4f9c08e5fd3e8b08cfb58 MD5 · raw file

  1. :mod:`compileall` --- Byte-compile Python libraries
  2. ===================================================
  3. .. module:: compileall
  4. :synopsis: Tools for byte-compiling all Python source files in a directory tree.
  5. This module provides some utility functions to support installing Python
  6. libraries. These functions compile Python source files in a directory tree,
  7. allowing users without permission to write to the libraries to take advantage of
  8. cached byte-code files.
  9. This module may also be used as a script (using the :option:`-m` Python flag) to
  10. compile Python sources. Directories to recursively traverse (passing
  11. :option:`-l` stops the recursive behavior) for sources are listed on the command
  12. line. If no arguments are given, the invocation is equivalent to ``-l
  13. sys.path``. Printing lists of the files compiled can be disabled with the
  14. :option:`-q` flag. In addition, the :option:`-x` option takes a regular
  15. expression argument. All files that match the expression will be skipped.
  16. .. function:: compile_dir(dir[, maxlevels[, ddir[, force[, rx[, quiet]]]]])
  17. Recursively descend the directory tree named by *dir*, compiling all :file:`.py`
  18. files along the way. The *maxlevels* parameter is used to limit the depth of
  19. the recursion; it defaults to ``10``. If *ddir* is given, it is used as the
  20. base path from which the filenames used in error messages will be generated.
  21. If *force* is true, modules are re-compiled even if the timestamps are up to
  22. date.
  23. If *rx* is given, it specifies a regular expression of file names to exclude
  24. from the search; that expression is searched for in the full path.
  25. If *quiet* is true, nothing is printed to the standard output in normal
  26. operation.
  27. .. function:: compile_path([skip_curdir[, maxlevels[, force]]])
  28. Byte-compile all the :file:`.py` files found along ``sys.path``. If
  29. *skip_curdir* is true (the default), the current directory is not included in
  30. the search. The *maxlevels* and *force* parameters default to ``0`` and are
  31. passed to the :func:`compile_dir` function.
  32. To force a recompile of all the :file:`.py` files in the :file:`Lib/`
  33. subdirectory and all its subdirectories::
  34. import compileall
  35. compileall.compile_dir('Lib/', force=True)
  36. # Perform same compilation, excluding files in .svn directories.
  37. import re
  38. compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True)
  39. .. seealso::
  40. Module :mod:`py_compile`
  41. Byte-compile a single source file.