Skip to content

Commit

Permalink
Switch linters and formatters to Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
HexDecimal committed Oct 25, 2023
1 parent 95e605a commit 2a7b58f
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 38 deletions.
36 changes: 13 additions & 23 deletions .github/workflows/python-package.yml
Expand Up @@ -16,26 +16,16 @@ env:
git-depth: 0 # Depth to search for tags.

jobs:
black:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Black
run: pip install black
- name: Run Black
run: black --check --diff examples/ scripts/ tcod/ tests/ *.py

isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install isort
run: pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v2
with:
linters: isort
run: isort scripts/ tcod/ tests/ examples/ --check --diff
- name: Install Ruff
run: pip install ruff
- name: Ruff Check
run: ruff check . --fix-only, --exit-non-zero-on-fix --output-format=github
- name: Ruff Format
run: ruff format . --check

mypy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -76,7 +66,7 @@ jobs:

# This makes sure that the latest versions of the SDL headers parse correctly.
parse_sdl:
needs: [black, isort, mypy]
needs: [ruff, mypy]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -100,7 +90,7 @@ jobs:
SDL_VERSION: ${{ matrix.sdl-version }}

build:
needs: [black, isort, mypy]
needs: [ruff, mypy]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -164,7 +154,7 @@ jobs:
retention-days: 7

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

isolated: # Test installing the package from source.
needs: [black, isort, mypy, sdist]
needs: [ruff, mypy, sdist]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -219,7 +209,7 @@ jobs:
python -c "import tcod.context"
linux-wheels:
needs: [black, isort, mypy]
needs: [ruff, mypy]
runs-on: "ubuntu-latest"
strategy:
matrix:
Expand Down Expand Up @@ -268,7 +258,7 @@ jobs:
retention-days: 7

build-macos:
needs: [black, isort, mypy]
needs: [ruff, mypy]
runs-on: "macos-11"
strategy:
fail-fast: true
Expand Down
12 changes: 5 additions & 7 deletions .pre-commit-config.yaml
Expand Up @@ -14,13 +14,11 @@ repos:
- id: debug-statements
- id: fix-byte-order-marker
- id: detect-private-key
- repo: https://github.com/psf/black
rev: 23.10.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.2
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- id: ruff
args: [--fix-only, --exit-non-zero-on-fix]
- id: ruff-format
default_language_version:
python: python3.11
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Expand Up @@ -6,13 +6,13 @@
"austin.code-gnu-global",
"editorconfig.editorconfig",
"ms-python.python",
"ms-python.black-formatter",
"ms-python.vscode-pylance",
"ms-vscode.cpptools",
"redhat.vscode-yaml",
"streetsidesoftware.code-spell-checker",
"tamasfe.even-better-toml",
"xaver.clang-format",
"charliermarsh.ruff"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
Expand Down
3 changes: 1 addition & 2 deletions .vscode/settings.json
Expand Up @@ -18,7 +18,6 @@
"--follow-imports=silent",
"--show-column-numbers"
],
"python.formatting.provider": "none",
"files.associations": {
"*.spec": "python",
},
Expand Down Expand Up @@ -483,7 +482,7 @@
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff"
},
"cSpell.enableFiletypes": [
"github-actions-workflow"
Expand Down
6 changes: 5 additions & 1 deletion build_sdl.py
Expand Up @@ -183,7 +183,11 @@ def _should_track_define(self, tokens: list[Any]) -> bool:
)

def on_directive_handle(
self, directive: Any, tokens: list[Any], if_passthru: bool, preceding_tokens: list[Any] # noqa: ANN401
self,
directive: Any, # noqa: ANN401
tokens: list[Any],
if_passthru: bool,
preceding_tokens: list[Any],
) -> Any: # noqa: ANN401
"""Catch and store definitions."""
if directive.value == "define" and self._should_track_define(tokens):
Expand Down
5 changes: 1 addition & 4 deletions examples/samples_tcod.py
Expand Up @@ -565,10 +565,7 @@ def draw_ui(self) -> None:
sample_console.print(
1,
1,
"IJKL : move around\n"
"T : torch fx {}\n"
"W : light walls {}\n"
"+-: algo {}".format(
"IJKL : move around\nT : torch fx {}\nW : light walls {}\n+-: algo {}".format(
"on " if self.torch else "off",
"on " if self.light_walls else "off",
FOV_ALGO_NAMES[self.algo_num],
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Expand Up @@ -186,6 +186,8 @@ ignore = [
"D407", # dashed-underline-after-section
"D408", # section-underline-after-name
"D409", # section-underline-matches-section-length
"D206", # indent-with-spaces
"W191", # tab-indentation
]
extend-exclude = ["libtcod"] # Ignore submodule
line-length = 120
Expand Down

0 comments on commit 2a7b58f

Please sign in to comment.