Skip to content
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

Migrate black, flake8, isort, pyupgrade linters and formatters to ruff #758

Merged
merged 11 commits into from
Jan 2, 2025

Conversation

kieran-ryan
Copy link
Contributor

@kieran-ryan kieran-ryan commented Dec 31, 2024

🤔 What's changed?

  • Migrated linters flake8, isort, pydocstyle and pyupgrade to ruff
  • Migrated formatter black to ruff
  • Froze pre-commit dependency versions to commit hashes
  • Applied and enforced from __future__ import annotations on all Python modules
  • Updated docstring type hints to match __future__.annotations syntax e.g. List to list, Optional to ... | None
  • Applied codespell spelling corrections

⚡️ What's your motivation?

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)

♻️ Anything particular you want feedback on?

  • Whether suitable to include a recommended VSCode workspace extension or should omit

References

- Configure `ruff` as a drop in replacement for `flake8`, `isort` and `pyupgrade`
- Lint for required `from __future__ import annotations` in `src/`
- Enable automatic fixing of linting errors in pre-commit
- Applied ruff `--fix` for `I001` on `src/pytest_bdd/parser.py`
- Applied ruff `--fix` for `UP032` on `src/pytest_bdd/gherkin_terminal_reporter.py`
- Applied ruff `--fix` for `tests/feature/test_feature_base_dir.py`
- Applied ruff `--fix` for `tests/feature/test_feature_base_dir.py`
- Ignore `B904` error on `src/pytest_bdd/scenario.py`
- Fix invalid pre-commit config error due to indentation syntax error
- Freeze pre-commit dependency versions
- Ensure linting tight feedback loop for contributors
- Applied through ruff `--fix`
- Subsequently simplified optional in `tests/feature/test_report.py`
@Pierre-Sassoulas Pierre-Sassoulas added the internal Internal work label Dec 31, 2024
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Looks great !

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.10%. Comparing base (9ff6980) to head (b96b83e).
Report is 12 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #758      +/-   ##
==========================================
+ Coverage   96.05%   96.10%   +0.05%     
==========================================
  Files          55       55              
  Lines        2359     2390      +31     
  Branches      136      136              
==========================================
+ Hits         2266     2297      +31     
  Misses         56       56              
  Partials       37       37              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kieran-ryan kieran-ryan marked this pull request as ready for review December 31, 2024 19:54
@jsa34
Copy link
Collaborator

jsa34 commented Jan 1, 2025

@youtux we talked about ruff before but I seem to remember you were keen to stick to psf-supported solutions, such as black.

I'll defer to @youtux

Copy link
Contributor

@youtux youtux left a comment

Choose a reason for hiding this comment

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

I'm willing to give it a shot to use ruff, given also pytest started using it.

There's just one thing I'd like to see addressed: I'd want to do as few import as possible inside the if TYPE_CHECKING: block, ideally none at all. The imports we do within that block are pretty much modules that should be already loaded in the interpreter, so the overhead of importing them is negligible.

src/pytest_bdd/scenario.py Outdated Show resolved Hide resolved
@kieran-ryan
Copy link
Contributor Author

kieran-ryan commented Jan 1, 2025

I'm willing to give it a shot to use ruff, given also pytest started using it.

Awesome @youtux!

There's just one thing I'd like to see addressed: I'd want to do as few import as possible inside the if TYPE_CHECKING: block, ideally none at all. The imports we do within that block are pretty much modules that should be already loaded in the interpreter, so the overhead of importing them is negligible.

Makes sense, happy to change. Clarifying my assumptions on scope: revert imports migrated into type checking blocks and revert adding the flake8-type-checking-tc (TC) linting rules (or a subset)?

@youtux
Copy link
Contributor

youtux commented Jan 1, 2025

Yes, both, thank you

@kieran-ryan
Copy link
Contributor Author

Yes, both, thank you

Dropped associated commit and updated pull request description - some of these imports may be dropped with #759 through associated gherkin parser enhancements in any case, so good shout 👍

@youtux youtux enabled auto-merge January 1, 2025 21:55
@youtux youtux merged commit a870b66 into pytest-dev:master Jan 2, 2025
11 checks passed
kieran-ryan added a commit to cucumber/gherkin that referenced this pull request Jan 4, 2025
- Faster tooling
- Better handling with linting rule conflicts
- Enables extending to hundreds of linting rules
- Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
kieran-ryan added a commit to cucumber/gherkin that referenced this pull request Jan 4, 2025
- Faster tooling
- Better handling with linting rule conflicts
- Enables extending to hundreds of linting rules
- Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
kieran-ryan added a commit to cucumber/gherkin that referenced this pull request Jan 5, 2025
- Faster tooling
- Better handling with linting rule conflicts
- Enables extending to hundreds of linting rules
- Aligns with pytest-bdd (pytest-dev/pytest-bdd#758)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Internal work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants