Skip to content

Commit

Permalink
chore: Use local ruff and mypy for pre-commit checks (#388)
Browse files Browse the repository at this point in the history
Ensures that the checks run by pre-commit are the same as the ones run
in CI, and the `ruff` and `mypy` versions are always controlled by
`pyproject.toml`.
Before, we used pre-commit actions with their own versions that needed
to be updated separately and tended to get out of date.

drive-by: Fix ruff lints added in the latest version
  • Loading branch information
aborgna-q authored Aug 20, 2024
1 parent 9ddf154 commit 0fdbbbb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,10 @@ jobs:
run: poetry run mypy guppylang

- name: Check formatting with ruff
uses: chartboost/ruff-action@v1
with:
src: "./guppylang"
args: format --check
version: 0.4.2
run: poetry run ruff format --check guppylang

- name: Lint with ruff
uses: chartboost/ruff-action@v1
with:
src: "./guppylang"
args: check
run: poetry run ruff check guppylang

- name: Install Guppy with validation and llvm-based execution
run: poetry install --with execution,validation
Expand Down
48 changes: 27 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,36 @@ repos:
hooks:
- id: typos

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.6
- repo: local
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: poetry-install
name: sync poetry deps
description: Ensure development tools are installed.
entry: poetry install --sync
language: system
files: poetry.lock
pass_filenames: false
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.10.0"
hooks:
- id: mypy
name: ruff format
description: Format python code with `ruff`.
entry: poetry run ruff format guppylang
language: system
files: \.py$
pass_filenames: false
- id: ruff-check
name: ruff
description: Check python code with `ruff`.
entry: poetry run ruff check --fix --exit-non-zero-on-fix guppylang
language: system
files: \.py$
pass_filenames: false
- id: mypy-check
name: mypy
description: Check python code with `mypy`.
entry: poetry run mypy guppylang
language: system
files: \.py$
pass_filenames: false
args: [--package=guppylang]
additional_dependencies: [
hugr,
graphviz,
networkx,
ormsgpack,
pydantic,
pytket,
]

- repo: local
hooks:
- id: cargo-check
name: Cargo check
entry: bash -c 'cd validator && exec cargo check'
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import pytest


@pytest.fixture()
@pytest.fixture
def export_test_cases_dir(request):
r = request.config.getoption("--export-test-cases")
if r and not r.exists():
r.mkdir(parents=True)
return r


@pytest.fixture()
@pytest.fixture
def validate(request, export_test_cases_dir: Path):
def validate_json(hugr: str):
try:
Expand All @@ -39,7 +39,7 @@ class LLVMException(Exception):
pass


@pytest.fixture()
@pytest.fixture
def run_int_fn():
def f(hugr: Hugr, expected: int, fn_name: str = "main"):
try:
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests.util import compile_guppy


@pytest.mark.skip()
@pytest.mark.skip
def test_if_no_else(validate):
@compile_guppy
def foo(x: bool, y: int) -> int:
Expand All @@ -16,7 +16,7 @@ def foo(x: bool, y: int) -> int:
validate(foo)


@pytest.mark.skip()
@pytest.mark.skip
def test_if_else(validate):
@compile_guppy
def foo(x: bool, y: int) -> int:
Expand All @@ -30,7 +30,7 @@ def foo(x: bool, y: int) -> int:
validate(foo)


@pytest.mark.skip()
@pytest.mark.skip
def test_if_elif(validate):
@compile_guppy
def foo(x: bool, y: int) -> int:
Expand All @@ -44,7 +44,7 @@ def foo(x: bool, y: int) -> int:
validate(foo)


@pytest.mark.skip()
@pytest.mark.skip
def test_if_elif_else(validate):
@compile_guppy
def foo(x: bool, y: int) -> int:
Expand All @@ -60,7 +60,7 @@ def foo(x: bool, y: int) -> int:
validate(foo)


@pytest.mark.skip()
@pytest.mark.skip
def test_infinite_loop(validate):
@compile_guppy
def foo() -> int:
Expand All @@ -71,7 +71,7 @@ def foo() -> int:
validate(foo)


@pytest.mark.skip()
@pytest.mark.skip
def test_counting_loop(validate):
@compile_guppy
def foo(i: int) -> int:
Expand All @@ -82,7 +82,7 @@ def foo(i: int) -> int:
validate(foo)


@pytest.mark.skip()
@pytest.mark.skip
def test_nested_loop(validate):
@compile_guppy
def foo(x: int, y: int) -> int:
Expand Down

0 comments on commit 0fdbbbb

Please sign in to comment.