From 0689868f0dd2a1f95d54f6de02c2af2338b1a978 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Borgna?= <121866228+aborgna-q@users.noreply.github.com> Date: Fri, 16 Aug 2024 16:38:39 +0100 Subject: [PATCH] chore: Use local `ruff` and `mypy` for pre-commit (#1440) 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 --- .pre-commit-config.yaml | 43 ++++++++++++++++++++++++------------ hugr-py/tests/test_custom.py | 2 +- poetry.lock | 41 +++++++++++++++++----------------- pyproject.toml | 5 +++-- 4 files changed, 54 insertions(+), 37 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a5b43f7ab..ea8003724 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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`. @@ -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 diff --git a/hugr-py/tests/test_custom.py b/hugr-py/tests/test_custom.py index 081a63a9a..8b14b8031 100644 --- a/hugr-py/tests/test_custom.py +++ b/hugr-py/tests/test_custom.py @@ -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) diff --git a/poetry.lock b/poetry.lock index 68802b027..864eb50ab 100644 --- a/poetry.lock +++ b/poetry.lock @@ -163,7 +163,7 @@ typing = ["typing-extensions (>=4.8)"] [[package]] name = "hugr" -version = "0.6.0" +version = "0.7.0" description = "Quantinuum's common representation for quantum programs" optional = false python-versions = ">=3.10" @@ -582,28 +582,29 @@ files = [ [[package]] name = "ruff" -version = "0.3.7" +version = "0.6.0" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:0e8377cccb2f07abd25e84fc5b2cbe48eeb0fea9f1719cad7caedb061d70e5ce"}, - {file = "ruff-0.3.7-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:15a4d1cc1e64e556fa0d67bfd388fed416b7f3b26d5d1c3e7d192c897e39ba4b"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d28bdf3d7dc71dd46929fafeec98ba89b7c3550c3f0978e36389b5631b793663"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:379b67d4f49774ba679593b232dcd90d9e10f04d96e3c8ce4a28037ae473f7bb"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c060aea8ad5ef21cdfbbe05475ab5104ce7827b639a78dd55383a6e9895b7c51"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:ebf8f615dde968272d70502c083ebf963b6781aacd3079081e03b32adfe4d58a"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d48098bd8f5c38897b03604f5428901b65e3c97d40b3952e38637b5404b739a2"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:da8a4fda219bf9024692b1bc68c9cff4b80507879ada8769dc7e985755d662ea"}, - {file = "ruff-0.3.7-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c44e0149f1d8b48c4d5c33d88c677a4aa22fd09b1683d6a7ff55b816b5d074f"}, - {file = "ruff-0.3.7-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:3050ec0af72b709a62ecc2aca941b9cd479a7bf2b36cc4562f0033d688e44fa1"}, - {file = "ruff-0.3.7-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:a29cc38e4c1ab00da18a3f6777f8b50099d73326981bb7d182e54a9a21bb4ff7"}, - {file = "ruff-0.3.7-py3-none-musllinux_1_2_i686.whl", hash = "sha256:5b15cc59c19edca917f51b1956637db47e200b0fc5e6e1878233d3a938384b0b"}, - {file = "ruff-0.3.7-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:e491045781b1e38b72c91247cf4634f040f8d0cb3e6d3d64d38dcf43616650b4"}, - {file = "ruff-0.3.7-py3-none-win32.whl", hash = "sha256:bc931de87593d64fad3a22e201e55ad76271f1d5bfc44e1a1887edd0903c7d9f"}, - {file = "ruff-0.3.7-py3-none-win_amd64.whl", hash = "sha256:5ef0e501e1e39f35e03c2acb1d1238c595b8bb36cf7a170e7c1df1b73da00e74"}, - {file = "ruff-0.3.7-py3-none-win_arm64.whl", hash = "sha256:789e144f6dc7019d1f92a812891c645274ed08af6037d11fc65fcbc183b7d59f"}, - {file = "ruff-0.3.7.tar.gz", hash = "sha256:d5c1aebee5162c2226784800ae031f660c350e7a3402c4d1f8ea4e97e232e3ba"}, + {file = "ruff-0.6.0-py3-none-linux_armv6l.whl", hash = "sha256:92dcce923e5df265781e5fc76f9a1edad52201a7aafe56e586b90988d5239013"}, + {file = "ruff-0.6.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:31b90ff9dc79ed476c04e957ba7e2b95c3fceb76148f2079d0d68a908d2cfae7"}, + {file = "ruff-0.6.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:6d834a9ec9f8287dd6c3297058b3a265ed6b59233db22593379ee38ebc4b9768"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f2089267692696aba342179471831a085043f218706e642564812145df8b8d0d"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:aa62b423ee4bbd8765f2c1dbe8f6aac203e0583993a91453dc0a449d465c84da"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7344e1a964b16b1137ea361d6516ce4ee61a0403fa94252a1913ecc1311adcae"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:487f3a35c3f33bf82be212ce15dc6278ea854e35573a3f809442f73bec8b2760"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:75db409984077a793cf344d499165298a6f65449e905747ac65983b12e3e64b1"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:84908bd603533ecf1db456d8fc2665d1f4335d722e84bc871d3bbd2d1116c272"}, + {file = "ruff-0.6.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0f1749a0aef3ec41ed91a0e2127a6ae97d2e2853af16dbd4f3c00d7a3af726c5"}, + {file = "ruff-0.6.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:016fea751e2bcfbbd2f8cb19b97b37b3fd33148e4df45b526e87096f4e17354f"}, + {file = "ruff-0.6.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:6ae80f141b53b2e36e230017e64f5ea2def18fac14334ffceaae1b780d70c4f7"}, + {file = "ruff-0.6.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:eaaaf33ea4b3f63fd264d6a6f4a73fa224bbfda4b438ffea59a5340f4afa2bb5"}, + {file = "ruff-0.6.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:7667ddd1fc688150a7ca4137140867584c63309695a30016880caf20831503a0"}, + {file = "ruff-0.6.0-py3-none-win32.whl", hash = "sha256:ae48365aae60d40865a412356f8c6f2c0be1c928591168111eaf07eaefa6bea3"}, + {file = "ruff-0.6.0-py3-none-win_amd64.whl", hash = "sha256:774032b507c96f0c803c8237ce7d2ef3934df208a09c40fa809c2931f957fe5e"}, + {file = "ruff-0.6.0-py3-none-win_arm64.whl", hash = "sha256:a5366e8c3ae6b2dc32821749b532606c42e609a99b0ae1472cf601da931a048c"}, + {file = "ruff-0.6.0.tar.gz", hash = "sha256:272a81830f68f9bd19d49eaf7fa01a5545c5a2e86f32a9935bb0e4bb9a1db5b8"}, ] [[package]] @@ -673,4 +674,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "02893dd1737b1046c8d63dc450feb880b2095a24231058bbffe4d78c57930e6b" +content-hash = "a663190fa348f1ebd7c6c2cb8e45962ebcb14295f981a36d7a67271a848d32a5" diff --git a/pyproject.toml b/pyproject.toml index 5818741eb..ad75fbb7b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"