Skip to content

Commit

Permalink
Use virtualenv for pre-commit script
Browse files Browse the repository at this point in the history
  • Loading branch information
martinthomson authored Aug 28, 2024
1 parent 0aa0de9 commit f5f9287
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.bak
*.swp
*~
/venv/
17 changes: 9 additions & 8 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

root="$(git rev-parse --show-toplevel 2>/dev/null)"
venv="$root/venv"
pip="$venv/bin/pip"
python="$venv/bin/python"

# Some sanity checking.
hash python3 || exit 1
Expand All @@ -30,21 +32,20 @@ fi
if [ ! -d "$venv" ]; then
echo "Setting up python venv"
python3 -m venv "$venv"
source "$venv/bin/activate"
pip3 install -r requirements.txt
elif [ requirements.txt -nt "$venv" ]; then
source "$venv/bin/activate"
pip3 install --upgrade --upgrade-stategy eager -r requirements.txt
else
source "$venv/bin/activate"
fi

source "$venv/bin/activate"

if [ requirements.txt -nt "$venv" ]; then
"$pip" install --upgrade --upgrade-strategy eager -r requirements.txt
fi

exec 1>&2

# Perform validation.
trap 'git stash pop -q' EXIT
git stash push -k -u -q -m "pre-commit stash from $(date '+%FT%T%z')"
if ! python3 activities.py validate; then
if ! "$python" activities.py validate; then
echo "Validation failed; \`git commit --no-verify\` to suppress validation."
exit 1
fi

0 comments on commit f5f9287

Please sign in to comment.