Skip to content

Commit 725b6a9

Browse files
author
y-p
committed
BLD: use_build_cache.py - fix 2to3 caching and messages
1 parent 3880b2a commit 725b6a9

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

ci/before_install.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,8 @@ if $PLEASE_TRAVIS_FASTER ; then
2020
unzip $ZIP_FLAGS /tmp/_"$CYTHON_HASH.zip" -d "$BUILD_CACHE_DIR";
2121
rm -f /tmp/_"$CYTHON_HASH.zip"
2222
# copy cythonized c files over
23-
cp -R "$BUILD_CACHE_DIR"/pandas/* pandas/
24-
# mkdir build/
25-
# ls -l build
26-
# mkdir build/temp.linux-x86-$TRAVIS_PYTHON_VERSION
27-
# mkdir build/temp.linux-x86-$TRAVIS_PYTHON_VERSION/pandas/
28-
# touch build/temp.linux-x86-$TRAVIS_PYTHON_VERSION/pandas/lib.o
29-
23+
cp -R "$BUILD_CACHE_DIR"/pandas/*.c pandas/
24+
cp -R "$BUILD_CACHE_DIR"/pandas/src/*.c pandas/src/
3025
fi;
3126
echo "VENV_FILE_AVAILABLE=$VENV_FILE_AVAILABLE"
3227
if $VENV_FILE_AVAILABLE ; then

scripts/use_build_cache.py

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,28 @@ class Foo(object):
7878
import shutil
7979
import multiprocessing
8080
pyver = "%d.%d" % (sys.version_info[:2])
81-
files = ["pandas"]
81+
fileq = ["pandas"]
8282
to_process = dict()
83-
orig_hashes= dict((f.split("-")[0],f) for f in os.listdir(BUILD_CACHE_DIR)
84-
if "-" in f and f.endswith(pyver))
85-
post_hashes= dict((f.split("-")[1],f) for f in os.listdir(BUILD_CACHE_DIR)
86-
if "-" in f and f.endswith(pyver))
8783
88-
while files:
89-
f = files.pop()
84+
# retrieve the hashes existing in the cache
85+
orig_hashes=dict()
86+
post_hashes=dict()
87+
for path,dirs,files in os.walk(os.path.join(BUILD_CACHE_DIR,'pandas')):
88+
for f in files:
89+
s=f.split(".py-")[-1]
90+
try:
91+
prev_h,post_h,ver = s.split('-')
92+
if ver == pyver:
93+
orig_hashes[prev_h] = os.path.join(path,f)
94+
post_hashes[post_h] = os.path.join(path,f)
95+
except:
96+
pass
97+
98+
while fileq:
99+
f = fileq.pop()
90100
91101
if os.path.isdir(f):
92-
files.extend([os.path.join(f,x) for x in os.listdir(f)])
102+
fileq.extend([os.path.join(f,x) for x in os.listdir(f)])
93103
else:
94104
if not f.endswith(".py"):
95105
continue
@@ -98,39 +108,54 @@ class Foo(object):
98108
h = sha1(open(f,"rb").read()).hexdigest()
99109
except IOError:
100110
to_process[h] = f
101-
if h in orig_hashes and not BC_FORCE_OVERWRITE:
102-
src = os.path.join(BUILD_CACHE_DIR,orig_hashes[h])
103-
if BC_DEBUG:
104-
print("2to3 cache hit %s,%s" % (f,h))
105-
shutil.copyfile(src,f)
106-
elif h not in post_hashes:
107-
108-
# we're not in a dev dir with already processed files
109-
if BC_DEBUG:
110-
print("2to3 cache miss %s,%s" % (f,h))
111-
print("2to3 will process " + f)
112-
to_process[h] = f
111+
else:
112+
if h in orig_hashes and not BC_FORCE_OVERWRITE:
113+
src = orig_hashes[h]
114+
if BC_DEBUG:
115+
print("2to3 cache hit %s,%s" % (f,h))
116+
shutil.copyfile(src,f)
117+
elif h not in post_hashes:
118+
# we're not in a dev dir with already processed files
119+
if BC_DEBUG:
120+
print("2to3 cache miss (will process) %s,%s" % (f,h))
121+
to_process[h] = f
113122
114123
avail_fixes = set(refactor.get_fixers_from_package("lib2to3.fixes"))
115124
avail_fixes.discard('lib2to3.fixes.fix_next')
116125
t=refactor.RefactoringTool(avail_fixes)
117-
print("Starting 2to3 refactoring...")
118-
for f in to_process.values():
119-
if BC_DEBUG:
120-
print("2to3 on %s" % f)
121-
try:
122-
t.refactor([f],True)
123-
post_h = sha1(open(f, "rb").read()).hexdigest()
124-
cached_fname = f + "-" + post_h + "-" + pyver
126+
if to_process:
127+
print("Starting 2to3 refactoring...")
128+
for orig_h,f in to_process.items():
125129
if BC_DEBUG:
126-
print("cache put %s,%s in %s" % (f, h, cached_fname))
127-
shutil.copyfile(f, os.path.join(BUILD_CACHE_DIR, cached_fname))
130+
print("2to3 on %s" % f)
131+
try:
132+
t.refactor([f],True)
133+
post_h = sha1(open(f, "rb").read()).hexdigest()
134+
cached_fname = f + '-' + orig_h + '-' + post_h + '-' + pyver
135+
path = os.path.join(BUILD_CACHE_DIR, cached_fname)
136+
pathdir =os.path.dirname(path)
137+
if BC_DEBUG:
138+
print("cache put %s in %s" % (f, path))
139+
try:
140+
os.makedirs(pathdir)
141+
except OSError as exc:
142+
import errno
143+
if exc.errno == errno.EEXIST and os.path.isdir(pathdir):
144+
pass
145+
else:
146+
raise
128147
129-
except:
130-
pass
131-
print("2to3 done refactoring.")
148+
shutil.copyfile(f, path)
149+
150+
except Exception as e:
151+
print("While processing %s 2to3 raised: %s" % (f,str(e)))
152+
153+
pass
154+
print("2to3 done refactoring.")
132155
133156
except Exception as e:
157+
if not isinstance(e,ZeroDivisionError):
158+
print( "Exception: " + str(e))
134159
BUILD_CACHE_DIR = None
135160
136161
class CompilationCacheMixin(object):

0 commit comments

Comments
 (0)