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 all released back to 0.7.0.
15
+ Tested on releases 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
+
18
36
shim = """
19
37
import os
20
38
import sys
21
39
import shutil
22
40
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 )
23
46
47
+ shim += """
24
48
try:
25
49
if not ("develop" in sys.argv) and not ("install" in sys.argv):
26
50
1/0
34
58
if os.path.isdir(BUILD_CACHE_DIR):
35
59
print("--------------------------------------------------------")
36
60
print("BUILD CACHE ACTIVATED (V2). be careful, this is experimental.")
61
+ print("BUILD_CACHE_DIR: " + BUILD_CACHE_DIR )
37
62
print("--------------------------------------------------------")
38
63
else:
39
64
BUILD_CACHE_DIR = None
65
90
h = sha1(open(f,"rb").read()).hexdigest()
66
91
except IOError:
67
92
to_process[h] = f
68
- if h in orig_hashes:
93
+ if h in orig_hashes and not BC_FORCE_OVERWRITE :
69
94
src = os.path.join(BUILD_CACHE_DIR,orig_hashes[h])
70
- # print("cache hit %s,%s" % (f,h))
95
+ if BC_DEBUG:
96
+ print("2to3 cache hit %s,%s" % (f,h))
71
97
shutil.copyfile(src,f)
72
98
elif h not in post_hashes:
73
99
74
100
# we're not in a dev dir with already processed files
75
- # print("cache miss %s,%s" % (f,h))
76
- # print("will process " + f)
101
+ if BC_DEBUG:
102
+ print("2to3 cache miss %s,%s" % (f,h))
103
+ print("2to3 will process " + f)
77
104
to_process[h] = f
78
105
79
106
avail_fixes = set(refactor.get_fixers_from_package("lib2to3.fixes"))
80
107
avail_fixes.discard('lib2to3.fixes.fix_next')
81
108
t=refactor.RefactoringTool(avail_fixes)
82
- t.refactor(to_process.values(),True)
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))
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))
90
120
91
- except:
92
- BUILD_CACHE_DIR = None
121
+ except:
122
+ pass
123
+ print("2to3 done refactoring.")
93
124
94
- print("BUILD_CACHE_DIR: " + str(BUILD_CACHE_DIR) )
125
+ except Exception as e:
126
+ print( "Exception: " + str(e))
127
+ BUILD_CACHE_DIR = None
95
128
96
129
class CompilationCacheMixin(object):
97
130
def __init__(self, *args, **kwds):
@@ -102,9 +135,10 @@ def __init__(self, *args, **kwds):
102
135
103
136
def _copy_from_cache(self, hash, target):
104
137
src = os.path.join(self.cache_dir, hash)
105
- if os.path.exists(src):
106
- # print("Cache HIT: asked to copy file %s in %s" %
107
- # (src,os.path.abspath(target)))
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)))
108
142
s = "."
109
143
for d in target.split(os.path.sep)[:-1]:
110
144
s = os.path.join(s, d)
@@ -118,7 +152,8 @@ def _copy_from_cache(self, hash, target):
118
152
119
153
def _put_to_cache(self, hash, src):
120
154
target = os.path.join(self.cache_dir, hash)
121
- # print( "Cache miss: asked to copy file from %s to %s" % (src,target))
155
+ if BC_DEBUG:
156
+ print( "Cache miss: asked to copy file from %s to %s" % (src,target))
122
157
s = "."
123
158
for d in target.split(os.path.sep)[:-1]:
124
159
s = os.path.join(s, d)
@@ -263,7 +298,7 @@ def main():
263
298
SEP = "\n setup("
264
299
before ,after = s .split (SEP )
265
300
with open (opj (opd (__file__ ),".." ,"setup.py" ),"wb" ) as f :
266
- f .write (before + shim + SEP + after )
301
+ f .write (( before + shim + SEP + after ). encode ( 'ascii' ) )
267
302
print ("""
268
303
setup.py was rewritten to use a build cache.
269
304
Make sure you've put the following in your .bashrc:
@@ -282,7 +317,6 @@ def main():
282
317
283
318
""" )
284
319
285
-
286
320
if __name__ == '__main__' :
287
321
import sys
288
322
sys .exit (main ())
0 commit comments