Skip to content

Commit

Permalink
Replace isort and black by ruff format
Browse files Browse the repository at this point in the history
  • Loading branch information
snejus committed Sep 21, 2024
1 parent f8ef223 commit 06a5eca
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
cache: poetry

- name: Install dependencies
run: poetry install --only=format
run: poetry install --only=lint

- name: Check code formatting
# the job output will contain colored diffs with what needs adjusting
Expand Down
12 changes: 3 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks

repos:
- repo: https://github.com/psf/black
rev: 24.2.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.6
hooks:
- id: black

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
- id: ruff-format
7 changes: 3 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,13 @@ There are a few coding conventions we use in beets:
Style
-----

We follow `black`_ formatting and `google's docstring format`_.
We use `ruff`_ to format and lint the codebase.

Use ``poe check-format`` and ``poe lint`` to check your code for style and
Run ``poe check-format`` and ``poe lint`` to check your code for style and
linting errors. Running ``poe format`` will automatically format your code
according to the specifications required by the project.

.. _black: https://black.readthedocs.io/en/stable/
.. _google's docstring format: https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings
.. _ruff: https://docs.astral.sh/ruff/

Handling Paths
--------------
Expand Down
76 changes: 1 addition & 75 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 2 additions & 38 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ rarfile = "*"
requests_oauthlib = "*"
responses = ">=0.3.0"

[tool.poetry.group.format.dependencies]
isort = { version = "<5.14", extras = ["colors"] }
black = ">=24.3,<25"

[tool.poetry.group.lint.dependencies]
ruff = ">=0.6.4"

Expand Down Expand Up @@ -153,24 +149,6 @@ build-backend = "poetry.core.masonry.api"
poethepoet = ">=0.26"
poetry = ">=1.8"

# We use a default path '.' to make black and isort behave like ruff and
# mypy do: they act on the entire codebase (ruff does it by default, and
# mypy follows our configuration) by default. Positional command-line arguments
# override this. Therefore, locally you can run `poe check-format <some-path>`
# to quickly check a specific path.
#
# Note: both tools respect .gitignore, therefore if we see them format
# something unwanted locally, we should add these paths to .gitignore.
[tool.poe.tasks._black]
help = "Run black"
cmd = "black $OPTS $path"
args = { path = { help = "Path to blacken", positional = true, multiple = true, default = "." } }

[tool.poe.tasks._isort]
help = "Run isort"
cmd = "isort $OPTS $path"
args = { path = { help = "Path to isort", positional = true, multiple = true, default = "." } }

[tool.poe.tasks.bump]
help = "Bump project version and update relevant files"
cmd = "python ./extra/release.py bump $version"
Expand All @@ -186,8 +164,7 @@ cmd = "make -C docs linkcheck"

[tool.poe.tasks.check-format]
help = "Check the code for style issues"
ref = "format"
env.OPTS = "--check --diff --color"
cmd = "ruff format --check --diff"

[tool.poe.tasks.check-types]
help = "Check the code for typing issues. Accepts mypy options."
Expand All @@ -199,9 +176,7 @@ cmd = "make -C docs html"

[tool.poe.tasks.format]
help = "Format the codebase"
ignore_fail = "return_non_zero"
sequence = ["_black $path", "_isort $path"]
args = { path = { help = "Path to format", positional = true, multiple = true, default = "." } }
cmd = "ruff format"

[tool.poe.tasks.lint]
help = "Check the code for linting issues. Accepts ruff options."
Expand Down Expand Up @@ -248,17 +223,6 @@ done
"""
interpreter = "zsh"

[tool.black]
line-length = 80
target-version = ["py38", "py39", "py310", "py311"]

[tool.isort]
profile = "black"
py_version = 38
multi_line_output = 3
line_length = 80
indent = 4

[tool.ruff]
target-version = "py38"
line-length = 80
Expand Down

0 comments on commit 06a5eca

Please sign in to comment.