PyDocs

Nav

Python Language Services

compile_dir

compileall

function (source) not WASI
  • compile_dir(dir, maxlevels=sys.getrecursionlimit(), ddir=None, force=False, rx=None, quiet=0, legacy=False, optimize=-1, workers=1, invalidation_mode=None, *, stripdir=None, prependdir=None, limit_sl_dest=None, hardlink_dupes=False)
Byte-compile all modules in the given directory tree.

Arguments (only dir is required):

dir:       the directory to byte-compile
maxlevels: maximum recursion level (default `sys.getrecursionlimit()`)
ddir:      the directory that will be prepended to the path to the
           file as it is compiled into each byte-code file.
force:     if True, force compilation, even if timestamps are up-to-date
quiet:     full output with False or 0, errors only with 1,
           no output with 2
legacy:    if True, produce legacy pyc paths instead of PEP 3147 paths
optimize:  int or list of optimization levels or -1 for level of
           the interpreter. Multiple levels leads to multiple compiled
           files each with one optimization level.
workers:   maximum number of parallel workers
invalidation_mode: how the up-to-dateness of the pyc will be checked
stripdir:  part of path to left-strip from source file path
prependdir: path to prepend to beginning of original file path, applied
           after stripdir
limit_sl_dest: ignore symlinks if they are pointing outside of
               the defined path
hardlink_dupes: hardlink duplicated pyc files
Changed in 3.2, 3.5, 3.6, 3.7, 3.7.2, 3.8, 3.9
  • 3.2: Added the legacy and optimize parameter.
  • 3.5: Added the workers parameter.
  • 3.5: quiet parameter was changed to a multilevel value.
  • 3.5: The legacy parameter only writes out .pyc files, not .pyo files no matter what the value of optimize is.
  • 3.6: Accepts a path-like object.
  • 3.7: The invalidation_mode parameter was added.
  • 3.7.2: The invalidation_mode parameter’s default value is updated to None.
  • 3.8: Setting workers to 0 now chooses the optimal number of cores.
  • 3.9: Added stripdir, prependdir, limit_sl_dest and hardlink_dupes arguments. Default value of maxlevels was changed from 10 to sys.getrecursionlimit()
0 Examples
No examples for compileall/compile_dir.
See Also
No see-alsos for compileall/compile_dir
0 Notes
No notes for compile_dir