From 27cce7b423bce34152989eebfa461216ce811f8a Mon Sep 17 00:00:00 2001 From: MarTrepodi Date: Tue, 13 Oct 2026 08:53:05 -0400 Subject: [PATCH] ci: run ruff from uv.lock in CI and pre-commit CI used unpinned `uvx ruff` (latest on PyPI), pre-commit pinned ruff-pre-commit at v0.15.4 (not tracked by Dependabot), and uv.lock held 0.15.15. Make uv.lock the single source of truth so Dependabot uv bumps move all three together. - Add a `lint` dependency group with ruff; `dev` includes it. - CI lint job: `uv sync --locked --only-group lint`, then `uv run --no-sync ruff ...`. - pre-commit: replace ruff-pre-commit with local `uv run ruff` hooks, matching the existing local ty hook. - Update CONTRIBUTING.md and the PR template to `uv run ruff`. Co-Authored-By: Claude Opus 5.5 --- .github/pull_request_template.md | 2 +- .github/workflows/ci.yml | 7 +++++-- .pre-commit-config.yaml | 15 ++++++++++++--- CONTRIBUTING.md | 6 +++--- pyproject.toml | 5 ++++- uv.lock | 4 ++++ 6 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index c3a6421..6eda18a 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -30,7 +30,7 @@ - [ ] I have updated the docs (`README.md`, `docs/`, `examples/`) if user-facing behavior changed - [ ] I have added unit tests that cover my changes (mocked, not requiring a live comlink service) - [ ] Tests pass (`uv run pytest tests/`) -- [ ] Ruff linter and formatter pass (`uvx ruff check src/ tests/` and `uvx ruff format --check src/ tests/`) +- [ ] Ruff linter and formatter pass (`uv run ruff check src/ tests/` and `uv run ruff format --check src/ tests/`) - [ ] Type check passes (`uv run ty check src/swgoh_comlink/`) - [ ] I have not bundled unrelated changes in this PR diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0d3a24..9242260 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,13 +30,16 @@ jobs: with: python-version: "3.12" + - name: Install dependencies + run: uv sync --locked --only-group lint + - name: Run Ruff linter - run: uvx ruff check src/ tests/ + run: uv run --no-sync ruff check src/ tests/ - name: Run Ruff formatter check # NOTE: Set continue-on-error to false once the initial formatting PR is merged continue-on-error: true - run: uvx ruff format --check src/ tests/ + run: uv run --no-sync ruff format --check src/ tests/ # ── Type check ───────────────────────────────────────────────────────── type-check: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 30ccdac..c843b89 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,13 +15,22 @@ repos: - id: debug-statements # ── Ruff linter & formatter (mirrors CI lint job) ───────────────────── - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.4 + # Run via local uv so the version comes from uv.lock, same as CI. + - repo: local hooks: - id: ruff - args: [--fix] + name: ruff check + entry: uv run ruff check --fix --force-exclude + language: system exclude: ^examples/ + types: [python] + require_serial: true - id: ruff-format + name: ruff format + entry: uv run ruff format --force-exclude + language: system + types: [python] + require_serial: true # ── ty type checking (Astral, run via local uv) ─────────────────────── - repo: local diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d43771b..4be10f5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -236,7 +236,7 @@ This project follows standard Python conventions, enforced by [Ruff](https://doc **General principles:** -- Follow [PEP 8](https://peps.python.org/pep-0008/) for formatting — `uvx ruff format` handles this for you +- Follow [PEP 8](https://peps.python.org/pep-0008/) for formatting — `uv run ruff format` handles this for you - Use **complete type annotations** on all functions, parameters, and return values — the package ships a `py.typed` marker, so downstream users' type checkers rely on them - Use `from __future__ import annotations` at the top of each module for modern annotation syntax - Use docstrings (Google style) on all public classes and methods — they are rendered into the API reference @@ -421,8 +421,8 @@ commit would be left out of the changelog entirely. ```bash # Lint and format - uvx ruff check src/ tests/ - uvx ruff format --check src/ tests/ + uv run ruff check src/ tests/ + uv run ruff format --check src/ tests/ # Type check uv run ty check src/swgoh_comlink/ diff --git a/pyproject.toml b/pyproject.toml index 42e4a18..7063090 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -118,6 +118,9 @@ test = [ typecheck = [ "ty>=0.0.34", ] +lint = [ + "ruff>=0.8", +] changelog = [ "git-changelog>=2.9,<3", ] @@ -125,7 +128,7 @@ dev = [ {include-group = "test"}, {include-group = "typecheck"}, {include-group = "changelog"}, - "ruff>=0.8", + {include-group = "lint"}, ] docs = [ # MkDocs 2.0 removes the plugin system (mkdocstrings) and theme overrides that this diff --git a/uv.lock b/uv.lock index 5fcfcaf..7385b4b 100644 --- a/uv.lock +++ b/uv.lock @@ -942,6 +942,9 @@ docs = [ { name = "mkdocs-material" }, { name = "mkdocstrings", extra = ["python"] }, ] +lint = [ + { name = "ruff" }, +] test = [ { name = "pytest" }, { name = "pytest-asyncio" }, @@ -974,6 +977,7 @@ docs = [ { name = "mkdocs-material", specifier = ">=9.5.0" }, { name = "mkdocstrings", extras = ["python"], specifier = ">=0.28.0" }, ] +lint = [{ name = "ruff", specifier = ">=0.8" }] test = [ { name = "pytest", specifier = ">=7.0" }, { name = "pytest-asyncio", specifier = ">=0.24" },