Skip to content

Commit

Permalink
add pre-commit
Browse files Browse the repository at this point in the history
https://pre-commit.com/ is a nice tool that can be installed and used
as git-hook as well as executed as a GitHub Action, unifying how to
validate our development efforts.

Please install pre-commit in your system, then run:

    pre-commit install

See https://pre-commit.com/#install
  • Loading branch information
barbieri committed May 25, 2023
1 parent 26c97ce commit 4790b1e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 15 deletions.
22 changes: 7 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,10 @@ jobs:
cache: "poetry"
- name: "Install poetry dependencies"
run: "poetry install --no-interaction"

- name: "Typecheck with MyPy"
run: "poetry run mypy"

- name: "Test with server v2 (reduced < python-3.11)"
if: ${{ matrix.python-version != '3.11' }}
run: "poetry run python hrana-test-server/server_v2.py pytest --ignore tests/dbapi2 --verbose"
- name: "Test with server v2 (full-python-3.11)"
if: ${{ matrix.python-version == '3.11' }}
run: "poetry run python hrana-test-server/server_v2.py pytest --verbose" # the dbapi2 tests were copied from python-3.11
- name: "Run the readme example"
run: "poetry run python examples/readme.py"
- name: "Run the books example"
run: "poetry run python examples/books.py"

- run: "pip install pre-commit"
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: "Run pre-commit"
run: pre-commit run --show-diff-on-failure --color=always --hook-stage push
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

default_install_hook_types: [pre-commit, pre-push, pre-merge-commit]

repos:
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.3.0
hooks:
- id: mypy
exclude: "^(tests|examples|docs|hrana-test-server)/"

- repo: local
hooks:
- id: run-tests
name: run-tests
entry: ./scripts/run-tests.sh
exclude: ^(examples|docs|hrana-test-server)/
language: script
pass_filenames: false
always_run: true
types: [python]
stages: [push, merge-commit]

- repo: local
hooks:
- id: run-examples
name: run-examples
entry: ./scripts/run-examples.sh
exclude: ^(tests|docs|hrana-test-server)/
language: script
pass_filenames: false
always_run: true
types: [python]
stages: [push, merge-commit]
21 changes: 21 additions & 0 deletions scripts/run-examples.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

export URL="ws://localhost:8080"
EXAMPLES=(
examples/books.py
examples/readme.py
examples/dbapi2.py
)

function die() {
echo "ERROR: $*" 1>&2
exit 1
}

for e in ${EXAMPLES[@]}; do
echo -e "\nEXAMPLE: $e"
poetry run \
python hrana-test-server/server_v2.py \
python $e ||
die "failed to execute $e"
done
14 changes: 14 additions & 0 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

PY_MIN_VER=`python -c "import sys; print(sys.version_info[1])"`

OPTS=("--verbose")
if [ "$PY_MIN_VER" -lt 11 ]; then
# tests/dbapi2 are based on cpython-3.11 test suite
OPTS+=("--ignore" "tests/dbapi2")
fi

set -x
exec poetry run \
python hrana-test-server/server_v2.py \
pytest "${OPTS[@]}"

0 comments on commit 4790b1e

Please sign in to comment.