-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move dep_util to _modified and mark dep_util as deprecated.
- Loading branch information
Showing
11 changed files
with
89 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"""Timestamp comparison of files and groups of files.""" | ||
|
||
import os.path | ||
|
||
from .errors import DistutilsFileError | ||
from .py39compat import zip_strict | ||
from ._functools import splat | ||
|
||
|
||
def _newer(source, target): | ||
return not os.path.exists(target) or ( | ||
os.path.getmtime(source) > os.path.getmtime(target) | ||
) | ||
|
||
|
||
def newer(source, target): | ||
""" | ||
Is source modified more recently than target. | ||
Returns True if 'source' is modified more recently than | ||
'target' or if 'target' does not exist. | ||
Raises DistutilsFileError if 'source' does not exist. | ||
""" | ||
if not os.path.exists(source): | ||
raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) | ||
|
||
return _newer(source, target) | ||
|
||
|
||
def newer_pairwise(sources, targets): | ||
""" | ||
Filter filenames where sources are newer than targets. | ||
Walk two filename iterables in parallel, testing if each source is newer | ||
than its corresponding target. Returns a pair of lists (sources, | ||
targets) where source is newer than target, according to the semantics | ||
of 'newer()'. | ||
""" | ||
newer_pairs = filter(splat(newer), zip_strict(sources, targets)) | ||
return tuple(map(list, zip(*newer_pairs))) | ||
|
||
|
||
def newer_group(sources, target, missing='error'): | ||
""" | ||
Is target out-of-date with respect to any file in sources. | ||
Return True if 'target' is out-of-date with respect to any file | ||
listed in 'sources'. In other words, if 'target' exists and is newer | ||
than every file in 'sources', return False; otherwise return True. | ||
``missing`` controls how to handle a missing source file: | ||
- error (default): allow the ``stat()`` call to fail. | ||
- ignore: silently disregard any missing source files. | ||
- newer: treat missing source files as "target out of date". This | ||
mode is handy in "dry-run" mode: it will pretend to carry out | ||
commands that wouldn't work because inputs are missing, but | ||
that doesn't matter because dry-run won't run the commands. | ||
""" | ||
|
||
def missing_as_newer(source): | ||
return missing == 'newer' and not os.path.exists(source) | ||
|
||
ignored = os.path.exists if missing == 'ignore' else None | ||
return any( | ||
missing_as_newer(source) or _newer(source, target) | ||
for source in filter(ignored, sources) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,14 @@ | ||
"""Timestamp comparison of files and groups of files.""" | ||
import warnings | ||
|
||
import os.path | ||
from . import _modified | ||
|
||
from .errors import DistutilsFileError | ||
from .py39compat import zip_strict | ||
from ._functools import splat | ||
|
||
|
||
def _newer(source, target): | ||
return not os.path.exists(target) or ( | ||
os.path.getmtime(source) > os.path.getmtime(target) | ||
) | ||
|
||
|
||
def newer(source, target): | ||
""" | ||
Is source modified more recently than target. | ||
Returns True if 'source' is modified more recently than | ||
'target' or if 'target' does not exist. | ||
Raises DistutilsFileError if 'source' does not exist. | ||
""" | ||
if not os.path.exists(source): | ||
raise DistutilsFileError("file '%s' does not exist" % os.path.abspath(source)) | ||
|
||
return _newer(source, target) | ||
|
||
|
||
def newer_pairwise(sources, targets): | ||
""" | ||
Filter filenames where sources are newer than targets. | ||
Walk two filename iterables in parallel, testing if each source is newer | ||
than its corresponding target. Returns a pair of lists (sources, | ||
targets) where source is newer than target, according to the semantics | ||
of 'newer()'. | ||
""" | ||
newer_pairs = filter(splat(newer), zip_strict(sources, targets)) | ||
return tuple(map(list, zip(*newer_pairs))) | ||
|
||
|
||
def newer_group(sources, target, missing='error'): | ||
""" | ||
Is target out-of-date with respect to any file in sources. | ||
Return True if 'target' is out-of-date with respect to any file | ||
listed in 'sources'. In other words, if 'target' exists and is newer | ||
than every file in 'sources', return False; otherwise return True. | ||
``missing`` controls how to handle a missing source file: | ||
- error (default): allow the ``stat()`` call to fail. | ||
- ignore: silently disregard any missing source files. | ||
- newer: treat missing source files as "target out of date". This | ||
mode is handy in "dry-run" mode: it will pretend to carry out | ||
commands that wouldn't work because inputs are missing, but | ||
that doesn't matter because dry-run won't run the commands. | ||
""" | ||
|
||
def missing_as_newer(source): | ||
return missing == 'newer' and not os.path.exists(source) | ||
|
||
ignored = os.path.exists if missing == 'ignore' else None | ||
return any( | ||
missing_as_newer(source) or _newer(source, target) | ||
for source in filter(ignored, sources) | ||
def __getattr__(name): | ||
if name not in ['newer', 'newer_group', 'newer_pairwise']: | ||
raise AttributeError(name) | ||
warnings.warn( | ||
"dep_util is Deprecated. Use functions from setuptools instead.", | ||
DeprecationWarning, | ||
stacklevel=2, | ||
) | ||
return getattr(_modified, name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
distutils/tests/test_dep_util.py → distutils/tests/test_modified.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters