Skip to content

Commit 3b00960

Browse files
authored
Use ruff for formatting and import sorting, with the shared pre-commit config (#41)
1 parent 6420044 commit 3b00960

4 files changed

Lines changed: 20 additions & 11 deletions

File tree

‎.github/workflows/static_analysis.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
- name: Check formatting
3232
run: uvx ruff format --check .
3333

34+
- name: Check statement order
35+
run: uvx ssort --check --diff .
36+
3437
pyright:
3538
runs-on: ubuntu-latest
3639
steps:

‎.pre-commit-config.yaml‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ repos:
44
rev: v6.0.0
55
hooks:
66
- id: check-yaml
7+
- id: check-toml
78
- id: end-of-file-fixer
89
- id: trailing-whitespace
910
- id: check-added-large-files # Prevent giant files from being committed.
1011
args: [--maxkb=500]
1112
exclude: ^(uv\.lock|docs/package-lock\.json)$ # generated lock files
1213
- id: check-merge-conflict # Check for files that contain merge conflict strings.
1314
- repo: https://github.com/kynan/nbstripout
14-
rev: 0.9.0
15+
rev: 0.9.1
1516
hooks:
1617
- id: nbstripout # strip jupyter notebook output
18+
- repo: https://github.com/bwhmather/ssort
19+
rev: 0.17.0
20+
hooks:
21+
- id: ssort # order statements so names are defined before they are used
1722
- repo: https://github.com/astral-sh/ruff-pre-commit
18-
rev: v0.9.1
23+
rev: v0.17.3
1924
hooks:
20-
- id: ruff
25+
- id: ruff-check # lint, including import sorting (the I rules)
2126
args: [--fix]
2227
- id: ruff-format

‎Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ install: ## uv sync with the dev extra, and the pre-commit hooks
1717
test: ## pytest with coverage
1818
uv run pytest --cov .
1919

20-
lint: ## ruff and pyright
20+
lint: ## ruff, ssort and pyright
2121
uv run ruff check .
2222
uv run ruff format --check .
23+
uvx ssort --check --diff .
2324
uv run pyright src/
2425

2526
readme: ## render README.md from README.qmd with quarto

‎scripts/check_pypi_dependencies.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ def is_installable(releases: Releases, requirement: Requirement) -> bool:
9191
return False
9292

9393

94+
def _version_key(text: str) -> Version:
95+
try:
96+
return Version(text)
97+
except InvalidVersion:
98+
return Version("0")
99+
100+
94101
def check(pyproject: dict, fetch: Fetch = fetch_releases) -> list[str]:
95102
"""Return one message per dependency that PyPI would reject or that cannot be installed."""
96103
project = pyproject.get("project", {})
@@ -139,13 +146,6 @@ def check(pyproject: dict, fetch: Fetch = fetch_releases) -> list[str]:
139146
return problems
140147

141148

142-
def _version_key(text: str) -> Version:
143-
try:
144-
return Version(text)
145-
except InvalidVersion:
146-
return Version("0")
147-
148-
149149
def main(argv: list[str] | None = None) -> int:
150150
"""Run the check on a pyproject.toml; return the exit status."""
151151
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])

0 commit comments

Comments
 (0)