Skip to content

Commit 352bf11

Browse files
committed
[chore] Replace Black 24.1 with Ruff 0.6
Quite a few automated reformatting as a result, but all in all it's not too bad - Ruff's formatting rules don't differ too much from Black's ones :-) --> https://docs.astral.sh/ruff/formatter/black/
1 parent 6f59077 commit 352bf11

32 files changed

+66
-121
lines changed

.github/workflows/test-suite.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ jobs:
2929
run: uv python install
3030
- name: "Install dependencies via uv"
3131
run: uv sync --all-extras
32-
- name: "Run linting checks: Black"
33-
run: uv run black src/
34-
- name: "Run linting checks: Ruff"
32+
- name: "Run linting checks: Ruff checker"
33+
run: uv run ruff format --check --quiet src/
34+
- name: "Run linting checks: Ruff linter"
3535
run: uv run ruff check --quiet src/
3636
- name: "Run linting checks: Mypy"
3737
run: uv run mypy src/

.pre-commit-config.yaml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
# See https://pre-commit.com for more information
22
# See https://pre-commit.com/hooks.html for more hooks
33
repos:
4-
- repo: https://github.com/psf/black
5-
rev: 24.1.1
6-
hooks:
7-
- id: black
84
- repo: https://github.com/pre-commit/mirrors-mypy
9-
rev: v1.8.0
5+
rev: v1.11.2
106
hooks:
117
- id: mypy
128
additional_dependencies: [types-requests==2.31.0.2]
139
exclude: "^scripts/load_testing/.*\\.py$"
1410
- repo: https://github.com/charliermarsh/ruff-pre-commit
15-
rev: v0.1.14
11+
rev: v0.6.3
1612
hooks:
13+
# Run the formatter.
14+
- id: ruff-format
15+
# Run the linter.
1716
- id: ruff
1817
args: ["--fix"]
1918
exclude: "^src/project/settings/.*\\.py$"
2019
- repo: https://github.com/abravalheri/validate-pyproject
21-
rev: v0.16
20+
rev: v0.19
2221
hooks:
2322
- id: validate-pyproject

Makefile

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ help:
1313
install: bin/uv .venv ./node_modules ## Install the Python and frontend dependencies
1414
bin/uv sync --all-extras
1515
${PYTHON_BINS}/pre-commit install
16+
${SUB_MAKE} .venv/bin/black
1617

1718
.PHONY: dev
1819
dev: .env.local db.sqlite3
@@ -60,18 +61,18 @@ test: ## Launch the pytest tests suite
6061
${PYTHON_BINS}/pytest ${pytest_opts}
6162

6263
.PHONY: code-quality/all
63-
code-quality/all: code-quality/black code-quality/ruff code-quality/mypy ## Run all our code quality tools
64-
65-
.PHONY: code-quality/black
66-
code-quality/black: black_opts ?=
67-
code-quality/black: ## Automated 'a la Prettier' code formatting
68-
# @link https://black.readthedocs.io/en/stable/
69-
@${PYTHON_BINS}/black ${black_opts} src/
70-
71-
.PHONY: code-quality/ruff
72-
code-quality/ruff: ruff_opts ?= --fix
73-
code-quality/ruff: ## Fast linting
74-
# @link https://docs.astral.sh/ruff/
64+
code-quality/all: code-quality/ruff_check code-quality/ruff_lint code-quality/mypy ## Run all our code quality tools
65+
66+
.PHONY: code-quality/ruff_check
67+
code-quality/ruff_check: ruff_opts ?=
68+
code-quality/ruff_check: ## Automated 'a la Prettier' code formatting
69+
# @link https://docs.astral.sh/ruff/formatter/
70+
@${PYTHON_BINS}/ruff format ${ruff_opts} src/
71+
72+
.PHONY: code-quality/ruff_lint
73+
code-quality/ruff_lint: ruff_opts ?= --fix
74+
code-quality/ruff_lint: ## Fast linting
75+
# @link https://docs.astral.sh/ruff/linter/
7576
@${PYTHON_BINS}/ruff check src/ ${ruff_opts}
7677

7778
.PHONY: code-quality/mypy
@@ -154,6 +155,10 @@ bin/uv: # Install `uv` and `uvx` locally in the "bin/" folder
154155
.env.local:
155156
cp .env.dist .env.local
156157

158+
.venv/bin/black: .venv ## A simple and stupid shim to use the IDE's Black integration with Ruff
159+
@echo '#!/usr/bin/env sh\n$$(dirname "$$0")/ruff format $$@' > ${PYTHON_BINS}/black
160+
@chmod +x ${PYTHON_BINS}/black
161+
157162
db.sqlite3: dotenv_file ?= .env.local
158163
db.sqlite3: ## Initialises the SQLite database
159164
touch db.sqlite3

manage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python
22
"""Django's command-line utility for administrative tasks."""
3+
34
import os
45
import sys
56

pyproject.toml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ dependencies= [
3131
[project.optional-dependencies]
3232
dev = [
3333
"python-dotenv==1.*",
34-
"black==24.1.*",
3534
"ruff==0.6.*",
3635
"mypy==1.*",
3736
"pre-commit==3.*",
3837
"ipython==8.*",
3938
"types-requests==2.*",
4039
"django-extensions==3.*",
41-
"httpx==0.26.*", # only used in "scripts/download_assets.py" for parallel downloads
40+
# (httpx is only used in "scripts/download_assets.py" for parallel downloads)
41+
"httpx==0.26.*",
4242
"sqlite-utils==3.*",
43-
4443
]
4544
test = [
4645
"pytest==7.*",
@@ -59,13 +58,9 @@ Repository = "https://github.com/olivierphi/zakuchess"
5958

6059

6160
[tool.uv]
62-
package = true
61+
package = true # symlinks the project's "src/" root folder to the venv
6362

6463

65-
[tool.black]
66-
# @link https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html
67-
target-version = ['py311']
68-
6964
[tool.ruff]
7065
# @link https://docs.astral.sh/ruff/configuration/
7166
target-version = "py311"

scripts/download_assets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
)
4242
)
4343

44+
# fmt: off
4445
ASSETS_MAP: dict[URL, Path] = {
45-
# fmt: off
4646
# Fonts:
4747
ASSETS_PATTERNS["GOOGLE_FONTS"].format(font_name="opensans", file_id="mem8YaGs126MiZpBA-UFVZ0b", v="v35"): WEBUI_STATIC / "fonts" / "OpenSans.woff2",
4848
# Stockfish:
@@ -81,8 +81,8 @@
8181
ASSETS_PATTERNS["WIKIMEDIA_CHESS_SVG_DARK"].format(folder="f/ff", piece="r"): CHESS_STATIC / "symbols" / "b-rook.svg",
8282
ASSETS_PATTERNS["WIKIMEDIA_CHESS_SVG_DARK"].format(folder="4/47", piece="q"): CHESS_STATIC / "symbols" / "b-queen.svg",
8383
ASSETS_PATTERNS["WIKIMEDIA_CHESS_SVG_DARK"].format(folder="f/f0", piece="k"): CHESS_STATIC / "symbols" / "b-king.svg",
84-
# fmt: on
8584
}
85+
# fmt: on
8686

8787

8888
async def download_assets(*, even_if_exists: bool) -> None:

src/apps/authentication/migrations/0001_initial.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88

99
class Migration(migrations.Migration):
10-
1110
initial = True
1211

1312
dependencies = [

src/apps/chess/business_logic/_do_chess_move.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
False: "b",
2525
}
2626

27-
_CHESS_OUTCOME_TO_GAME_END_REASON_MAPPING: (
28-
"Mapping[chess.Termination, GameEndReason]"
29-
) = {
27+
_CHESS_OUTCOME_TO_GAME_END_REASON_MAPPING: "Mapping[chess.Termination, GameEndReason]" = {
3028
chess.Termination.CHECKMATE: "checkmate",
3129
chess.Termination.STALEMATE: "stalemate",
3230
chess.Termination.INSUFFICIENT_MATERIAL: "insufficient_material",

src/apps/chess/components/chess_board.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@
4040
)
4141
_PIECE_GROUND_MARKER_COLOR_TAILWIND_CLASSES: dict[tuple["PlayerSide", bool], str] = {
4242
# the boolean says if the piece can move
43-
# fmt: off
4443
("w", False): "bg-emerald-800/40 border-2 border-emerald-800",
4544
("b", False): "bg-indigo-800/40 border-2 border-indigo-800",
4645
("w", True): "bg-emerald-600/40 border-2 border-emerald-800",
4746
("b", True): "bg-indigo-600/40 border-2 border-indigo-800",
48-
# fmt: on
4947
}
5048
_CHESS_PIECE_Z_INDEXES: dict[str, str] = {
5149
# N.B. z-indexes must be multiples of 10 in Tailwind.
@@ -672,7 +670,6 @@ def chess_last_move(
672670
def chess_last_move_marker(
673671
*, square: "Square", move_part: Literal["from", "to"]
674672
) -> "dom_tag":
675-
676673
match move_part:
677674
case "from":
678675
start_class = "!w-full"

src/apps/chess/consts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
"q": 9,
2424
}
2525

26+
# fmt: off
2627
SQUARES: Final[tuple["Square", ...]] = (
2728
# The order matters here, as we use that for the board visual representation.
28-
# fmt: off
2929
"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8",
3030
"b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8",
3131
"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8",
@@ -34,8 +34,8 @@
3434
"f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8",
3535
"g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8",
3636
"h1", "h2", "h3", "h4", "h5", "h6", "h7", "h8",
37-
# fmt: on
3837
)
38+
# fmt: on
3939
FILES: Final[tuple["File", ...]] = ("a", "b", "c", "d", "e", "f", "g", "h")
4040
RANKS: Final[tuple["Rank", ...]] = ("1", "2", "3", "4", "5", "6", "7", "8")
4141

0 commit comments

Comments
 (0)