Skip to content

Commit

Permalink
Run pre-commit using a python venv
Browse files Browse the repository at this point in the history
This ensures that you don't need to rely on the environment quite so
much.

Also: Add .gitignore for venv dir
  • Loading branch information
martinthomson authored Jan 8, 2024
1 parent c45dfd8 commit b9dbf59
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.swp
*~
/venv/
16 changes: 15 additions & 1 deletion pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# $ ln -s ../../hooks/pre-commit .git/pre-commit

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

# Some sanity checking.
hash python3 || exit 1
Expand All @@ -17,14 +18,27 @@ if [[ "$1" == "install" ]]; then
hook="$root"/.git/hooks/pre-commit
if [[ -e "$hook" ]]; then
echo "Hook already installed:"
ls -l "$hook"
ls -l "$hook"
else
ln -s ../../pre-commit "$hook"
echo "Installed git pre-commit hook at $hook"
fi
exit
fi

# venv setup
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

exec 1>&2

# Perform validation.
Expand Down

0 comments on commit b9dbf59

Please sign in to comment.