Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run pre-commit using a python venv #956

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading