-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from isort/Black/Flake8 to Ruff for Code Formatting and Linti…
…ng (#5424) #### 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 1. **GitHub Actions Workflow** - Updated `.github/workflows/lint.yml` to use `poetry install --only=lint` and `poe lint --output-format=github`. 2. **Pre-commit Configuration** - Replaced Black and Isort with Ruff in `.pre-commit-config.yaml`. 3. **Documentation** - Updated `CONTRIBUTING.rst` to reflect the use of Ruff for formatting and linting. - Modified instructions for running tests and handling external API requests. 4. **Poetry Configuration** - Removed Black, Isort, Flake8, and related dependencies from `poetry.lock` and `pyproject.toml`. - Added Ruff as the new linter and formatter in `pyproject.toml`. 5. **Setup Configuration** - Removed Flake8 configuration from `setup.cfg`. 6. **Git blame** - Introduced `.git-blame-ignore-revs` file to keep git blame clean from formatting changes. Configure your local `beets` repository to use this file by running: ```fish $ git config --local blame.ignoreRevsFile .git-blame-ignore-revs ``` #### Benefits - **Performance**: Ruff is known for its speed and efficiency, which should improve the developer experience. - **Consolidation**: Using a single tool for both formatting and linting simplifies the development workflow. #### How to Test 1. **Linting and Formatting** - Run `poe check-format` to check for formatting issues. - Run `poe format` to format the codebase. - Run `poe lint` to check for linting issues. 2. **Pre-commit Hooks** - Ensure pre-commit hooks are working correctly by running `pre-commit run --all-files`. 3. **CI Pipeline** - Verify that the GitHub Actions workflow completes successfully. #### Notes - Contributions migrating existing tests from `unittest` to `pytest` are welcome. - External API requests should be mocked using `requests_mock` and tested weekly in the integration test suite. #### References - [Ruff Documentation](https://docs.astral.sh/ruff/) - [Pre-commit Hooks](https://pre-commit.com/hooks.html) --- This PR aims to streamline our development process by adopting Ruff, a modern and efficient tool for Python code formatting and linting.
- Loading branch information
Showing
121 changed files
with
555 additions
and
795 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# 2014 | ||
# flake8-cleanliness in missing | ||
e21c04e9125a28ae0452374acf03d93315eb4381 | ||
|
||
# 2016 | ||
# Removed unicode_literals from library, logging and mediafile | ||
43572f50b0eb3522239d94149d91223e67d9a009 | ||
# Removed unicode_literals from plugins | ||
53d2c8d9db87be4d4750ad879bf46176537be73f | ||
# reformat flake8 errors | ||
1db46dfeb6607c164afb247d8da82443677795c1 | ||
|
||
# 2021 | ||
# pyupgrade root | ||
e26276658052947e9464d9726b703335304c7c13 | ||
# pyupgrade beets dir | ||
6d1316f463cb7c9390f85bf35b220e250a35004a | ||
# pyupgrade autotag dir | ||
f8b8938fd8bbe91898d0982552bc75d35703d3ef | ||
# pyupgrade dbcore dir | ||
d288f872903c79a7ee7c5a7c9cc690809441196e | ||
# pyupgrade ui directory | ||
432fa557258d9ff01e23ed750f9a86a96239599e | ||
# pyupgrade util dir | ||
af102c3e2f1c7a49e99839e2825906fe01780eec | ||
# fix unused import and flake8 | ||
910354a6c617ed5aa643cff666205b43e1557373 | ||
# pyupgrade beetsplug and tests | ||
1ec87a3bdd737abe46c6e614051bf9e314db4619 | ||
|
||
# 2022 | ||
# Reformat flake8 config comments | ||
abc3dfbf429b179fac25bd1dff72d577cd4d04c7 | ||
|
||
# 2023 | ||
# Apply formatting tools to all files | ||
a6e5201ff3fad4c69bf24d17bace2ef744b9f51b | ||
|
||
# 2024 | ||
# Reformat the codebase | ||
85a17ee5039628a6f3cdcb7a03d7d1bd530fbe89 | ||
# Fix lint issues | ||
f36bc497c8c8f89004f3f6879908d3f0b25123e1 | ||
# Remove some lint exclusions and fix the issues | ||
5f78d1b82b2292d5ce0c99623ba0ec444b80d24c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
`python -m beets`. | ||
""" | ||
|
||
|
||
import sys | ||
|
||
from .ui import main | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
music and items' embedded album art. | ||
""" | ||
|
||
|
||
import os | ||
from tempfile import NamedTemporaryFile | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.