Skip to content

Commit 5488a37

Browse files
committed
feat: integrate helper into package properly
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 107064c commit 5488a37

File tree

5 files changed

+301
-27
lines changed

5 files changed

+301
-27
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ Python.
264264
- `pyproject`: Include validate pyproject with schema store.
265265
- `all`: All extras
266266

267+
## Helper utility
268+
269+
There's also a script, accessible as `sp-repo-review.ruff-checks`, that will
270+
compare your ruff checks to the known values. It's a little more elegant on the
271+
command line than the Ruff family description, which will only print out a basic
272+
list.
273+
267274
## Other ways to use
268275

269276
You can also use GitHub Actions:

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Source = "https://github.com/scientific-python/cookie"
5656

5757
[project.scripts]
5858
sp-repo-review = "repo_review.__main__:main"
59+
"sp-repo-review.ruff-checks" = "sp_repo_review.ruff_checks.__main__:main"
5960

6061
[project.entry-points."repo_review.checks"]
6162
general = "sp_repo_review.checks.general:repo_review_checks"

src/sp_repo_review/ruff_checks/__init__.py

Whitespace-only changes.

helpers/missing_ruff.py renamed to src/sp_repo_review/ruff_checks/__main__.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1-
#!/usr/bin/env -S uv run --script
2-
3-
# /// script
4-
# dependencies = ["ruff", "rich"]
5-
# ///
6-
7-
81
import argparse
2+
import importlib.resources
93
import json
10-
import subprocess
4+
import sys
115
from collections.abc import Iterator
126
from pathlib import Path
137

14-
import tomllib
158
from rich import print
169
from rich.columns import Columns
1710
from rich.panel import Panel
18-
from ruff.__main__ import find_ruff_bin
11+
12+
from .._compat import tomllib
13+
from ..checks.ruff import get_rule_selection, ruff
1914

