Skip to content

Commit

Permalink
chore: Use local ruff and mypy for pre-commit (#1440)
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.
Before, we used pre-commit actions with their own versions that needed
to be updated separately and tended to get out of date.

As an example, the ruff update errors from #1437 didn't appear locally
when running `just check`.

drive-by: Update `ruff` to latest version
  • Loading branch information
aborgna-q authored Aug 16, 2024
1 parent 3a7d09f commit 0689868
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 37 deletions.
43 changes: 29 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,36 @@ repos:
- id: check-docstring-first
- id: debug-statements

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.0
hooks:
- id: mypy
additional_dependencies: [pydantic]

- repo: local
hooks:
- 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
name: ruff format
description: Format python code with `ruff`.
entry: poetry run ruff format
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
language: system
files: \.py$
pass_filenames: false
- id: mypy-check
name: mypy
description: Check python code with `mypy`.
entry: poetry run mypy .
language: system
files: \.py$
pass_filenames: false
- id: cargo-fmt
name: cargo format
description: Format rust code with `cargo fmt`.
Expand Down Expand Up @@ -88,7 +103,7 @@ repos:
# We need to rebuild `hugr-cli` without the `extension_inference` feature
# to avoid test errors.
# TODO: Remove this once the issue is fixed.
entry: sh -c "cargo build -p hugr-cli && poetry install && poetry run pytest"
entry: sh -c "cargo build -p hugr-cli && poetry run pytest"
language: system
files: \.py$
pass_filenames: false
2 changes: 1 addition & 1 deletion hugr-py/tests/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_registry():
reg.get_extension("not_found")


@pytest.fixture()
@pytest.fixture
def registry() -> ext.ExtensionRegistry:
reg = ext.ExtensionRegistry()
reg.add_extension(LOGIC_EXT)
Expand Down
41 changes: 21 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ pre-commit = "^3.6.2"
pytest = "^8.1.1"
pytest-cov = "^5.0.0"
mypy = "^1.9.0"
ruff = "^0.3.3"
ruff = "^0.6.0"
toml = "^0.10.0"

[tool.poetry.group.hugr.dependencies]
hugr = { path = "hugr-py", develop = true }


[tool.poetry.dependencies]
python = "^3.10"
typing-extensions = "^4.12.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down

0 comments on commit 0689868

Please sign in to comment.