forked from flatpak/xdg-desktop-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
githooks: Replace pre-commit tool with simple shell script
It's basically impossible to run mypy with pre-commit because it will ignore the repo config and check all files changed the commit. The dbusmock templates are special and mypy fails on them so we use the mypy config to skip them. This introduces a new script which checks the python tests and installs all the required tools into a python virtual environment. It also changes to pre-commit hook to call the script if any of the files in tests changed and uses git stash push/pop to get the test a clean state of the repo.
- Loading branch information
Showing
6 changed files
with
52 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
PYTHON=${PYTHON:-python} | ||
|
||
HERE="$(cd "$(dirname "$0")" && pwd)" | ||
VENV="${HERE}/.venv" | ||
|
||
[ -d $VENV ] || $PYTHON -m venv $VENV | ||
source $VENV/bin/activate | ||
|
||
|
||
$PYTHON -m ruff --version >/dev/null || $PYTHON -m pip install ruff | ||
$PYTHON -m mypy --version >/dev/null || $PYTHON -m pip install mypy | ||
$PYTHON -m pytest --version >/dev/null || $PYTHON -m pip install pytest | ||
|
||
cd tests | ||
|
||
# FIXME run all of them and then exit with correct code | ||
python3 -m ruff check . | ||
python3 -m ruff format --check . | ||
mypy . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,31 @@ | ||
#!/usr/bin/env bash | ||
# File generated by pre-commit: https://pre-commit.com | ||
# ID: 138fd403232d2ddd5efb44317e38bf03 | ||
|
||
# start templated | ||
INSTALL_PYTHON=/usr/bin/python3 | ||
ARGS=(hook-impl --config=.pre-commit-config.yaml --hook-type=pre-commit) | ||
# end templated | ||
set -euo pipefail | ||
|
||
HERE="$(cd "$(dirname "$0")" && pwd)" | ||
ARGS+=(--hook-dir "$HERE" -- "$@") | ||
CHECK_TEST_PYTHON="${HERE}/check-tests-python.sh" | ||
|
||
path_unchanged() | ||
{ | ||
! git diff --cached --name-only | grep $1 >/dev/null | ||
} | ||
|
||
check() | ||
{ | ||
if [ -z ${PRE_COMMIT_STASH+x} ]; then | ||
PRE_COMMIT_STASH=1 | ||
|
||
clean_up () | ||
{ | ||
git stash pop | ||
} | ||
|
||
if ! git diff -s --exit-code; then | ||
git stash push --keep-index | ||
trap clean_up EXIT | ||
fi | ||
fi | ||
|
||
$@ | ||
} | ||
|
||
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 | ||
path_unchanged ^tests/ || check $CHECK_TEST_PYTHON |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
env: | ||
IMAGE_TAG: 20241211-1 | ||
IMAGE_TAG: 2025-01-17.0 | ||
|
||
on: | ||
workflow_call: | ||
|
This file was deleted.
Oops, something went wrong.