Skip to content

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

Merged
Ckk3 merged 28 commits intostrawberry-graphql:pre-commit-lint-and-format-updatefrom
Ckk3:run-precommit-in-all-files
May 24, 2025
Merged

Update pre-commit to all files and Mypy setup#247
Ckk3 merged 28 commits intostrawberry-graphql:pre-commit-lint-and-format-updatefrom
Ckk3:run-precommit-in-all-files

Conversation

@Ckk3
Copy link
Copy Markdown
Contributor

@Ckk3 Ckk3 commented May 15, 2025

Description

This PR introduces a mypy configuration similar to the one used in the main Strawberry project, and integrates a type-checking step into the CI workflows to ensure type safety is enforced consistently across the codebase.

Additionally, I ran pre-commit on all files, as many had not been formatted previously and did not follow the project's linting architecture. This helps standardize the codebase and reduce noise in future diffs.

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

Enforce consistent code style and type safety by running pre-commit across the codebase, integrating a shared mypy configuration with CI type-checking, and consolidating linting/formatting into Ruff

Enhancements:

  • Add mypy configuration aligned with the main Strawberry project and enforce type checking in CI
  • Standardize formatting by applying pre-commit to all files
  • Migrate linting and formatting hooks from Black/isort to Ruff

Build:

  • Switch Poetry build backend to poetry-core in pyproject.toml

CI:

  • Introduce mypy, ruff-lint, and ruff-format sessions in nox and update GitHub Actions to run lint, format, and type-check triggers

Documentation:

  • Clean up Sphinx conf.py formatting and update documentation build settings

Chores:

  • Add RELEASE.md outlining internal code quality improvements

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented May 15, 2025

Reviewer's Guide

Integrate Mypy type checking and Ruff-based linting/formatting into CI and project configuration, migrate build backend to poetry-core, apply pre-commit across all files, and standardize code and documentation formatting.

File-Level Changes

Change Details Files
Integrate Mypy type checking into CI workflows
  • Introduce a mypy configuration aligned with the main Strawberry project
  • Define a Mypy nox session that installs types non-interactively and uses a dedicated cache directory
  • Integrate the Mypy step into GitHub Actions pull_request triggers
noxfile.py
.github/workflows/test.yml
pyproject.toml
Replace Black with Ruff and enforce standardized linting/formatting
  • Update pre-commit hooks to run ruff-check for linting and ruff-format for formatting
  • Remove Black from dependencies and configure Ruff settings (line length, ignore rules, per-file ignores)
  • Apply ruff fixes across the entire codebase via pre-commit
.pre-commit-config.yaml
pyproject.toml
.github/pyproject.toml
Switch Poetry build backend to poetry-core
  • Change build-system requires to use poetry-core
  • Update the build-backend to poetry.core.masonry.api
pyproject.toml
Refactor code style for consistency across source and tests
  • Condense multi-line list comprehensions and conditionals into single-line expressions
  • Standardize type cast annotations to string-literal forms and simplify lambda definitions
  • Clean up exception messages and remove unnecessary line breaks
src/strawberry_sqlalchemy_mapper/mapper.py
src/strawberry_sqlalchemy_mapper/field.py
src/strawberry_sqlalchemy_mapper/loader.py
src/strawberry_sqlalchemy_mapper/relay.py
src/strawberry_sqlalchemy_mapper/utils.py
tests/
Update documentation and release notes
  • Refine Sphinx conf.py to use context managers and f-strings
  • Add a new RELEASE.md summarizing internal code quality improvements
  • Adjust Dependabot settings and streamline CHANGELOG formatting
docs/conf.py
RELEASE.md
.github/dependabot.yml
CHANGELOG.md

Assessment against linked issues

Issue Objective Addressed Explanation

Possibly linked issues


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 marked this pull request as ready for review May 15, 2025 15:54
@botberry
Copy link
Copy Markdown
Member

botberry commented May 15, 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.

Copy link
Copy Markdown
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:

  • Remove the test_without_pre_commit dummy function before merging, as it’s only intended to trigger lint failures.
  • Add a mypy type‐checking step to your CI workflows (e.g. GitHub Actions) to ensure the new mypy.ini is actually enforced.
  • Make sure the pydantic mypy plugin is added to the project’s dev dependencies so mypy can load it successfully.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟡 Testing: 1 issue found
  • 🟢 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.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented May 15, 2025

CodSpeed Performance Report

Merging #247 will not alter performance

Comparing Ckk3:run-precommit-in-all-files (29f86c6) with main (7f2cbaf)

Summary

✅ 1 untouched benchmarks

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 15, 2025

Codecov Report

Attention: Patch coverage is 58.06452% with 26 lines in your changes missing coverage. Please review.

Project coverage is 89.72%. Comparing base (7f2cbaf) to head (29f86c6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #247      +/-   ##
==========================================
- Coverage   89.94%   89.72%   -0.23%     
==========================================
  Files          17       17              
  Lines        1939     1936       -3     
  Branches      141      145       +4     
==========================================
- Hits         1744     1737       -7     
- Misses        123      125       +2     
- Partials       72       74       +2     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ckk3 Ckk3 changed the title Update pre-commit to all files and Mypy setup [NOT READY FOR REVIEW] Update pre-commit to all files and Mypy setup May 15, 2025
@Ckk3
Copy link
Copy Markdown
Contributor Author

Ckk3 commented May 17, 2025

@sourcery-ai review

@Ckk3
Copy link
Copy Markdown
Contributor Author

Ckk3 commented May 17, 2025

@sourcery-ai summary

Copy link
Copy Markdown
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.

We encountered an error and are unable to review this PR. We have been notified and are working to fix it.

You can try again by commenting this pull request with @sourcery-ai review, or contact us for help.

@Ckk3
Copy link
Copy Markdown
Contributor Author

Ckk3 commented May 17, 2025

@sourcery-ai review

Copy link
Copy Markdown
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:

  • This PR bundles extensive config and formatting changes—consider splitting into separate PRs (e.g., one for pre-commit/ruff setup, another for mypy integration, and a third for code formatting) to simplify review.
  • The current ruff.ignore list is very broad; pruning these ignores gradually will help tighten lint enforcement and catch more issues moving forward.
  • In your CI mypy step, consider enabling stricter flags (e.g. --strict or enabling missing imports/stubs reporting) to enforce stronger type safety across the codebase.
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.

Copy link
Copy Markdown
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 and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues 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 title [NOT READY FOR REVIEW] Update pre-commit to all files and Mypy setup Update pre-commit to all files and Mypy setup May 18, 2025
@Ckk3 Ckk3 marked this pull request as draft May 18, 2025 00:33
@Ckk3 Ckk3 changed the base branch from main to pre-commit-lint-and-format-update May 18, 2025 01:08
@Ckk3 Ckk3 self-assigned this May 20, 2025
@Ckk3 Ckk3 marked this pull request as ready for review May 20, 2025 13:42
@Ckk3 Ckk3 requested review from bellini666 and patrick91 May 20, 2025 13:42
Copy link
Copy Markdown
Member

@bellini666 bellini666 left a comment

Choose a reason for hiding this comment

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

Nice! :)

@Ckk3 Ckk3 merged commit 38c8189 into strawberry-graphql:pre-commit-lint-and-format-update May 24, 2025
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.

Add mypy setup like the main strawberry project

4 participants