-
Notifications
You must be signed in to change notification settings - Fork 1
/
.pre-commit-run.sh
executable file
·52 lines (47 loc) · 1.37 KB
/
.pre-commit-run.sh
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
#!/bin/sh
# Invoked from .pre-commit-config.yaml to run mypy (or other tool)
# using "pre-commit" variable in pyproject.toml file
# project.optional-dependencies section.
# NOTE!! Takes FULL command line as arguments
LOG=$0.log
(
date
pwd
echo COMMAND LINE: $0 $*
echo '#####'
echo ENVIRONMENT:
env
echo '#####'
) > $LOG
# NOTE!! https://github.com/pre-commit/mirrors-mypy/README.md says
# "using the --install-types is problematic." (mutates cache)
# Want to stash copy of pyproject.toml in the top level of the
# pre-commit created virtual environment to detect changes.
# Fortunately, a useful variable points there!
if [ -n "$VIRTUAL_ENV" ]; then
TMP=$VIRTUAL_ENV/pyproject.toml
else
echo "$0: VIRTUAL_ENV not set; see $LOG" 1>&2
exit 1
fi
echo TMP $TMP >> $LOG
# check saved copy of pyproject.toml to see if it has changed (or does
# not yet exist) and if (re)install pre-commit optional dependencies if
# needed.
if cmp -s pyproject.toml $TMP; then
echo no change to pyproject.toml >> $LOG
else
echo installing pre-commit optional dependencies >> $LOG
# --editable skips installing project package
if python3 -m pip install --editable '.[pre-commit]'; then
cp -p pyproject.toml $TMP
echo done >> $LOG
else
STATUS=$?
echo pip failed $STATUS >> $LOG
exit $STATUS
fi
fi
#pip list >> $LOG
# NOTE! first arg must be command to invoke!
"$@"