Skip to content

Commit 1d2ef5f

Browse files
committed
refactor: rename
1 parent 4fb2bba commit 1d2ef5f

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

src/sp_repo_review/checks/noxfile.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# NOX: Noxfile checks
2-
## NOXxxx: noxfile checks
1+
# NOX: Nox checks
2+
## NOX1xx: Contents of noxfile
3+
## NOX2xx: Script mode for noxfile
34

45
from __future__ import annotations
56

@@ -18,23 +19,23 @@
1819

1920

2021
@dataclasses.dataclass(frozen=True, kw_only=True, slots=True, eq=False)
21-
class NoxfileInfo:
22+
class Noxfile:
2223
module: ast.Module
2324
shebang: str
2425
script: dict[str, Any]
2526

2627
__hash__ = None # type: ignore[assignment]
2728

2829
@classmethod
29-
def from_str(cls, content: str) -> NoxfileInfo:
30+
def from_str(cls, content: str) -> Noxfile:
3031
module = ast.parse(content, filename="noxfile.py")
3132
shebang_match = re.match(r"^#!.*\n", content)
3233
shebang = shebang_match.group(0).strip() if shebang_match else ""
3334
script = _load_script_block(content)
3435
return cls(module=module, shebang=shebang, script=script)
3536

3637
def __eq__(self, other: object) -> bool:
37-
if not isinstance(other, NoxfileInfo):
38+
if not isinstance(other, Noxfile):
3839
return NotImplemented
3940

