12
12
- The .c files resulting from cythonizing pyx/d files
13
13
- 2to3 refactoring results (when run under python3)
14
14
15
- Tested on releases back to 0.7.0.
15
+ Tested on all released back to 0.7.0.
16
16
17
17
"""
18
- import argparse
19
- argparser = argparse .ArgumentParser (description = """
20
- 'Program description.
21
- """ .strip ())
22
-
23
- argparser .add_argument ('-f' , '--force-overwrite' ,
24
- default = False ,
25
- help = 'Setting this will overwrite any existing cache results for the current commit' ,
26
- action = 'store_true' )
27
- argparser .add_argument ('-d' , '--debug' ,
28
- default = False ,
29
- help = 'Report cache hits/misses' ,
30
- action = 'store_true' )
31
-
32
- args = argparser .parse_args ()
33
-
34
- #print args.accumulate(args.integers)
35
-
36
18
shim = """
37
19
import os
38
20
import sys
39
21
import shutil
40
22
import warnings
41
- import re
42
- """
43
-
44
- shim += ("BC_FORCE_OVERWRITE = %s\n " % args .force_overwrite )
45
- shim += ("BC_DEBUG = %s\n " % args .debug )
46
23
47
- shim += """
48
24
try:
49
25
if not ("develop" in sys.argv) and not ("install" in sys.argv):
50
26
1/0
58
34
if os.path.isdir(BUILD_CACHE_DIR):
59
35
print("--------------------------------------------------------")
60
36
print("BUILD CACHE ACTIVATED (V2). be careful, this is experimental.")
61
- print("BUILD_CACHE_DIR: " + BUILD_CACHE_DIR )
62
37
print("--------------------------------------------------------")
63
38
else:
64
39
BUILD_CACHE_DIR = None
90
65
h = sha1(open(f,"rb").read()).hexdigest()
91
66
except IOError:
92
67
to_process[h] = f
93
- if h in orig_hashes and not BC_FORCE_OVERWRITE :
68
+ if h in orig_hashes:
94
69
src = os.path.join(BUILD_CACHE_DIR,orig_hashes[h])
95
- if BC_DEBUG:
96
- print("2to3 cache hit %s,%s" % (f,h))
70
+ # print("cache hit %s,%s" % (f,h))
97
71
shutil.copyfile(src,f)
98
72
elif h not in post_hashes:
99
73
100
74
# we're not in a dev dir with already processed files
101
- if BC_DEBUG:
102
- print("2to3 cache miss %s,%s" % (f,h))
103
- print("2to3 will process " + f)
75
+ # print("cache miss %s,%s" % (f,h))
76
+ # print("will process " + f)
104
77
to_process[h] = f
105
78
106
79
avail_fixes = set(refactor.get_fixers_from_package("lib2to3.fixes"))
107
80
avail_fixes.discard('lib2to3.fixes.fix_next')
108
81
t=refactor.RefactoringTool(avail_fixes)
109
- print("Starting 2to3 refactoring...")
110
- for f in to_process.values():
111
- if BC_DEBUG:
112
- print("2to3 on %s" % f)
113
- try:
114
- t.refactor([f],True)
115
- post_h = sha1(open(f, "rb").read()).hexdigest()
116
- cached_fname = f + "-" + post_h + "-" + pyver
117
- if BC_DEBUG:
118
- print("cache put %s,%s in %s" % (f, h, cached_fname))
119
- shutil.copyfile(f, os.path.join(BUILD_CACHE_DIR, cached_fname))
120
-
121
- except:
122
- pass
82
+ t.refactor(to_process.values(),True)
123
83
print("2to3 done refactoring.")
84
+ for orig_h in to_process:
85
+ f = to_process[orig_h]
86
+ post_h = sha1(open(f,"rb").read()).hexdigest()
87
+ cached_fname = orig_h + "-" + post_h + "-" + pyver
88
+ # print("cache put %s,%s in %s" % (f,h,cached_fname))
89
+ shutil.copyfile(f,os.path.join(BUILD_CACHE_DIR,cached_fname))
90
+
91
+ except:
92
+ BUILD_CACHE_DIR = None
124
93
125
- except Exception as e:
126
- print( "Exception: " + str(e))
127
- BUILD_CACHE_DIR = None
94
+ print("BUILD_CACHE_DIR: " + str(BUILD_CACHE_DIR) )
128
95
129
96
class CompilationCacheMixin(object):
130
97
def __init__(self, *args, **kwds):
@@ -135,10 +102,9 @@ def __init__(self, *args, **kwds):
135
102
136
103
def _copy_from_cache(self, hash, target):
137
104
src = os.path.join(self.cache_dir, hash)
138
- if os.path.exists(src) and not BC_FORCE_OVERWRITE:
139
- if BC_DEBUG:
140
- print("Cache HIT: asked to copy file %s in %s" %
141
- (src,os.path.abspath(target)))
105
+ if os.path.exists(src):
106
+ # print("Cache HIT: asked to copy file %s in %s" %
107
+ # (src,os.path.abspath(target)))
142
108
s = "."
143
109
for d in target.split(os.path.sep)[:-1]:
144
110
s = os.path.join(s, d)
@@ -152,8 +118,7 @@ def _copy_from_cache(self, hash, target):
152
118
153
119
def _put_to_cache(self, hash, src):
154
120
target = os.path.join(self.cache_dir, hash)
155
- if BC_DEBUG:
156
- print( "Cache miss: asked to copy file from %s to %s" % (src,target))
121
+ # print( "Cache miss: asked to copy file from %s to %s" % (src,target))
157
122
s = "."
158
123
for d in target.split(os.path.sep)[:-1]:
159
124
s = os.path.join(s, d)
@@ -298,7 +263,7 @@ def main():
298
263
SEP = "\n setup("
299
264
before ,after = s .split (SEP )
300
265
with open (opj (opd (__file__ ),".." ,"setup.py" ),"wb" ) as f :
301
- f .write (( before + shim + SEP + after ). encode ( 'ascii' ) )
266
+ f .write (before + shim + SEP + after )
302
267
print ("""
303
268
setup.py was rewritten to use a build cache.
304
269
Make sure you've put the following in your .bashrc:
@@ -317,6 +282,7 @@ def main():
317
282
318
283
""" )
319
284
285
+
320
286
if __name__ == '__main__' :
321
287
import sys
322
288
sys .exit (main ())
0 commit comments