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

Introducing ruff as a linter to replace pylint, flake8 and isort #2634

Merged
merged 45 commits into from
Jul 26, 2023

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Jun 2, 2023

Signed-off-by: Nok nok.lam.chan@quantumblack.com

NOTE: Kedro datasets are moving from kedro.extras.datasets to a separate kedro-datasets package in
kedro-plugins repository. Any changes to the dataset implementations
should be done by opening a pull request in that repository.

Description

The goal for this is to use ruff to replace pylint, we should aim at compatible (99.9%) for this scope. We can decide later rather we should enable extra rule set.

ruff is much fast than pylint, which kills dev productivity for trivial changes. black will be kept because ruff is not a formatter although it can flag issues with formatting.

Development notes

  • Update linting.md
  • Remove isort,flake8,pylint from our CI (noted the dependencies are still here because we only deprecate kedro lint in 0.19.0`

Checklist

  • Read the contributing guidelines
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added a description of this change in the RELEASE.md file
  • Added tests to cover my changes

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Jun 2, 2023

Playing around with it, it's amazingly fast. I get confused a little bit with max-length. It seems that it can only warn the line is too long but couldn't fix it.

So I configure it to ignore E501(line-length), and just run black over it instead. There are subtle difference so they are not 1:1 mapping, but I guess black is doing a good job there and I am not worry about it.

noklam added 2 commits June 2, 2023 15:35
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam noklam changed the title Draft - remove pylint Draft - remove pylint with ruff Jul 3, 2023
@noklam noklam added Help Wanted 🙏 Contribution task, outside help would be appreciated! Community Issue/PR opened by the open-source community labels Jul 3, 2023
noklam added 6 commits July 3, 2023 13:14
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
…nto replace-pylint

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam noklam changed the title Draft - remove pylint with ruff Introducing ruff as a linter and replace pylint, flake8 and isort Jul 3, 2023
@noklam noklam self-assigned this Jul 3, 2023
@noklam noklam requested review from astrojuanlu and deepyaman July 3, 2023 17:05
@noklam noklam marked this pull request as ready for review July 3, 2023 17:05
@noklam noklam requested a review from idanov as a code owner July 3, 2023 17:05
@noklam
Copy link
Contributor Author

noklam commented Jul 3, 2023

To test this you can still uncomment the existing setup. They are mostly identical but with some slight difference as ruff is not a 100% replacement to the existing tools.

@datajoely
Copy link
Contributor

❤️

@astrojuanlu
Copy link
Member

This still calls pylint right? Maybe we can remove it from CI to see the difference in execution times

@noklam noklam changed the title Introducing ruff as a linter and replace pylint, flake8 and isort Introducing ruff as a linter to replace pylint, flake8 and isort Jul 3, 2023
noklam added 2 commits July 3, 2023 23:04
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Jul 3, 2023

@astrojuanlu Ruff run almost instantly compare to pylint :) I have removed it from the pre-commit config now.

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@@ -20,7 +20,6 @@ holoviews~=1.13.0
import-linter[toml]==1.8.0
ipython>=7.31.1, <8.0; python_version < '3.8'
ipython~=8.10; python_version >= '3.8'
isort~=5.0
Jinja2<3.1.0
joblib>=0.14
jupyterlab_server>=2.11.1, <2.16.0 # 2.16.0 requires importlib_metedata >= 4.8.3 which conflicts with flake8 requirement
Copy link
Member

Choose a reason for hiding this comment

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

Does this mean that we don't need to cap jupyterlab_server anymore?

Copy link
Member

Choose a reason for hiding this comment

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

xref #2700

noklam added 4 commits July 18, 2023 17:21
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
… of `else` then `if`, to reduce indentation

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Jul 18, 2023

There are many linting error, many of them are not difference between ruff and pylint but rather we are using old pylint version.

For the changes that are obvious and meaningful, I have applied the changes and suppressed the rest.

For example, this is a good fix hinted by ruff e0275f0.

@noklam noklam marked this pull request as ready for review July 18, 2023 17:33
@noklam noklam requested review from merelcht and stichbury and removed request for stichbury July 18, 2023 17:34
@noklam noklam marked this pull request as draft July 18, 2023 17:42
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam noklam marked this pull request as ready for review July 18, 2023 17:45
name: "ruff on tests/ and docs/"
# PLR2004: Magic value used
# PLR0913: Too many arguments
args: ["--fix", "--exit-non-zero-on-fix", "--ignore=PLR2004,PLR0913"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Ruff allows you to have different sets of rules for these cases. Run the linter once, and select/ignore rules for testing.

For an example, check GitHub.com/ing-bank/popmon

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sbrugman Could you share a link? Not sure if I missed anything, I checked their config but it does not use any arguments.

https://github.com/ing-bank/popmon/blob/ac79d212a519368d01525950142e0a282f5287c3/.pre-commit-config.yaml#L6-L10

Copy link
Contributor

Choose a reason for hiding this comment

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

See the section [tool.ruff.per-file-ignores] in pyproject.toml

.pre-commit-config.yaml Show resolved Hide resolved
docs/source/development/linting.md Outdated Show resolved Hide resolved
docs/source/development/linting.md Outdated Show resolved Hide resolved
noklam added 3 commits July 18, 2023 23:12
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Copy link
Member

@merelcht merelcht left a comment

Choose a reason for hiding this comment

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

Great work @noklam ⭐ I went through most of the changed files and can see that the changes minimal and mostly just changing # pylint: disable to # noqa.

noklam added 2 commits July 20, 2023 13:41
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Jul 20, 2023

I don't want this PR stuck forever, since this is already very useful to speed up dev.

Follows up:

  • See the section [tool.ruff.per-file-ignores] in pyproject.toml
  • Replace bandit with ruff

@astrojuanlu
Copy link
Member

I agree it would be super cool to get this in ASAP. Plugins can follow suit.

See the section [tool.ruff.per-file-ignores] in pyproject.toml

Just to clarify, is that something you want to do in this PR for the CI to pass?

@noklam
Copy link
Contributor Author

noklam commented Jul 20, 2023

No, I will save this for future PRs.

The lining is still failing for weird reason, I cannot reproduce it anywhere so I may have to ssh into it.

Other than that it's block by the E2e test.

@noklam
Copy link
Contributor Author

noklam commented Jul 20, 2023

The unsort import error is mysteriou, I cannot reproduce it anywhere. It's not important at all so I silent this error for the micropkg.py.

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Jul 20, 2023

Linting now all pass, only blocked by #2816, enable auto-merge.

@noklam noklam enabled auto-merge (squash) July 20, 2023 22:48
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.

6 participants