Skip to content

Commit 449e824

Browse files
nparleyjreback
authored andcommitted
Cython cache diff compare
As talked about in #13425 with @gfyoung and @jreback this PR does cython caching by comparing the pyx files and not relying on the git history. Author: Neil Parley <[email protected]> Closes #13526 from nparley/pyx-diff and squashes the following commits: 8b4ad0b [Neil Parley] Remove test commit 2dc2ce2 [Neil Parley] Merge branch 'upstream' into pyx-diff 81cbb7b [Neil Parley] Reset pyx changes 79fe0f0 [Neil Parley] Remove do_not_merge dca6e61 [Neil Parley] Test commit 30bd9da [Neil Parley] Check for the case where less cython file has been deleted aaf4dd2 [Neil Parley] Merge branch 'upstream' into pyx-diff 6cc3d6e [Neil Parley] Diff python pyx files as a test if they have changed
1 parent ffb582c commit 449e824

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

ci/prep_cython_cache.sh

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,73 @@
11
#!/bin/bash
22

33
ls "$HOME/.cache/"
4+
5+
PYX_CACHE_DIR="$HOME/.cache/pyxfiles"
6+
pyx_file_list=`find ${TRAVIS_BUILD_DIR} -name "*.pyx"`
7+
pyx_cache_file_list=`find ${PYX_CACHE_DIR} -name "*.pyx"`
8+
49
CACHE_File="$HOME/.cache/cython_files.tar"
510

11+
# Clear the cython cache 0 = NO, 1 = YES
612
clear_cache=0
13+
14+
pyx_files=`echo "$pyx_file_list" | wc -l`
15+
pyx_cache_files=`echo "$pyx_cache_file_list" | wc -l`
16+
17+
if [[ pyx_files -ne pyx_cache_files ]]
18+
then
19+
echo "Different number of pyx files"
20+
clear_cache=1
21+
fi
22+
723
home_dir=$(pwd)
824

9-
if [ -f "$CACHE_File" ] && [ "$USE_CACHE" ]; then
25+
if [ -f "$CACHE_File" ] && [ "$USE_CACHE" ] && [ -d "$PYX_CACHE_DIR" ]; then
26+
27+
echo "Cache available - checking pyx diff"
28+
29+
for i in ${pyx_file_list}
30+
do
31+
diff=`diff -u $i $PYX_CACHE_DIR${i}`
32+
if [[ $? -eq 2 ]]
33+
then
34+
echo "${i##*/} can't be diffed; probably not in cache"
35+
clear_cache=1
36+
fi
37+
if [[ ! -z $diff ]]
38+
then
39+
echo "${i##*/} has changed:"
40+
echo $diff
41+
clear_cache=1
42+
fi
43+
done
1044

11-
echo "Cache available"
12-
clear_cache=1
13-
# did the last commit change cython files?
14-
# go back 2 commits
1545
if [ "$TRAVIS_PULL_REQUEST" == "false" ]
1646
then
17-
echo "Not a PR: checking for cython files changes from last 2 commits"
18-
git diff HEAD~2 --numstat | grep -E "pyx|pxd"
19-
retval=$(git diff HEAD~2 --numstat | grep -E "pyx|pxd"| wc -l)
47+
echo "Not a PR"
48+
# Uncomment next 2 lines to turn off cython caching not in a PR
49+
# echo "Non PR cython caching is disabled"
50+
# clear_cache=1
2051
else
21-
echo "PR: checking for any cython file changes from last 5 commits"
22-
git diff PR_HEAD~5 --numstat | grep -E "pyx|pxd"
23-
retval=$(git diff PR_HEAD~5 --numstat | grep -E "pyx|pxd"| wc -l)
24-
echo "Forcing cython rebuild due to possibility of history rewritting in PR"
25-
retval=-1
52+
echo "In a PR"
53+
# Uncomment next 2 lines to turn off cython caching in a PR
54+
# echo "PR cython caching is disabled"
55+
# clear_cache=1
2656
fi
27-
echo "number of cython files changed: $retval"
57+
2858
fi
2959

30-
if [ $clear_cache -eq 1 ] && [ $retval -eq 0 ] && [ "$USE_CACHE" ]
60+
if [ $clear_cache -eq 0 ] && [ "$USE_CACHE" ]
3161
then
32-
# nope, reuse cython files
62+
# No and use_cache is set
3363
echo "Will reuse cached cython file"
3464
cd /
3565
tar xvmf $CACHE_File
3666
cd $home_dir
3767
else
3868
echo "Rebuilding cythonized files"
39-
echo "Use cache = $USE_CACHE"
40-
echo "Clear cache = $clear_cache"
69+
echo "Use cache (Blank if not set) = $USE_CACHE"
70+
echo "Clear cache (1=YES) = $clear_cache"
4171
fi
4272

4373

ci/submit_cython_cache.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#!/bin/bash
22

33
CACHE_File="$HOME/.cache/cython_files.tar"
4+
PYX_CACHE_DIR="$HOME/.cache/pyxfiles"
5+
pyx_file_list=`find ${TRAVIS_BUILD_DIR} -name "*.pyx"`
6+
47
rm -rf $CACHE_File
8+
rm -rf $PYX_CACHE_DIR
59

610
home_dir=$(pwd)
711

8-
pyx_files=`find ${TRAVIS_BUILD_DIR} -name "*.pyx"`
12+
mkdir $PYX_CACHE_DIR
13+
rsync -Rv $pyx_file_list $PYX_CACHE_DIR
14+
915
echo "pyx files:"
10-
echo $pyx_files
16+
echo $pyx_file_list
1117

1218
tar cf ${CACHE_File} --files-from /dev/null
1319

14-
for i in ${pyx_files}
20+
for i in ${pyx_file_list}
1521
do
1622
f=${i%.pyx}
1723
ls $f.{c,cpp} | tar rf ${CACHE_File} -T -

0 commit comments

Comments
 (0)