Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions Lib/compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
stripdir = os.fspath(stripdir) if stripdir is not None else None
name = os.path.basename(fullname)

# Without a cache_tag, we can only create legacy .pyc files. None of our
# callers seem to expect this, so the best we can do is fail without raising
if not legacy and sys.implementation.cache_tag is None:
if not quiet:
print("No cache tag is available to generate .pyc path for",
repr(fullname))
return False

dfile = None

if ddir is not None:
Expand Down Expand Up @@ -223,7 +231,7 @@ def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
cfile = importlib.util.cache_from_source(fullname)
opt_cfiles[opt_level] = cfile

head, tail = name[:-3], name[-3:]
tail = name[-3:]
if tail == '.py':
if not force:
try:
Expand Down Expand Up @@ -318,7 +326,6 @@ def main():

parser = argparse.ArgumentParser(
description='Utilities to support installing Python libraries.',
color=True,
)
parser.add_argument('-l', action='store_const', const=0,
default=None, dest='maxlevels',
Expand All @@ -330,10 +337,10 @@ def main():
parser.add_argument('-f', action='store_true', dest='force',
help='force rebuild even if timestamps are up to date')
parser.add_argument('-q', action='count', dest='quiet', default=0,
help='output only error messages; -qq will suppress '
help='output only error messages; `-qq` will suppress '
'the error messages as well.')
parser.add_argument('-b', action='store_true', dest='legacy',
help='use legacy (pre-PEP3147) compiled file locations')
help='use legacy (pre-PEP 3147) compiled file locations')
parser.add_argument('-d', metavar='DESTDIR', dest='ddir', default=None,
help=('directory to prepend to file paths for use in '
'compile-time tracebacks and in runtime '
Expand All @@ -359,28 +366,28 @@ def main():
'of each file considered for compilation'))
parser.add_argument('-i', metavar='FILE', dest='flist',
help=('add all the files and directories listed in '
'FILE to the list considered for compilation; '
'if "-", names are read from stdin'))
'`FILE` to the list considered for compilation; '
'if `"-"`, names are read from `stdin`'))
parser.add_argument('compile_dest', metavar='FILE|DIR', nargs='*',
help=('zero or more file and directory names '
'to compile; if no arguments given, defaults '
'to the equivalent of -l sys.path'))
'to the equivalent of `-l` `sys.path`'))
parser.add_argument('-j', '--workers', default=1,
type=int, help='Run compileall concurrently')
invalidation_modes = [mode.name.lower().replace('_', '-')
for mode in py_compile.PycInvalidationMode]
parser.add_argument('--invalidation-mode',
choices=sorted(invalidation_modes),
help=('set .pyc invalidation mode; defaults to '
'"checked-hash" if the SOURCE_DATE_EPOCH '
help=('set `.pyc` invalidation mode; defaults to '
'`"checked-hash"` if the `SOURCE_DATE_EPOCH` '
'environment variable is set, and '
'"timestamp" otherwise.'))
'`"timestamp"` otherwise.'))
parser.add_argument('-o', action='append', type=int, dest='opt_levels',
help=('Optimization levels to run compilation with. '
'Default is -1 which uses the optimization level '
'of the Python interpreter itself (see -O).'))
'Default is `-1` which uses the optimization level '
'of the Python interpreter itself (see `-O`).'))
parser.add_argument('-e', metavar='DIR', dest='limit_sl_dest',
help='Ignore symlinks pointing outsite of the DIR')
help='Ignore symlinks pointing outsite of the `DIR`')
parser.add_argument('--hardlink-dupes', action='store_true',
dest='hardlink_dupes',
help='Hardlink duplicated pyc files')
Expand Down
45 changes: 12 additions & 33 deletions Lib/glob.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,6 @@ def _glob0(dirname, basename, dir_fd, dironly, include_hidden=False):
return [basename]
return []

_deprecated_function_message = (
"{name} is deprecated and will be removed in Python {remove}. Use "
"glob.glob and pass a directory to its root_dir argument instead."
)

def glob0(dirname, pattern):
import warnings
warnings._deprecated("glob.glob0", _deprecated_function_message, remove=(3, 15))
return _glob0(dirname, pattern, None, False)

def glob1(dirname, pattern):
import warnings
warnings._deprecated("glob.glob1", _deprecated_function_message, remove=(3, 15))
return _glob1(dirname, pattern, None, False)

# This helper function recursively yields relative pathnames inside a literal
# directory.

Expand Down Expand Up @@ -385,6 +370,12 @@ def concat_path(path, text):
"""
raise NotImplementedError

@staticmethod
def stringify_path(path):
"""Converts the path to a string object
"""
raise NotImplementedError

# High-level methods

def compile(self, pat, altsep=None):
Expand Down Expand Up @@ -493,8 +484,9 @@ def recursive_selector(self, part, parts):
select_next = self.selector(parts)

def select_recursive(path, exists=False):
match_pos = len(str(path))
if match is None or match(str(path), match_pos):
path_str = self.stringify_path(path)
match_pos = len(path_str)
if match is None or match(path_str, match_pos):
yield from select_next(path, exists)
stack = [path]
while stack:
Expand All @@ -516,7 +508,7 @@ def select_recursive_step(stack, match_pos):
pass

if is_dir or not dir_only:
entry_path_str = str(entry_path)
entry_path_str = self.stringify_path(entry_path)
if dir_only:
entry_path = self.concat_path(entry_path, self.sep)
if match is None or match(entry_path_str, match_pos):
Expand Down Expand Up @@ -556,19 +548,6 @@ def scandir(path):
entries = list(scandir_it)
return ((entry, entry.name, entry.path) for entry in entries)


class _PathGlobber(_GlobberBase):
"""Provides shell-style pattern matching and globbing for pathlib paths.
"""

@staticmethod
def lexists(path):
return path.info.exists(follow_symlinks=False)

@staticmethod
def scandir(path):
return ((child.info, child.name, child) for child in path.iterdir())

@staticmethod
def concat_path(path, text):
return path.with_segments(str(path) + text)
def stringify_path(path):
return path # Already a string.
Loading
Loading