2015
libs = {"AIR", "ASYNC", "DJ", "FAST", "INT", "NPY", "PD"}
2116
specialty = {
@@ -39,23 +34,28 @@
3934

4035

4136
def process_dir(path: Path) -> None:
42-
with path.joinpath("pyproject.toml").open("rb") as f:
43-
pyproject = tomllib.load(f)
44-
45-
match pyproject:
46-
case {"tool": {"ruff": {"lint": {"extend-select": selection}}}}:
47-
selected = frozenset(selection)
48-
case _:
49-
raise SystemExit(1)
50-
51-
linter_txt = subprocess.run(
52-
[find_ruff_bin(), "linter", "--output-format=json"],
53-
check=True,
54-
capture_output=True,
55-
text=True,
56-
cwd=path,
57-
).stdout
58-
linter = json.loads(linter_txt)
37+
try:
38+
with path.joinpath("pyproject.toml").open("rb") as f:
39+
pyproject = tomllib.load(f)
40+
except FileNotFoundError:
41+
pyproject = {}
42+
43+
ruff_config = ruff(pyproject=pyproject, root=path)
44+
if ruff_config is None:
45+
print(
46+
"[red]Could not find a ruff config [dim](.ruff.toml, ruff.toml, or pyproject.toml)",
47+
file=sys.stderr,
48+
)
49+
raise SystemExit(1)
50+
selected = get_rule_selection(ruff_config)
51+
52+
# Create using ruff linter --output-format=json > src/sp_repo_review/ruff/linter.json
53+
with (
54+
importlib.resources.files("sp_repo_review.ruff_checks")
55+
.joinpath("linter.json")
56+
.open(encoding="utf-8") as ff
57+
):
58+
linter = json.load(ff)
5959

6060
lint_info = {r["prefix"]: r["name"] for r in linter if r["prefix"] not in {"", "F"}}
6161
lint_info = dict(sorted(lint_info.items()))
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
[
2+
{
3+
"prefix": "AIR",
4+
"name": "Airflow"
5+
},
6+
{
7+
"prefix": "ERA",
8+
"name": "eradicate"
9+
},
10+
{
11+
"prefix": "FAST",
12+
"name": "FastAPI"
13+
},
14+
{
15+
"prefix": "YTT",
16+
"name": "flake8-2020"
17+
},
18+
{
19+
"prefix": "ANN",
20+
"name": "flake8-annotations"
21+
},
22+
{
23+
"prefix": "ASYNC",
24+
"name": "flake8-async"
25+
},
26+
{
27+
"prefix": "S",
28+
"name": "flake8-bandit"
29+
},
30+
{
31+
"prefix": "BLE",
32+
"name": "flake8-blind-except"
33+
},
34+
{
35+
"prefix": "FBT",
36+
"name": "flake8-boolean-trap"
37+
},
38+
{
39+
"prefix": "B",
40+
"name": "flake8-bugbear"
41+
},
42+
{
43+
"prefix": "A",
44+
"name": "flake8-builtins"
45+
},
46+
{
47+
"prefix": "COM",
48+
"name": "flake8-commas"
49+
},
50+
{
51+
"prefix": "C4",
52+
"name": "flake8-comprehensions"
53+
},
54+
{
55+
"prefix": "CPY",
56+
"name": "flake8-copyright"
57+
},
58+
{
59+
"prefix": "DTZ",
60+
"name": "flake8-datetimez"
61+
},
62+
{
63+
"prefix": "T10",
64+
"name": "flake8-debugger"
65+
},
66+
{
67+
"prefix": "DJ",
68+
"name": "flake8-django"
69+
},
70+
{
71+
"prefix": "EM",
72+
"name": "flake8-errmsg"
73+
},
74+
{
75+
"prefix": "EXE",
76+
"name": "flake8-executable"
77+
},
78+
{
79+
"prefix": "FIX",
80+
"name": "flake8-fixme"
81+
},
82+
{
83+
"prefix": "FA",
84+
"name": "flake8-future-annotations"
85+
},
86+
{
87+
"prefix": "INT",
88+
"name": "flake8-gettext"
89+
},
90+
{
91+
"prefix": "ISC",
92+
"name": "flake8-implicit-str-concat"
93+
},
94+
{
95+
"prefix": "ICN",
96+
"name": "flake8-import-conventions"
97+
},
98+
{
99+
"prefix": "LOG",
100+
"name": "flake8-logging"
101+
},
102+
{
103+
"prefix": "G",
104+
"name": "flake8-logging-format"
105+
},
106+
{
107+
"prefix": "INP",
108+
"name": "flake8-no-pep420"
109+
},
110+
{
111+
"prefix": "PIE",
112+
"name": "flake8-pie"
113+
},
114+
{
115+
"prefix": "T20",
116+
"name": "flake8-print"
117+
},
118+
{
119+
"prefix": "PYI",
120+
"name": "flake8-pyi"
121+
},
122+
{
123+
"prefix": "PT",
124+
"name": "flake8-pytest-style"
125+
},
126+
{
127+
"prefix": "Q",
128+
"name": "flake8-quotes"
129+
},
130+
{
131+
"prefix": "RSE",
132+
"name": "flake8-raise"
133+
},
134+
{
135+
"prefix": "RET",
136+
"name": "flake8-return"
137+
},
138+
{
139+
"prefix": "SLF",
140+
"name": "flake8-self"
141+
},
142+
{
143+
"prefix": "SIM",
144+
"name": "flake8-simplify"
145+
},
146+
{
147+
"prefix": "SLOT",
148+
"name": "flake8-slots"
149+
},
150+
{
151+
"prefix": "TID",
152+
"name": "flake8-tidy-imports"
153+
},
154+
{
155+
"prefix": "TD",
156+
"name": "flake8-todos"
157+
},
158+
{
159+
"prefix": "TC",
160+
"name": "flake8-type-checking"
161+
},
162+
{
163+
"prefix": "ARG",
164+
"name": "flake8-unused-arguments"
165+
},
166+
{
167+
"prefix": "PTH",
168+
"name": "flake8-use-pathlib"
169+
},
170+
{
171+
"prefix": "FLY",
172+
"name": "flynt"
173+
},
174+
{
175+
"prefix": "I",
176+
"name": "isort"
177+
},
178+
{
179+
"prefix": "C90",
180+
"name": "mccabe"
181+
},
182+
{
183+
"prefix": "NPY",
184+
"name": "NumPy-specific rules"
185+
},
186+
{
187+
"prefix": "PD",
188+
"name": "pandas-vet"
189+
},
190+
{
191+
"prefix": "N",
192+
"name": "pep8-naming"
193+
},
194+
{
195+
"prefix": "PERF",
196+
"name": "Perflint"
197+
},
198+
{
199+
"prefix": "",
200+
"name": "pycodestyle",
201+
"categories": [
202+
{
203+
"prefix": "E",
204+
"name": "Error"
205+
},
206+
{
207+
"prefix": "W",
208+
"name": "Warning"
209+
}
210+
]
211+
},
212+
{
213+
"prefix": "DOC",
214+
"name": "pydoclint"
215+
},
216+
{
217+
"prefix": "D",
218+
"name": "pydocstyle"
219+
},
220+
{
221+
"prefix": "F",
222+
"name": "Pyflakes"
223+
},
224+
{
225+
"prefix": "PGH",
226+
"name": "pygrep-hooks"
227+
},
228+
{
229+
"prefix": "PL",
230+
"name": "Pylint",
231+
"categories": [
232+
{
233+
"prefix": "C",
234+
"name": "Convention"
235+
},
236+
{
237+
"prefix": "E",
238+
"name": "Error"
239+
},
240+
{
241+
"prefix": "R",
242+
"name": "Refactor"
243+
},
244+
{
245+
"prefix": "W",
246+
"name": "Warning"
247+
}
248+
]
249+
},
250+
{
251+
"prefix": "UP",
252+
"name": "pyupgrade"
253+
},
254+
{
255+
"prefix": "FURB",
256+
"name": "refurb"
257+
},
258+
{
259+
"prefix": "RUF",
260+
"name": "Ruff-specific rules"
261+
},
262+
{
263+
"prefix": "TRY",
264+
"name": "tryceratops"
265+
}
266+
]

0 commit comments

Comments
 (0)