Skip to content

Update pre-commit and CI to ensure format and lint #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

Ckk3
Copy link
Contributor

@Ckk3 Ckk3 commented May 18, 2025

Description

This PR introduces the following infrastructure improvements:

  • Removed black in favor of ruff format for code formatting
  • Updated .pre-commit-config.yaml to use Ruff for both linting and formatting
  • Updated noxfile.py and devcontainer.json to include support for Ruff, including a new session to test formatting and linting, also added a new mypy command

This PR contains only configuration and tooling changes, with no changes to the codebase formatting.
This separation is intentional to keep the review focused and easy to follow.

⚠️ Note: The CI is currently failing because the pre-commit hooks haven't been run on the codebase in this PR.
The formatting and linting updates have already been applied in this draft PR:
#247
We'll proceed with that PR after this one is merged.

This PR is targeting the pre-commit-lint-and-format-update branch (not main) to isolate the tooling changes.
By doing this, we can group everything into a single release.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).

Summary by Sourcery

Replace Black with Ruff as the central formatting and linting tool across the project, update pre-commit, Nox, and CI to run Ruff and mypy, and migrate to the poetry-core build backend.

Enhancements:

  • Use Ruff for both code formatting and linting in pyproject.toml and .pre-commit-config.yaml, removing Black
  • Refactor noxfile by extracting a shared poetry_install_run_always helper and add dedicated Ruff lint, Ruff format, and improved mypy sessions

Build:

  • Migrate project build configuration to the poetry-core backend in pyproject.toml

CI:

  • Extend GitHub Actions triggers to additional pull request events, rename and split the lint job into lint and format, and invoke nox lint/format sessions

Documentation:

  • Clean up Sphinx configuration in docs/conf.py, using context managers and formatting tweaks to simplify setup

@Ckk3 Ckk3 self-assigned this May 18, 2025
Copy link
Contributor

sourcery-ai bot commented May 18, 2025

Reviewer's Guide

This PR replaces Black with Ruff for formatting and linting, updates pre-commit and project configs, refactors CI and nox workflows to streamline dependency installation and add Ruff lint/format sessions, enhances the Sphinx docs build config for cleaner exception handling and formatting, and migrates the Poetry build backend to poetry-core.

Sequence Diagram: Pre-commit Workflow with Ruff and Taplo

sequenceDiagram
    actor Dev as Developer
    participant Git
    participant PreCommit as Pre-commit Framework
    participant RuffFormat as Ruff Formatter
    participant RuffLint as Ruff Linter
    participant TaploFormat as Taplo Formatter

    Dev->>Git: git commit
    Git->>PreCommit: Execute hooks
    PreCommit->>RuffFormat: Run ruff format
    RuffFormat-->>PreCommit: Formatting applied/checked
    PreCommit->>RuffLint: Run ruff check --fix
    RuffLint-->>PreCommit: Linting issues fixed/reported
    PreCommit->>TaploFormat: Run taplo format (on TOML files)
    TaploFormat-->>PreCommit: TOML formatting applied/checked
    alt All hooks pass
        PreCommit-->>Git: Hooks successful
        Git-->>Dev: Commit successful
    else Some hooks fail
        PreCommit-->>Git: Hooks failed
        Git-->>Dev: Commit failed, fix issues
    end
Loading

Sequence Diagram: CI Pipeline Execution with Nox, Ruff, and Mypy

sequenceDiagram
    actor User as Developer
    participant GitHub
    participant GHA as GitHub Actions
    participant Nox
    participant RuffFormat as Ruff Format Check
    participant RuffLint as Ruff Lint Check
    participant Mypy
    participant Pytest

    User->>GitHub: Push code / Create PR
    GitHub->>GHA: Trigger CI Workflow
    GHA->>Nox: Setup Environment & Invoke Nox
    Nox->>RuffFormat: Run 'ruff_format' session
    RuffFormat-->>Nox: Format Check Status (reports diff if not formatted)
    Nox->>RuffLint: Run 'ruff_lint' session
    RuffLint-->>Nox: Lint Check Status (reports issues)
    Nox->>Mypy: Run 'mypy' session
    Mypy-->>Nox: Type Check Status
    Nox->>Pytest: Run 'tests' session(s)
    Pytest-->>Nox: Test Results
    Nox-->>GHA: Overall Status
    GHA-->>GitHub: Report CI Status (Success/Failure)
Loading

File-Level Changes

