1. Larry Hastings
  2. python-clinic

Source

python-clinic / Doc / library / compileall.rst

:mod:`compileall` --- Byte-compile Python libraries

This module provides some utility functions to support installing Python libraries. These functions compile Python source files in a directory tree. This module can be used to create the cached byte-code files at library installation time, which makes them available for use even by users who don't have write permission to the library directories.

Command-line use

This module can work as a script (using :program:`python -m compileall`) to compile Python sources.

There is no command-line option to control the optimization level used by the :func:`compile` function, because the Python interpreter itself already provides the option: :program:`python -O -m compileall`.

Public functions

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(r'[/\\][.]svn'), force=True)