diff --git a/.githooks/check-tests-python.sh b/.githooks/check-tests-python.sh new file mode 100755 index 000000000..485065fb0 --- /dev/null +++ b/.githooks/check-tests-python.sh @@ -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 . diff --git a/.githooks/pre-commit b/.githooks/pre-commit index a78365acb..b7831500d 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -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 diff --git a/.github/workflows/Containerfile b/.github/workflows/Containerfile index ad7e899dc..7027e7486 100644 --- a/.github/workflows/Containerfile +++ b/.github/workflows/Containerfile @@ -61,8 +61,5 @@ RUN apt install -y --no-install-recommends python3-pip RUN pip install --user --break-system-packages furo">=2024.04.27" \ sphinx-copybutton sphinxext-opengraph matplotlib -# Install pre-commit -RUN pip install --user --break-system-packages pre-commit - # Install qdbusxml2cpp RUN apt install -y --no-install-recommends qt6-base-dev-tools diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 652d5f167..11ca3fa3e 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -38,11 +38,9 @@ jobs: - name: Check out xdg-desktop-portal uses: actions/checkout@v4 - - name: Run pre-commit hooks + - name: Run checks run: | - export PYTHONPATH="/root/.local/lib/python$(python3 -c 'import sys; print("{}.{}".format(*sys.version_info))')/site-packages:$PYTHONPATH" - export PATH="/root/.local/bin:$PATH" - pre-commit run --show-diff-on-failure --color=always --all-files + .githooks/check-tests-python.sh - name: Check POTFILES.in run: .github/workflows/check-potfiles.sh diff --git a/.github/workflows/container.yml b/.github/workflows/container.yml index 7ecf61d3b..59c71c5e7 100644 --- a/.github/workflows/container.yml +++ b/.github/workflows/container.yml @@ -1,5 +1,5 @@ env: - IMAGE_TAG: 20241211-1 + IMAGE_TAG: 2025-01-17.0 on: workflow_call: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 9752aedb3..000000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,10 +0,0 @@ -repos: -- repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. - rev: v0.7.0 - hooks: - # Run the linter. - - id: ruff - # Run the formatter. - - id: ruff-format - args: [ --check ]