-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Migrate from isort/Black/Flake8 to Ruff for Code Formatting and Linting #5424
Conversation
292996f
to
52507cf
Compare
622ed3c
to
3eb04ba
Compare
ef83264
to
9b6b1e9
Compare
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.
For completeness, I've reviewed every file by hand. In almost all cases, I significantly prefer the changes Ruff has introduced. I'm happy with this PR overall -- well done @snejus!
3eb04ba
to
4d481d7
Compare
d7c656b
to
66bbd67
Compare
Since this PR depends on |
- Fix imports - Fix pytest issues - Do not assign lambda as variable - Use isinstance instead of type to check type - Rename ambiguously named variables - Name custom errors with Error suffix
* Replace `noqa` comments in `assert...` method definitions with a configuration option to ignore these names. * Use the `__all__` variable to specify importable items from the module, replacing `*` imports and `noqa` comments for unused imports. * Address issues with poorly named variables and methods by renaming them appropriately.
The variable in `test_ordered_enum` was flagged for naming issues, and I noticed that `OrderedEnum` is essentially `enum.IntEnum`. I guess `OrderedEnum` exists because it was created before `enum.IntEnum` was made available in Python 3.4. We do not need it anymore though, so it's now gone.
66bbd67
to
8e8f77d
Compare
Above does not apply anymore - I rebased it on |
LGTM, @snejus! |
This commit introduces a `.git-blame-ignore-revs` file to the repository. The purpose of this file is to list specific commit hashes that should be ignored when using the `git blame` command. This is useful for ignoring commits that involve large-scale formatting changes, refactoring, or other non-functional changes that would otherwise clutter the blame history. I added a couple of previous commit hashes which reformatted the code. Configure this repository to use this file: git config --local blame.ignoreRevsFile .git-blame-ignore-revs
8e8f77d
to
11fa6c7
Compare
Great, I have just updated the |
Context
I noticed one of recently merged PRs used
unittest
assertions that we are migrating from. Thus, I thought it would be a good idea to configure our linting to catch such issues in the future. Since I was here, I replaced our multiple linting and formatting tools with a single tool, Ruff, to simplify and speed up our development workflow.Summary
This PR migrates the codebase from using isort, Black and Flake8 to Ruff for code formatting and linting. The changes include updates to the GitHub Actions workflow, pre-commit configuration, and documentation to reflect the new tooling.
Changes
GitHub Actions Workflow
.github/workflows/lint.yml
to usepoetry install --only=lint
andpoe lint --output-format=github
.Pre-commit Configuration
.pre-commit-config.yaml
.Documentation
CONTRIBUTING.rst
to reflect the use of Ruff for formatting and linting.Poetry Configuration
poetry.lock
andpyproject.toml
.pyproject.toml
.Setup Configuration
setup.cfg
.Git blame
.git-blame-ignore-revs
file to keep git blame clean from formattingchanges. Configure your local
beets
repository to use this file by running:$ git config --local blame.ignoreRevsFile .git-blame-ignore-revs
Benefits
How to Test
Linting and Formatting
poe check-format
to check for formatting issues.poe format
to format the codebase.poe lint
to check for linting issues.Pre-commit Hooks
pre-commit run --all-files
.CI Pipeline
Notes
unittest
topytest
are welcome.requests_mock
and tested weekly in the integration test suite.References
This PR aims to streamline our development process by adopting Ruff, a modern and efficient tool for Python code formatting and linting.