bpo-39769: Fix compileall ddir for subpkgs. (GH-18676)

Fix compileall.compile_dir() ddir= behavior on sub-packages.

Fixes compileall.compile_dir's ddir parameter and compileall command
line flag `-d` to no longer write the wrong pathname to the generated
pyc file for submodules beneath the root of the directory tree being
compiled.  This fixes a regression introduced with Python 3.5.

Also marks the _new_ in 3.9 from PR #16012 parameters to compile_dir as keyword only (as that is the only way they will be used) and fixes an omission of them in one place from the docs.
This commit is contained in:
Gregory P. Smith 2020-02-28 17:28:37 -08:00 committed by GitHub
parent 03153dd145
commit 02673352b5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 67 additions and 4 deletions

View file

@ -46,7 +46,7 @@ def _walk_dir(dir, maxlevels, quiet=0):
def compile_dir(dir, maxlevels=None, ddir=None, force=False,
rx=None, quiet=0, legacy=False, optimize=-1, workers=1,
invalidation_mode=None, stripdir=None,
invalidation_mode=None, *, stripdir=None,
prependdir=None, limit_sl_dest=None):
"""Byte-compile all modules in the given directory tree.
@ -72,6 +72,13 @@ def compile_dir(dir, maxlevels=None, ddir=None, force=False,
the defined path
"""
ProcessPoolExecutor = None
if ddir is not None and (stripdir is not None or prependdir is not None):
raise ValueError(("Destination dir (ddir) cannot be used "
"in combination with stripdir or prependdir"))
if ddir is not None:
stripdir = dir
prependdir = ddir
ddir = None
if workers < 0:
raise ValueError('workers must be greater or equal to 0')
if workers != 1:
@ -111,7 +118,7 @@ def compile_dir(dir, maxlevels=None, ddir=None, force=False,
def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
legacy=False, optimize=-1,
invalidation_mode=None, stripdir=None, prependdir=None,
invalidation_mode=None, *, stripdir=None, prependdir=None,
limit_sl_dest=None):
"""Byte-compile one file.