6
6
from .errors import DistutilsFileError
7
7
8
8
9
+ def _newer (source , target ):
10
+ if not os .path .exists (target ):
11
+ return True
12
+
13
+ mtime1 = os .stat (source )[stat .ST_MTIME ]
14
+ mtime2 = os .stat (target )[stat .ST_MTIME ]
15
+
16
+ return mtime1 > mtime2
17
+
18
+
9
19
def newer (source , target ):
10
20
"""
11
21
Is source modified more recently than target.
@@ -18,13 +28,7 @@ def newer(source, target):
18
28
if not os .path .exists (source ):
19
29
raise DistutilsFileError ("file '%s' does not exist" % os .path .abspath (source ))
20
30
21
- if not os .path .exists (target ):
22
- return True
23
-
24
- mtime1 = os .stat (source )[stat .ST_MTIME ]
25
- mtime2 = os .stat (target )[stat .ST_MTIME ]
26
-
27
- return mtime1 > mtime2
31
+ return _newer (source , target )
28
32
29
33
30
34
def newer_pairwise (sources , targets ):
@@ -66,26 +70,12 @@ def newer_group(sources, target, missing='error'):
66
70
commands that wouldn't work because inputs are missing, but
67
71
that doesn't matter because dry-run won't run the commands.
68
72
"""
69
- # If the target doesn't even exist, then it's definitely out-of-date.
70
- if not os .path .exists (target ):
71
- return True
72
73
73
- # If *any* source file
74
- # is more recent than 'target', then 'target' is out-of-date and
75
- # we can immediately return True. If the loop completes, then
76
- # 'target' is up-to-date.
77
- target_mtime = os .stat (target )[stat .ST_MTIME ]
78
- for source in sources :
79
- if not os .path .exists (source ):
80
- if missing == 'error' : # blow up when we stat() the file
81
- pass
82
- elif missing == 'ignore' : # missing source dropped from
83
- continue # target's dependency list
84
- elif missing == 'newer' : # missing source means target is
85
- return True # out-of-date
86
-
87
- source_mtime = os .stat (source )[stat .ST_MTIME ]
88
- if source_mtime > target_mtime :
89
- return True
90
- else :
91
- return False
74
+ def missing_as_newer (source ):
75
+ return missing == 'newer' and not os .path .exists (source )
76
+
77
+ ignored = os .path .exists if missing == 'ignore' else None
78
+ return any (
79
+ missing_as_newer (source ) or _newer (source , target )
80
+ for source in filter (ignored , sources )
81
+ )
0 commit comments