Skip to content

Commit

Permalink
Install pre-commit with setup, add GitHub action for pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dhower-qc committed Dec 11, 2024
1 parent 59df882 commit dd81398
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/regress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ on:
- main
workflow_dispatch:
jobs:
regress-pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
regress-smoke:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 3 additions & 1 deletion bin/python
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash

ROOT=$(dirname $(realpath $BASH_SOURCE[0]))
source $ROOT/setup
if [ ! -v NO_SOURCE ]; then
source $ROOT/setup
fi

$PYTHON "$@"
30 changes: 28 additions & 2 deletions bin/setup
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if [ -v DEVCONTAINER_ENV ]; then
NPM="npm"
NPX="npx"
NODE="node"
PYTHON="python3"
PYTHON="${ROOT}/.home/.venv/bin/python3"
PIP="${ROOT}/.home/.venv/bin/pip"
BASH="bash"
else
Expand All @@ -101,7 +101,33 @@ else
NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm"
NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx"
NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node"
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} python3"
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/python3"
PIP="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/pip"
BASH="singularity run ${HOME_OPT} ${CONTAINER_PATH} bash"
fi

if [ ! -f $ROOT/.git/hooks/pre-commit ]; then
cat << HOOK > $ROOT/.git/hooks/pre-commit
#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
# start templated
INSTALL_PYTHON=$ROOT/bin/python
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit)
# end templated
HERE="$(cd "$(dirname "\$0")" && pwd)"
ARGS+=(--hook-dir "\$HERE" -- "\$@")
if [ -x "\$INSTALL_PYTHON" ]; then
exec "\$INSTALL_PYTHON" -mpre_commit "\${ARGS[@]}"
elif command -v pre-commit > /dev/null; then
exec pre-commit "\${ARGS[@]}"
else
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
exit 1
fi
HOOK
chmod +x $ROOT/.git/hooks/pre-commit
fi

0 comments on commit dd81398

Please sign in to comment.