-
Notifications
You must be signed in to change notification settings - Fork 87
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
Format and lint Python code with ruff #533
Conversation
.github/workflows/lint_python.yml
Outdated
- run: pip install codespell mypy pytest ruff | ||
- run: codespell --ignore-words-list="commend" | ||
- run: ruff format --check | ||
- run: ruff check --output-format=github --select=ALL |
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.
Why both ruff format --check
and ruff check ...
?
Also: is there a reason to keep these as separate single-line - run:
commands rather than a - run: |
section?
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.
Updated to use single quotes.
Ruff format and Ruff check (lint) are two separate commands.
The overhead of multiple run:
commands is minimal and I find it useful to rapidly see if formatting was the failing step vs. linting.
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.
If I understand correctly, ruff format --check
will not actually do anything, it is informational. Is it typical to dump that information to a CI log? Perhaps we could do without it.
The ruff check
step emits warnings. Can those be silenced?
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.
ruff format --check
will fail the build if code is not formatted. We are removing black
so I think we want something similar. ruff format --diff
would be an alternate approach.
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.
Often https://pre-commit.com and https://commit.ci are used for sub-second tests like linting and formatting. The combination will allow ruff to --fix or reformat any fixable or unformatted code and add those changes as a new commit to an existing pull request.
Thanks @cclauss |
Replace bandit, black, flake8, flake8-2020, flake8-bugbear, flake8-comprehensions, isort, and pyupgrade with ruff.
https://docs.astral.sh/ruff