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

Update to ruff (instead of pylint (and isort)) #192

Merged
merged 22 commits into from
Dec 14, 2023
Merged

Conversation

CasperWA
Copy link
Collaborator

@CasperWA CasperWA commented Oct 9, 2023

Closes #191

Remove pylint as a dependency.
Remove all "# pylint: disable=..." statements.
Remove pylint and isort as pre-commit hooks.
Add ruff as a pre-commit hook.
Avoid running pylint in the CI.
Add a 'ruff' CI job.

Add (back) disable E501 statements.
E501: Line too long.
Add it for either lines with string-formatted type (which has to be on one line) or an f-string with a single variable (i.e., a single-line f-string part with an implemented logic for a variable that results in the line being too long).

Also, add pyupgrade as a pre-commit hook and enfore importing __future__.annotations in all Python files.

Remove pylint as a dependency.
Remove all "# pylint: disable=..." statements.
Remove pylint and isort as pre-commit hooks.
Add ruff as a pre-commit hook.
Avoid running pylint in the CI.
Add a 'ruff' CI job.

Add (back) disable E501 statements.
E501: Line too long.
Add it for either lines with string-formatted type (which has to be on
one line) or an f-string with a single variable (i.e., a single-line
f-string part with an implemented logic for a variable that results in
the line being too long).
@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (ddda034) 81.06% compared to head (40d3a23) 81.29%.

Files Patch % Lines
ci_cd/utils/versions.py 93.93% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #192      +/-   ##
==========================================
+ Coverage   81.06%   81.29%   +0.22%     
==========================================
  Files          12       12              
  Lines         898      909      +11     
==========================================
+ Hits          728      739      +11     
  Misses        170      170              

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

CasperWA and others added 2 commits October 16, 2023 10:23
Copy link
Contributor

@francescalb francescalb left a comment

Choose a reason for hiding this comment

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

It looks fine, but I do not understand how come we now can remove all these different disable statements. Is ruff less strict?

@CasperWA
Copy link
Collaborator Author

It looks fine, but I do not understand how come we now can remove all these different disable statements. Is ruff less strict?

This is a good point - something I've thought glancingly about as well.
A closer read of the tutorial reveals that the default rule set is similar to standard flake8 usage (not pylint). We should probably experiment with the rule set selection and come up with one that suits us? Something like adding all isort and pylint rules.

Extend arguments to ruff CLI, ensuring no unsafe fixes are made and any
fixes are shown explicitly in the output.
Extend rule set for job on code base to include flake8-blind-except and
pylint.
Ignore self assignment of variable rule.
Ignore all too-many-* rules from pylint, because we will extend the
recommended number of branches, statements, function args, etc. in this
code base.

Otherwise, run with a rule set that includes pycodestyle, pyflakes,
pyupgrade, flake8-bugbear, flake8-simplify, isort, and ruff.
@CasperWA
Copy link
Collaborator Author

CasperWA commented Oct 25, 2023

It looks fine, but I do not understand how come we now can remove all these different disable statements. Is ruff less strict?

This is a good point - something I've thought glancingly about as well. A closer read of the tutorial reveals that the default rule set is similar to standard flake8 usage (not pylint). We should probably experiment with the rule set selection and come up with one that suits us? Something like adding all isort and pylint rules.

So, in relation to this comment, I have now tried to explicitly define some rules. It indeed again ended up in having to have two separate pre-commit jobs (if we want linting on non-code base files as well, i.e., tests). This has ended up showing that the previous pylint rules were indeed not checked (but are now). I have disabled some of them globally (see the pre-commit config file), but otherwise, this rule set should be configured specifically for the package.
For example, DLite and OTEAPI Core would benefit from explicit NumPy linting rules and such.

The full list of ruff rules to be used can be found here.

Also:
- Remove pyupgrade (UP) rule for ruff.
  An actual pyupgrade hook should be used instead.
- Remove bandit (S) rule for ruff hooks for core code base.
  The bandit hook takes care of these.
- Update hook versions.
- Switch hook activation order; run black before ruff.
- Add python_version-specific pre-commit version in the 'dev' extra.
- Add a typing.NamedTuple for an ignore entry pair.
  This is used to minimize mypy ignore statements.
Enforce importing __future__.annotations in all Python files.
Update code accordingly.
@CasperWA
Copy link
Collaborator Author

For reference, this may be a nice guide on which rules to use (and general Python code styling) https://learn.scientific-python.org/development/guides/style/.

Copy link
Contributor

@daniel-sintef daniel-sintef left a comment

Choose a reason for hiding this comment

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

I didn't notice any comments that weren't already covered by @francescalb (and addressed)

@CasperWA CasperWA merged commit e4b2cc9 into main Dec 14, 2023
24 checks passed
@CasperWA CasperWA deleted the cwa/close-191-use-ruff branch December 14, 2023 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use ruff instead of pylint (and isort) in code base
3 participants