Change Details Files
Replace Black with Ruff and update related configurations
  • Removed Black dependency and config blocks
  • Added tool.ruff settings (formatting and linting rules) in pyproject.toml
  • Updated pre-commit hooks to use ruff-check and ruff-format
  • Adjusted GitHub Ruff extension config under lint.extend-ignore
pyproject.toml
.pre-commit-config.yaml
.github/pyproject.toml
Refactor and extend Nox sessions to support Ruff
  • Introduced poetry_install_run_always helper for consistent installs
  • Updated test and mypy sessions to use the new helper
  • Added Ruff Lint and Ruff Format sessions with appropriate flags
noxfile.py
Update GitHub Actions workflow to run lint and format
  • Adjusted pull_request triggers and branch filters
  • Renamed Lint job and added format step
  • Ensured .mypy_cache directory is created before linting
.github/workflows/test.yml
Clean up Sphinx docs configuration
  • Replaced bare try/except with suppress context manager for rmtree
  • Converted print statements to f-strings with noqa comments
  • Reformatted html_theme_options and LaTeX document tuples for consistency
docs/conf.py

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

@Ckk3 Ckk3 requested review from bellini666 and patrick91 May 18, 2025 00:57
@botberry
Copy link
Member

botberry commented May 18, 2025

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release does not introduce any new features or bug fixes. It focuses solely on internal code quality improvements.

Changes:

  • Added Mypy configuration aligned with the main Strawberry project.
  • Enforced type checking via CI to ensure consistency.
  • Ran pre-commit across all files to standardize formatting and follow the project's linting architecture.

These changes aim to improve maintainability and ensure better development practices moving forward.

@codecov-commenter
Copy link

codecov-commenter commented May 18, 2025

Codecov Report

Attention: Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Project coverage is 89.48%. Comparing base (7f2cbaf) to head (3230fd4).

Additional details and impacted files
@@                          Coverage Diff                          @@
##           pre-commit-lint-and-format-update     #248      +/-   ##
=====================================================================
- Coverage                              89.94%   89.48%   -0.47%     
=====================================================================
  Files                                     17       17              
  Lines                                   1939     1949      +10     
  Branches                                 141      141              
=====================================================================
  Hits                                    1744     1744              
- Misses                                   123      133      +10     
  Partials                                  72       72              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

codspeed-hq bot commented May 18, 2025

CodSpeed Performance Report

Merging #248 will not alter performance

Comparing Ckk3:update-precommit-and-ci-only (3230fd4) with main (7f2cbaf)

Summary

✅ 1 untouched benchmarks

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @Ckk3 - I've reviewed your changes - here's some feedback:

  • In docs/conf.py you use with suppress(FileNotFoundError): but I don’t see from contextlib import suppress—make sure to import suppress or this will error.
  • Rather than shelling out to poetry install in every Nox session, consider using nox-poetry’s built-in session.install() or session.poetry_install() for faster, cache-friendly installs.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Documentation: all looks good

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.

@Ckk3 Ckk3 changed the base branch from main to pre-commit-lint-and-format-update May 18, 2025 01:08
@Ckk3 Ckk3 merged commit de74f94 into strawberry-graphql:pre-commit-lint-and-format-update May 20, 2025
18 of 19 checks passed
@Ckk3 Ckk3 mentioned this pull request May 24, 2025
11 tasks
Ckk3 added a commit that referenced this pull request May 24, 2025
* Update pre-commit and CI to ensure format and lint (#248)

* Adding the changes we made in precommit, poetry, nox

* add release.md

* Update pre-commit to all files and Mypy setup (#247)

* Update pre-commit and mypy .ini just like the main strawberry project

* add a lint error on purpose to test lint

* add a release md and add file attr to tmol pre-commit

* fix test action to run when a PR is ready for review

* test mappe

* fix action

* continue with tests in lint in nox file

* remove pydantic.mypy plugin

* made first lint ajustment, but still missing lint test

* add ruff and black to lint te

* Fix nox file and add ruff to pyptoject toml

* fix poetry lock

* fix command to raise error

* make ruff output errors

* bring back black to pre-commit

* remove --diff from ruff because we want to run in all files, remove invalid rules in lint

* update pre-commit to ruff run lint and formatter

* separate ruff lint from formater in noxfile

* remove test function from mapper

* remove black and use only ruff

* add lint tag to ruff format in nox

* change test.yml to run lint and format divided

* Run pre-commit in all files and made line-lenght 100

* updated ruff check

* update pyproject.toml

* Made sourcery fixes

* remove unecessary else

* bring back session._session
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants