Skip to content

Commit 086684f

Browse files
committed
Switch linters and formatters to Ruff
1 parent 95e605a commit 086684f

File tree

7 files changed

+28
-38
lines changed

7 files changed

+28
-38
lines changed

.github/workflows/python-package.yml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,16 @@ env:
1616
git-depth: 0 # Depth to search for tags.
1717

1818
jobs:
19-
black:
19+
ruff:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@v3
23-
- name: Install Black
24-
run: pip install black
25-
- name: Run Black
26-
run: black --check --diff examples/ scripts/ tcod/ tests/ *.py
27-
28-
isort:
29-
runs-on: ubuntu-latest
30-
steps:
31-
- uses: actions/checkout@v3
32-
- name: Install isort
33-
run: pip install isort
34-
- name: isort
35-
uses: liskin/gh-problem-matcher-wrap@v2
36-
with:
37-
linters: isort
38-
run: isort scripts/ tcod/ tests/ examples/ --check --diff
23+
- name: Install Ruff
24+
run: pip install ruff
25+
- name: Ruff Check
26+
run: ruff check . --fix-only --exit-non-zero-on-fix --output-format=github
27+
- name: Ruff Format
28+
run: ruff format . --check
3929

4030
mypy:
4131
runs-on: ubuntu-latest
@@ -76,7 +66,7 @@ jobs:
7666

7767
# This makes sure that the latest versions of the SDL headers parse correctly.
7868
parse_sdl:
79-
needs: [black, isort, mypy]
69+
needs: [ruff, mypy]
8070
runs-on: ${{ matrix.os }}
8171
strategy:
8272
matrix:
@@ -100,7 +90,7 @@ jobs:
10090
SDL_VERSION: ${{ matrix.sdl-version }}
10191

10292
build:
103-
needs: [black, isort, mypy]
93+
needs: [ruff, mypy]
10494
runs-on: ${{ matrix.os }}
10595
strategy:
10696
matrix:
@@ -164,7 +154,7 @@ jobs:
164154
retention-days: 7
165155

166156
test-docs:
167-
needs: [black, isort, mypy]
157+
needs: [ruff, mypy]
168158
runs-on: ubuntu-latest
169159
steps:
170160
- name: Install APT dependencies
@@ -189,7 +179,7 @@ jobs:
189179
run: python -m sphinx -T -E -W --keep-going . _build/html
190180

191181
isolated: # Test installing the package from source.
192-
needs: [black, isort, mypy, sdist]
182+
needs: [ruff, mypy, sdist]
193183
runs-on: ${{ matrix.os }}
194184
strategy:
195185
matrix:
@@ -219,7 +209,7 @@ jobs:
219209
python -c "import tcod.context"
220210
221211
linux-wheels:
222-
needs: [black, isort, mypy]
212+
needs: [ruff, mypy]
223213
runs-on: "ubuntu-latest"
224214
strategy:
225215
matrix:
@@ -268,7 +258,7 @@ jobs:
268258
retention-days: 7
269259

270260
build-macos:
271-
needs: [black, isort, mypy]
261+
needs: [ruff, mypy]
272262
runs-on: "macos-11"
273263
strategy:
274264
fail-fast: true

.pre-commit-config.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ repos:
1414
- id: debug-statements
1515
- id: fix-byte-order-marker
1616
- id: detect-private-key
17-
- repo: https://github.com/psf/black
18-
rev: 23.10.0
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.1.2
1919
hooks:
20-
- id: black
21-
- repo: https://github.com/pycqa/isort
22-
rev: 5.12.0
23-
hooks:
24-
- id: isort
20+
- id: ruff
21+
args: [--fix-only, --exit-non-zero-on-fix]
22+
- id: ruff-format
2523
default_language_version:
2624
python: python3.11

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
"austin.code-gnu-global",
77
"editorconfig.editorconfig",
88
"ms-python.python",
9-
"ms-python.black-formatter",
109
"ms-python.vscode-pylance",
1110
"ms-vscode.cpptools",
1211
"redhat.vscode-yaml",
1312
"streetsidesoftware.code-spell-checker",
1413
"tamasfe.even-better-toml",
1514
"xaver.clang-format",
15+
"charliermarsh.ruff"
1616
],
1717
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
1818
"unwantedRecommendations": []

.vscode/settings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"--follow-imports=silent",
1919
"--show-column-numbers"
2020
],
21-
"python.formatting.provider": "none",
2221
"files.associations": {
2322
"*.spec": "python",
2423
},
@@ -483,7 +482,7 @@
483482
"python.testing.unittestEnabled": false,
484483
"python.testing.pytestEnabled": true,
485484
"[python]": {
486-
"editor.defaultFormatter": "ms-python.black-formatter"
485+
"editor.defaultFormatter": "charliermarsh.ruff"
487486
},
488487
"cSpell.enableFiletypes": [
489488
"github-actions-workflow"

build_sdl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,11 @@ def _should_track_define(self, tokens: list[Any]) -> bool:
183183
)
184184

185185
def on_directive_handle(
186-
self, directive: Any, tokens: list[Any], if_passthru: bool, preceding_tokens: list[Any] # noqa: ANN401
186+
self,
187+
directive: Any, # noqa: ANN401
188+
tokens: list[Any],
189+
if_passthru: bool,
190+
preceding_tokens: list[Any],
187191
) -> Any: # noqa: ANN401
188192
"""Catch and store definitions."""
189193
if directive.value == "define" and self._should_track_define(tokens):

examples/samples_tcod.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,7 @@ def draw_ui(self) -> None:
565565
sample_console.print(
566566
1,
567567
1,
568-
"IJKL : move around\n"
569-
"T : torch fx {}\n"
570-
"W : light walls {}\n"
571-
"+-: algo {}".format(
568+
"IJKL : move around\nT : torch fx {}\nW : light walls {}\n+-: algo {}".format(
572569
"on " if self.torch else "off",
573570
"on " if self.light_walls else "off",
574571
FOV_ALGO_NAMES[self.algo_num],

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ ignore = [
186186
"D407", # dashed-underline-after-section
187187
"D408", # section-underline-after-name
188188
"D409", # section-underline-matches-section-length
189+
"D206", # indent-with-spaces
190+
"W191", # tab-indentation
189191
]
190192
extend-exclude = ["libtcod"] # Ignore submodule
191193
line-length = 120

0 commit comments

Comments
 (0)