4041
ast_equal = ast.dump(self.module, include_attributes=True) == ast.dump(
@@ -63,7 +64,7 @@ def _load_script_block(content: str, /) -> dict[str, Any]:
6364
return tomllib.loads(content)
6465

6566

66-
def noxfile(root: Traversable) -> NoxfileInfo | None:
67+
def noxfile(root: Traversable) -> Noxfile | None:
6768
"""
6869
Returns the shebang line (or empty string if missing), the noxfile script block, and the AST of the noxfile.py.
6970
Returns None if noxfile.py is not present.
@@ -74,20 +75,20 @@ def noxfile(root: Traversable) -> NoxfileInfo | None:
7475
return None
7576

7677
with noxfile_path.open("r", encoding="utf-8") as f:
77-
return NoxfileInfo.from_str(f.read())
78+
return Noxfile.from_str(f.read())
7879

7980

80-
class Noxfile:
81+
class Nox:
8182
family = "noxfile"
8283
requires = {"PY007"}
8384
url = mk_url("tasks")
8485

8586

86-
class NOX101(Noxfile):
87+
class NOX101(Nox):
8788
"Sets minimum nox version"
8889

8990
@staticmethod
90-
def check(noxfile: NoxfileInfo | None) -> bool | None:
91+
def check(noxfile: Noxfile | None) -> bool | None:
9192
"""Set a minimum nox version:
9293
9394
```python
@@ -110,11 +111,11 @@ def check(noxfile: NoxfileInfo | None) -> bool | None:
110111
return False
111112

112113

113-
class NOX102(Noxfile):
114+
class NOX102(Nox):
114115
"Sets venv backend"
115116

116117
@staticmethod
117-
def check(noxfile: NoxfileInfo | None) -> bool | None:
118+
def check(noxfile: Noxfile | None) -> bool | None:
118119
"""
119120
The default venv backend should be set, ideally to `uv|virtualenv`:
120121
@@ -140,11 +141,11 @@ def check(noxfile: NoxfileInfo | None) -> bool | None:
140141
return False
141142

142143

143-
class NOX103(Noxfile):
144+
class NOX103(Nox):
144145
"Set default per session instead of session list"
145146

146147
@staticmethod
147-
def check(noxfile: NoxfileInfo | None) -> bool | None:
148+
def check(noxfile: Noxfile | None) -> bool | None:
148149
"""
149150
You should use `default=` in each session instead of setting a global list.
150151
"""
@@ -166,11 +167,11 @@ def check(noxfile: NoxfileInfo | None) -> bool | None:
166167
return True
167168

168169

169-
class NOX201(Noxfile):
170+
class NOX201(Nox):
170171
"Set a script block with dependencies in your noxfile"
171172

172173
@staticmethod
173-
def check(noxfile: NoxfileInfo | None) -> bool | None:
174+
def check(noxfile: Noxfile | None) -> bool | None:
174175
"""
175176
You should have a script block with nox in it, for example:
176177
@@ -188,11 +189,11 @@ def check(noxfile: NoxfileInfo | None) -> bool | None:
188189
return False
189190

190191

191-
class NOX202(Noxfile):
192+
class NOX202(Nox):
192193
"Has a shebang line"
193194

194195
@staticmethod
195-
def check(noxfile: NoxfileInfo | None) -> bool | None:
196+
def check(noxfile: Noxfile | None) -> bool | None:
196197
"""
197198
You should have a shebang line at the top of your noxfile.py, for example:
198199
@@ -205,11 +206,11 @@ def check(noxfile: NoxfileInfo | None) -> bool | None:
205206
return bool(noxfile.shebang)
206207

207208

208-
class NOX203(Noxfile):
209+
class NOX203(Nox):
209210
"Provide a main block to run nox"
210211

211212
@staticmethod
212-
def check(noxfile: NoxfileInfo | None) -> bool | None:
213+
def check(noxfile: Noxfile | None) -> bool | None:
213214
"""
214215
You should have a main block at the bottom of your noxfile.py, for example:
215216
@@ -235,8 +236,8 @@ def check(noxfile: NoxfileInfo | None) -> bool | None:
235236

236237

237238
def repo_review_checks(
238-
list_all: bool = True, noxfile: NoxfileInfo | None = None
239-
) -> dict[str, Noxfile]:
239+
list_all: bool = True, noxfile: Noxfile | None = None
240+
) -> dict[str, Nox]:
240241
if not list_all and noxfile is None:
241242
return {}
242-
return {p.__name__: p() for p in Noxfile.__subclasses__()}
243+
return {p.__name__: p() for p in Nox.__subclasses__()}
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from repo_review.testing import compute_check
44

5-
from sp_repo_review.checks.noxfile import NoxfileInfo
5+
from sp_repo_review.checks.noxfile import Noxfile
66

77

88
def test_nox101():
@@ -15,7 +15,7 @@ def test_nox101():
1515
def tests(session):
1616
session.run("pytest", "tests")
1717
""")
18-
result = compute_check("NOX101", noxfile=NoxfileInfo.from_str(noxfile))
18+
result = compute_check("NOX101", noxfile=Noxfile.from_str(noxfile))
1919
assert result.result
2020

2121

@@ -27,7 +27,7 @@ def test_nox101_invalid():
2727
def tests(session):
2828
session.run("pytest", "tests")
2929
""")
30-
result = compute_check("NOX101", noxfile=NoxfileInfo.from_str(noxfile))
30+
result = compute_check("NOX101", noxfile=Noxfile.from_str(noxfile))
3131
assert result.result is False
3232

3333

@@ -40,7 +40,7 @@ def test_nox102():
4040
def tests(session):
4141
session.run("pytest", "tests")
4242
""")
43-
result = compute_check("NOX102", noxfile=NoxfileInfo.from_str(noxfile))
43+
result = compute_check("NOX102", noxfile=Noxfile.from_str(noxfile))
4444
assert result.result
4545

4646

@@ -52,7 +52,7 @@ def test_nox102_invalid():
5252
def tests(session):
5353
session.run("pytest", "tests")
5454
""")
55-
result = compute_check("NOX102", noxfile=NoxfileInfo.from_str(noxfile))
55+
result = compute_check("NOX102", noxfile=Noxfile.from_str(noxfile))
5656
assert result.result is False
5757

5858

@@ -64,7 +64,7 @@ def test_nox103():
6464
def tests(session):
6565
session.run("pytest", "tests")
6666
""")
67-
result = compute_check("NOX103", noxfile=NoxfileInfo.from_str(noxfile))
67+
result = compute_check("NOX103", noxfile=Noxfile.from_str(noxfile))
6868
assert result.result is True
6969

7070

@@ -78,7 +78,7 @@ def test_nox103_invalid():
7878
def tests(session):
7979
session.run("pytest", "tests")
8080
""")
81-
result = compute_check("NOX103", noxfile=NoxfileInfo.from_str(noxfile))
81+
result = compute_check("NOX103", noxfile=Noxfile.from_str(noxfile))
8282
assert result.result is False
8383

8484

@@ -92,15 +92,15 @@ def test_nox201():
9292
9393
import nox
9494
""")
95-
result = compute_check("NOX201", noxfile=NoxfileInfo.from_str(noxfile))
95+
result = compute_check("NOX201", noxfile=Noxfile.from_str(noxfile))
9696
assert result.result
9797

9898

9999
def test_nox201_invalid():
100100
noxfile = inspect.cleandoc("""
101101
import nox
102102
""")
103-
result = compute_check("NOX201", noxfile=NoxfileInfo.from_str(noxfile))
103+
result = compute_check("NOX201", noxfile=Noxfile.from_str(noxfile))
104104
assert result.result is False
105105

106106

@@ -110,15 +110,15 @@ def test_nox202():
110110
111111
import nox
112112
""")
113-
result = compute_check("NOX202", noxfile=NoxfileInfo.from_str(noxfile))
113+
result = compute_check("NOX202", noxfile=Noxfile.from_str(noxfile))
114114
assert result.result
115115

116116

117117
def test_nox202_invalid():
118118
noxfile = inspect.cleandoc("""
119119
import nox
120120
""")
121-
result = compute_check("NOX202", noxfile=NoxfileInfo.from_str(noxfile))
121+
result = compute_check("NOX202", noxfile=Noxfile.from_str(noxfile))
122122
assert result.result is False
123123

124124

@@ -133,7 +133,7 @@ def tests(session):
133133
if __name__ == "__main__":
134134
nox.main()
135135
""")
136-
result = compute_check("NOX203", noxfile=NoxfileInfo.from_str(noxfile))
136+
result = compute_check("NOX203", noxfile=Noxfile.from_str(noxfile))
137137
assert result.result
138138

139139

@@ -145,5 +145,5 @@ def tests_nox203_invalid():
145145
def tests(session):
146146
session.run("pytest", "tests")
147147
""")
148-
result = compute_check("NOX203", noxfile=NoxfileInfo.from_str(noxfile))
148+
result = compute_check("NOX203", noxfile=Noxfile.from_str(noxfile))
149149
assert result.result is False

0 commit comments

Comments
 (0)