-
Notifications
You must be signed in to change notification settings - Fork 161
CHORE: Setting up ruff #6157
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
CHORE: Setting up ruff #6157
Conversation
… (no formatting), enforce I(sort) rule
Thanks for opening a Pull Request. If you want to perform a review write a comment saying: @ansys-reviewer-bot review |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6157 +/- ##
==========================================
+ Coverage 84.41% 85.25% +0.84%
==========================================
Files 170 170
Lines 64119 64119
==========================================
+ Hits 54125 54666 +541
+ Misses 9994 9453 -541 🚀 New features to boost your workflow:
|
…nfig and update files accordingly
…nored ruff linting rules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @ecoussoux-ansys ! I left some minor changes that need to be taken care of before merging
Co-authored-by: Sébastien Morais <[email protected]>
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Sébastien Morais <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Description
This PR introduces the use of
ruff
for linting and formatting, replacingisort
,black
andflake8
.ruff
is an extremely fast Python linter and code formatter, that integrates the functionalities of several tools behind a single, common interface (https://docs.astral.sh/ruff/)Its implementation in pyaedt was suggested in issue #4775.
This PR can also be seen as contributing to the efforts described in issue #5504.
It should be noted that
ruff
does not replace the following tools, whose use in the project is therefore not affected by the changes made in this PR:blacken-docs
(used for formatting Python code blocks in documentation files):ruff
does not support formatting/linting of embedded code (particularly in.rst
or.md
files, see ☂️ Formatter: Support formatting of embedded code astral-sh/ruff#8237). Similarly,blacken-docs
does not support theruff
formatter as an alternative forblack
(see Support Ruff formatter as an alternative for Black adamchainz/blacken-docs#352). This tool is therefore retained (as a pre-commit hook), despite the remaining dependence onblack
,codespell
(fixes common misspellings in source code and other files): Is not integrated intoruff
(see Request: Spelling check astral-sh/ruff#1628),numpydoc
(used for formatting docstrings): Is also not integrated intoruff
(see Feature request: numpydoc rules astral-sh/ruff#8425).The changes in this PR are limited to the definition of a minimal configuration for
ruff
(in thepyproject.toml
file) with only a few rules applied to the code base, together with the introduction of pre-commit hooks for linting and formatting withruff
. Python files fixed byruff
are updated. Configurations forisort
,black
andflake8
are removed and the associated pre-commit hooks are also dropped.The currently ignored rules shall be gradually applied to the project in subsequent PRs. For this task, a useful command-line instruction can be used, which will return the number of errors flagged for each selected rule as well as the availability of automatic fixes :
ruff check . --statistics
It is also worth mentioning that the list of rules selected until now for linting in the
.flake8
file is not regarded as a reference for defining theruff
configuration implemented. Instead, this config is based on the recommendations from the pyansys-dev-guide, as introduced in ansys/pyansys-dev-guide#592.Furthermore, the enforcement of ‘PTH’ type rules is not a priority as part of the introduction of
ruff
to the project, as an effort in this direction is currently underway as described in issue #5180.Issue linked
Related to #4775 and #5504.