On this page
  1. compileall.compile_dir
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

compileall.compile_dir

Up: compileall | Next: compileall.compile_file
Rel: compileall.compile_file, compileall.compile_path
Ref: docs.python.org — compileall.compile_dir
Tags: #public #python3 #stdlib #compileall


Import

import compileall
from compileall import compile_dir

Signature & Overview

compileall.compile_dir(dir, maxlevels=None, 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.

Usage

import compileall
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    (Path(tmp) / "ok.py").write_text("x = 1\n", encoding="utf-8")
    assert compileall.compile_dir(tmp, quiet=1) is True

Gotchas

REPL Inspect

from compileall import compile_dir
help(compile_dir)

Linked from

Related notes