CHORE: Setting up ruff#6157
Merged
Merged
Conversation
… (no formatting), enforce I(sort) rule
Contributor
|
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
SMoraisAnsys
requested changes
May 19, 2025
Collaborator
SMoraisAnsys
left a comment
There was a problem hiding this comment.
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 <146729917+SMoraisAnsys@users.noreply.github.com>
This was referenced May 20, 2025
SMoraisAnsys
approved these changes
May 22, 2025
jsalant22
pushed a commit
that referenced
this pull request
Jun 3, 2025
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Co-authored-by: Sébastien Morais <146729917+SMoraisAnsys@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces the use of
rufffor linting and formatting, replacingisort,blackandflake8.ruffis 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
ruffdoes 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):ruffdoes not support formatting/linting of embedded code (particularly in.rstor.mdfiles, see ☂️ Formatter: Support formatting of embedded code astral-sh/ruff#8237). Similarly,blacken-docsdoes not support theruffformatter 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.tomlfile) 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 byruffare updated. Configurations forisort,blackandflake8are 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 . --statisticsIt is also worth mentioning that the list of rules selected until now for linting in the
.flake8file is not regarded as a reference for defining theruffconfiguration 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
ruffto the project, as an effort in this direction is currently underway as described in issue #5180.Issue linked
Related to #4775 and #5504.