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

Use ruff to improve code quality #2741

Closed
seisman opened this issue Oct 12, 2023 · 4 comments
Closed

Use ruff to improve code quality #2741

seisman opened this issue Oct 12, 2023 · 4 comments
Labels
maintenance Boring but important stuff for the core devs
Milestone

Comments

@seisman
Copy link
Member

seisman commented Oct 12, 2023

It seems ruff has been very hot recently. The README says it can replace flake8 and pylint, and more importantly, it's 10-100x faster.

Someone interested may try it and tell us how it works for the PyGMT project.

@seisman seisman added the question Further information is requested label Oct 12, 2023
@weiji14
Copy link
Member

weiji14 commented Oct 15, 2023

Opened a PR to replace flakeheaven and isort with ruff at #2747, so that we can move ahead with the Python 3.12 support.

It should also be possible to replace pylint with ruff (see https://docs.astral.sh/ruff/faq/#how-does-ruff-compare-to-pylint), which would:

  • Pro:
    • Allow us to remove make lint (which is slow) from the Makefile (i.e. only have make check and make format)
    • Bonus is that ruff can actually automatically fix some pylint rules (see those marked with 🛠️ at https://docs.astral.sh/ruff/rules/#pylint-pl)
  • Con: Not all pylint rules are applied (see Implement Pylint astral-sh/ruff#970), but I'm not sure if we even need to check all of them...

So should we replace pylint with ruff? Vote 👍 for yes, 👎 for no. If everyone is generally in favour, we can open a PR after #2747 is merged.

@seisman seisman added maintenance Boring but important stuff for the core devs and removed question Further information is requested labels Oct 16, 2023
@seisman
Copy link
Member Author

seisman commented Oct 16, 2023

So should we replace pylint with ruff?

Instead of replacing pylint with ruff, I think we can use both to see if there are any linting issues reported by pylint but not detected by ruff. We can then decide if we want to remove pylint before releasing v0.11.0. So I propose to have two separate PRs:

  • Configure ruff as a linting tool
  • Remove pylint before v0.11.0

@seisman seisman added this to the 0.11.0 milestone Oct 16, 2023
@seisman
Copy link
Member Author

seisman commented Nov 9, 2023

ruff supports many groups of rules (https://docs.astral.sh/ruff/rules/). I think we should go through the available rules and apply the rules that make sense to our project.

ruff v0.1.8 provides the following linters/rules:

ruff linter | awk '{printf("- [ ] [`%s`](https://docs.astral.sh/ruff/rules/#%s-%s): %s\n"), $1, tolower($2), tolower($1), $2}' 

@seisman
Copy link
Member Author

seisman commented Dec 21, 2023

I've enabled ~32 rulesets that make sense to our project. Closing the issue now and we may revisit it in the feature if new ruff versions provide more rulesets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Boring but important stuff for the core devs
Projects
None yet
Development

No branches or pull requests

2 participants