Skip to content

Enforce Ruff complexity and argument limits - #22

Merged
leynos merged 1 commit into
mainfrom
codex/update-ruff-configuration-in-pyproject.toml
Nov 2, 2025
Merged

Enforce Ruff complexity and argument limits#22
leynos merged 1 commit into
mainfrom
codex/update-ruff-configuration-in-pyproject.toml

Conversation

@leynos

@leynos leynos commented Nov 1, 2025

Copy link
Copy Markdown
Owner

Summary

  • enable Ruff's C90 and PLR0913 checks and configure max arguments with targeted test exemptions
  • refactor test workspace manifest helper to derive metadata from crate specifications
  • adjust publish fixture assembly to pull dependencies from pytest's request object and stay within argument limits

Testing

  • make check-fmt
  • make typecheck
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_6906190604748322b063d246911e8341

Summary by Sourcery

Enforce code complexity and argument limits via Ruff while refactoring test helpers to derive metadata from CrateSpec and streamline fixture assembly through pytest request

New Features:

  • Enable Ruff C90 and PLR0913 checks with configured max-complexity and max-args thresholds

Enhancements:

  • Refactor _write_crate_manifest to accept a CrateSpec object for deriving manifest metadata
  • Simplify publish_fixtures by retrieving fixtures via pytest's request object to reduce direct arguments

Summary by CodeRabbit

  • Chores
    • Updated linting configuration to enforce additional code quality rules.
    • Refactored internal test infrastructure for improved maintainability and consistency.

@sourcery-ai

sourcery-ai Bot commented Nov 1, 2025

Copy link
Copy Markdown

Reviewer's Guide

This PR enables Ruff’s C90 and PLR0913 rules with max-args enforcement by updating pyproject.toml, refactors the workspace manifest helper to accept a single _CrateSpec parameter, and adjusts the publish_fixtures fixture to pull dependencies via pytest’s request to comply with argument limits.

Class diagram for refactored workspace manifest helper

classDiagram
    class WorkspaceManifestHelper {
        +from_crate_spec(crate_spec: _CrateSpec)
        -metadata
    }
    class _CrateSpec {
        +name
        +version
        +dependencies
    }
    WorkspaceManifestHelper -- _CrateSpec: derives metadata from
Loading

Class diagram for updated publish_fixtures fixture

classDiagram
    class PublishFixtures {
        +__call__(request)
        -dependencies
    }
    class PytestRequest {
        +getfixturevalue(name)
    }
    PublishFixtures ..> PytestRequest: pulls dependencies from
Loading

File-Level Changes

Change Details Files
Refactor crate manifest writer to use a _CrateSpec parameter
  • Replace individual name, version, readme, and extra args with a single spec object
  • Update header_lines to reference spec.name and spec.version
  • Append spec.readme_workspace and spec.manifest_extra when present
  • Simplify calls in workspace builder to pass spec directly
tests/helpers/workspace_builders.py
Simplify publish_fixtures by loading fixtures from request
  • Change fixture signature to accept only request and publish_options
  • Use request.getfixturevalue to retrieve tmp_path and helper factories
  • Remove direct fixture parameters to reduce argument count
tests/unit/conftest.py
Enable Ruff complexity and argument-limit checks in configuration
  • Add C90 and PLR0913 to the Ruff select list
  • Include PLR0913 in test-file per-file-ignores
  • Introduce a pylintrc max-args = 4 section
  • Retain max-complexity = 9 under mccabe settings
pyproject.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 1, 2025

Copy link
Copy Markdown

Walkthrough

This pull request refactors test infrastructure by introducing a spec-based configuration pattern. Changes include updating Ruff linting rules in pyproject.toml, replacing the _write_crate_manifest function signature to accept a _CrateSpec dataclass, and modifying the publish_fixtures fixture to use pytest's request object for dynamic fixture resolution.

Changes

Cohort / File(s) Change Summary
Linting Configuration
pyproject.toml
Added C90 and PLR0913 to Ruff lint selection. Introduced [tool.ruff.lint.pylint] section with max-args = 4. Extended ignore rules and per-file ignores for test files. Added [tool.ruff.lint.flake8-import-conventions] configuration with aliases.
Test Infrastructure Refactoring
tests/helpers/workspace_builders.py
Introduced _CrateSpec dataclass to encapsulate crate configuration (name, manifest_extra, dependencies, version, readme_workspace). Replaced _write_crate_manifest signature from multiple keyword arguments to single spec parameter. Updated manifest construction logic to derive fields from spec object.
Fixture Wiring Changes
tests/unit/conftest.py
Modified publish_fixtures fixture to accept request parameter and publish_options instead of concrete fixture parameters. Deferred fixture resolution to runtime using request.getfixturevalue().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Areas requiring extra attention:

  • workspace_builders.py: Verify all call sites to _write_crate_manifest have been updated to pass the new _CrateSpec object correctly
  • conftest.py: Confirm the runtime fixture resolution via request.getfixturevalue() retrieves the correct fixtures and maintain equivalent behavior to the original explicit parameters
  • pyproject.toml: Validate that new Ruff rules (C90, PLR0913) and pylint configuration (max-args = 4) align with project coding standards and don't cause unexpected lint failures

Poem

🐰 A spec in a dataclass, neat and refined,
Fixtures resolved at runtime, all in mind,
Linting rules tightened, the code stays aligned,
Refactoring magic, where tests are redesigned! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Enforce Ruff complexity and argument limits" accurately describes the primary objective of the PR, which is to enable and configure Ruff checks C90 and PLR0913 with a maximum argument limit. This is clearly demonstrated in the pyproject.toml changes that form the core configuration work. While the PR also includes significant refactoring to test helpers (workspace_builders.py and conftest.py) to comply with these new limits, these changes are supporting work undertaken to make the Ruff enforcement feasible rather than independent changes. The title captures the main goal and the changes that trigger the refactoring, making it fully related to the primary objective of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/update-ruff-configuration-in-pyproject.toml

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@leynos
leynos merged commit 114b752 into main Nov 2, 2025
4 checks passed
@leynos
leynos deleted the codex/update-ruff-configuration-in-pyproject.toml branch November 2, 2025 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant