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

Format and lint Python code with ruff #533

Merged
merged 2 commits into from
Oct 23, 2024
Merged

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Oct 23, 2024

Replace bandit, black, flake8, flake8-2020, flake8-bugbear, flake8-comprehensions, isort, and pyupgrade with ruff.

https://docs.astral.sh/ruff

Ruff can be used to replace Flake8 (plus dozens of plugins), Black, isort, pydocstyle, pyupgrade, autoflake, and more, all while executing tens or hundreds of times faster than any individual tool.

- 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
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

@cclauss cclauss Oct 23, 2024

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.

supported_wheels.py Outdated Show resolved Hide resolved
@mattip mattip merged commit 8a9333e into multi-build:devel Oct 23, 2024
3 of 4 checks passed
@mattip
Copy link
Collaborator

mattip commented Oct 23, 2024

Thanks @cclauss

@cclauss cclauss deleted the ruff branch October 23, 2024 11:46
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.

2 participants