-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgithook-pre-commit
executable file
·127 lines (114 loc) · 4.12 KB
/
githook-pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/env bash
## Create pre-commit symlink if unset ##
GITDIR="";
if [ -d .git ]; then
GITDIR=".git";
elif [ -f .git ]; then
GITDIR=$(sed -n '/^gitdir:/{ s|.*: ||; p; }' .git);
fi
if [ ! -d "$GITDIR" ]; then
echo "${0##*/}: error: unable to find git directory" 1>&2;
exit 1;
fi
if [ ! -h "$GITDIR/hooks/pre-commit" ]; then
if [ $(realpath --help 2>&1 | grep -c relative) != 0 ]; then
HOOK=$(realpath --relative-to="$GITDIR/hooks" ./githook-pre-commit);
else
HOOK=$(readlink -f ./githook-pre-commit);
fi
ln -fs "$HOOK" "$GITDIR/hooks/pre-commit";
echo "${0##*/}: creating git pre-commit hook symlink" 1>&2;
exit 1;
fi
## Update versions on files ##
FILES=( $(git status --porcelain | sed -r 's|^ |_|; s|^(.) |\1_|;' | grep -E '^([MRA]|.M)' | grep -v '^R_') );
V=$(date -u +%Y.%m.%d);
check_change_after_staged () {
[ "${2:1:1}" = "M" ] &&
echo "${0##*/}: error: aborting due to file change: $1" 1>&2 &&
exit 1;
}
VERSION_UPDATED=( - );
update_file_version () {
echo "${0##*/}: updating version of $1" 1>&2;
sed -r -i 's|([$"])Version:[^$"]*([$"])|\1Version: '"$V"'\2|' "$1";
git add "$1";
VERSION_UPDATED+=( "$1" );
}
already_updated () {
echo $(printf "%s\n" "${VERSION_UPDATED[@]}" | grep -c "^$1\$");
}
n=1;
while [ "$n" -lt "${#FILES[@]}" ]; do
check_change_after_staged "${FILES[$n]}" "${FILES[$((n-1))]}";
[ $(already_updated "${FILES[$n]}") = 0 ] &&
case "${FILES[$n]}" in
*.cc )
update_file_version "${FILES[$n]}";
[ -e "${FILES[$n]/.cc/.h}" ] &&
update_file_version "${FILES[$n]/.cc/.h}";
;;
*.h )
update_file_version "${FILES[$n]}";
[ -e "${FILES[$n]/.h/.cc}" ] &&
update_file_version "${FILES[$n]/.h/.cc}";
;;
*.py )
update_file_version "${FILES[$n]}";
echo "${0##*/}: pylint --errors-only --extension-pkg-whitelist=cv2 ${FILES[$n]}" 1>&2;
pylint --errors-only --extension-pkg-whitelist=cv2 "${FILES[$n]}";
[ "$?" != 0 ] && exit 1;
;;
esac
n=$((n+2));
done
if [ "${#VERSION_UPDATED[@]}" -gt 0 ]; then
echo "## Test pagexml python wrapper ##"
cd py-pagexml;
./setup.py test;
[ "$?" != 0 ] && exit 1;
cd ..;
echo "## Test textfeat python wrapper ##"
cd py-textfeat;
./setup.py test;
[ "$?" != 0 ] && exit 1;
cd ..;
fi
## Only when bumping version ##
if [ "${BUMPVERSION_NEW_VERSION+x}" != "" ]; then
if [ "${#VERSION_UPDATED[@]}" -gt 0 ]; then
echo "## Update swig docstrings ##"
cd lib;
doxygen &&
../doxy2swig/doxy2swig.py xml/class_page_x_m_l.xml --output ../py-pagexml/pagexml/PageXML_doxy2swig.i &&
../doxy2swig/doxy2swig.py xml/class_text_feat_extractor.xml --output ../py-textfeat/textfeat/TextFeatExtractor_doxy2swig.i;
[ "$?" != 0 ] && exit 1;
cd ..;
git add py-pagexml/pagexml/PageXML_doxy2swig.i py-textfeat/textfeat/TextFeatExtractor_doxy2swig.i;
echo "## Update pagexml documentation ##"
cd py-pagexml;
./setup.py build_sphinx --quiet --builder html --version $V --release $V &&
rm -r ../docs/py-pagexml/{_modules,_sources} ../docs/py-pagexml/*.* &&
mv sphinx/_build/html/{_modules,_sources} sphinx/_build/html/*.* ../docs/py-pagexml &&
mv sphinx/_build/html/_static/documentation_options.js ../docs/py-pagexml/_static &&
find ../docs/py-pagexml -name '*.html' -or -name '*.js' \
| grep -v _static \
| xargs sed -i 's|pagexml\.swigPageXML|pagexml|g';
[ "$?" != 0 ] && exit 1;
cd ..;
git add docs/py-pagexml;
echo "## Update textfeat documentation ##"
cd py-textfeat;
./setup.py build_sphinx --quiet --builder html --version $V --release $V &&
rm -r ../docs/py-textfeat/{_modules,_sources} ../docs/py-textfeat/*.* &&
mv sphinx/_build/html/{_modules,_sources} sphinx/_build/html/*.* ../docs/py-textfeat &&
mv sphinx/_build/html/_static/documentation_options.js ../docs/py-textfeat/_static &&
find ../docs/py-textfeat -name '*.html' -or -name '*.js' \
| grep -v _static \
| xargs sed -i 's|textfeat\.swigTextFeatExtractor|textfeat|g';
[ "$?" != 0 ] && exit 1;
cd ..;
git add docs/py-textfeat;
fi
fi
exit 0;