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
(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)
| 46 | quiet=quiet) |
| 47 | |
| 48 | def compile_dir(dir, maxlevels=None, ddir=None, force=False, |
| 49 | rx=None, quiet=0, legacy=False, optimize=-1, workers=1, |
| 50 | invalidation_mode=None, *, stripdir=None, |
| 51 | prependdir=None, limit_sl_dest=None, hardlink_dupes=False): |
| 52 | """Byte-compile all modules in the given directory tree. |
| 53 | |
| 54 | Arguments (only dir is required): |
| 55 | |
| 56 | dir: the directory to byte-compile |
| 57 | maxlevels: maximum recursion level (default `sys.getrecursionlimit()`) |
| 58 | ddir: the directory that will be prepended to the path to the |
| 59 | file as it is compiled into each byte-code file. |
| 60 | force: if True, force compilation, even if timestamps are up-to-date |
| 61 | quiet: full output with False or 0, errors only with 1, |
| 62 | no output with 2 |
| 63 | legacy: if True, produce legacy pyc paths instead of PEP 3147 paths |
| 64 | optimize: int or list of optimization levels or -1 for level of |
| 65 | the interpreter. Multiple levels leads to multiple compiled |
| 66 | files each with one optimization level. |
| 67 | workers: maximum number of parallel workers |
| 68 | invalidation_mode: how the up-to-dateness of the pyc will be checked |
| 69 | stripdir: part of path to left-strip from source file path |
| 70 | prependdir: path to prepend to beginning of original file path, applied |
| 71 | after stripdir |
| 72 | limit_sl_dest: ignore symlinks if they are pointing outside of |
| 73 | the defined path |
| 74 | hardlink_dupes: hardlink duplicated pyc files |
| 75 | """ |
| 76 | ProcessPoolExecutor = None |
| 77 | if ddir is not None and (stripdir is not None or prependdir is not None): |
| 78 | raise ValueError(("Destination dir (ddir) cannot be used " |
| 79 | "in combination with stripdir or prependdir")) |
| 80 | if ddir is not None: |
| 81 | stripdir = dir |
| 82 | prependdir = ddir |
| 83 | ddir = None |
| 84 | if workers < 0: |
| 85 | raise ValueError('workers must be greater or equal to 0') |
| 86 | if workers != 1: |
| 87 | # Check if this is a system where ProcessPoolExecutor can function. |
| 88 | from concurrent.futures.process import _check_system_limits |
| 89 | try: |
| 90 | _check_system_limits() |
| 91 | except NotImplementedError: |
| 92 | workers = 1 |
| 93 | else: |
| 94 | from concurrent.futures import ProcessPoolExecutor |
| 95 | if maxlevels is None: |
| 96 | maxlevels = sys.getrecursionlimit() |
| 97 | files = _walk_dir(dir, quiet=quiet, maxlevels=maxlevels) |
| 98 | success = True |
| 99 | if workers != 1 and ProcessPoolExecutor is not None: |
| 100 | import multiprocessing |
| 101 | if multiprocessing.get_start_method() == 'fork': |
| 102 | mp_context = multiprocessing.get_context('forkserver') |
| 103 | else: |
| 104 | mp_context = None |
| 105 | # If workers == 0, let ProcessPoolExecutor choose |
no test coverage detected
searching dependent graphs…