Skip to content

Commit 3d778d6

Browse files
committed
Enable the rest of the ruff rulesets.
1 parent 29e2270 commit 3d778d6

File tree

4 files changed

+101
-36
lines changed

4 files changed

+101
-36
lines changed

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def entire_domain(host):
3737
linkcheck_ignore = [
3838
entire_domain("img.shields.io"),
3939
"https://github.com/python-jsonschema/sphinx-json-schema-spec/actions",
40-
"https://github.com/python-jsonschema/sphinx-json-schema-spec/workflows/CI/badge.svg", # noqa: E501
40+
"https://github.com/python-jsonschema/sphinx-json-schema-spec/workflows/CI/badge.svg",
4141
]
4242

4343
# = Extensions =

noxfile.py

+39-5
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,51 @@
88
DOCS = ROOT / "docs"
99
PACKAGE = ROOT / "sphinx_json_schema_spec"
1010

11+
REQUIREMENTS = dict(
12+
docs=DOCS / "requirements.txt",
13+
)
14+
REQUIREMENTS_IN = [ # this is actually ordered, as files depend on each other
15+
path.parent / f"{path.stem}.in" for path in REQUIREMENTS.values()
16+
]
17+
18+
SUPPORTED = ["3.11", "3.12"]
19+
LATEST = "3.12"
1120

1221
nox.options.sessions = []
1322

1423

15-
def session(default=True, **kwargs):
24+
def session(default=True, python=LATEST, **kwargs): # noqa: D103
1625
def _session(fn):
1726
if default:
1827
nox.options.sessions.append(kwargs.get("name", fn.__name__))
19-
return nox.session(**kwargs)(fn)
28+
return nox.session(python=python, **kwargs)(fn)
2029

2130
return _session
2231

2332

24-
@session(python=["3.11", "3.12"])
33+
@session(python=SUPPORTED)
2534
def tests(session):
35+
"""
36+
Run the test suite with a corresponding Python version.
37+
"""
2638
session.install("pytest", ROOT)
2739
session.run("pytest", *session.posargs, PACKAGE)
2840

2941

3042
@session()
3143
def audit(session):
44+
"""
45+
Audit dependencies for vulnerabilities.
46+
"""
3247
session.install("pip-audit", ROOT)
3348
session.run("python", "-m", "pip_audit")
3449

3550

3651
@session(tags=["build"])
3752
def build(session):
53+
"""
54+
Build a distribution suitable for PyPI and check its validity.
55+
"""
3856
session.install("build", "twine")
3957
with TemporaryDirectory() as tmpdir:
4058
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
@@ -43,12 +61,18 @@ def build(session):
4361

4462
@session(tags=["style"])
4563
def style(session):
64+
"""
65+
Check Python code style.
66+
"""
4667
session.install("ruff")
4768
session.run("ruff", "check", ROOT)
4869

4970

5071
@session()
5172
def typing(session):
73+
"""
74+
Check static typing.
75+
"""
5276
session.install("mypy", "types-docutils", "types-lxml", ROOT)
5377
session.run("python", "-m", "mypy", PACKAGE)
5478

@@ -68,7 +92,10 @@ def typing(session):
6892
],
6993
)
7094
def docs(session, builder):
71-
session.install("-r", DOCS / "requirements.txt")
95+
"""
96+
Build the documentation using a specific Sphinx builder.
97+
"""
98+
session.install("-r", REQUIREMENTS["docs"])
7299
with TemporaryDirectory() as tmpdir_str:
73100
tmpdir = Path(tmpdir_str)
74101
argv = ["-n", "-T", "-W"]
@@ -89,6 +116,9 @@ def docs(session, builder):
89116

90117
@session(tags=["docs", "style"], name="docs(style)")
91118
def docs_style(session):
119+
"""
120+
Check the documentation style.
121+
"""
92122
session.install(
93123
"doc8",
94124
"pygments",
@@ -99,12 +129,16 @@ def docs_style(session):
99129

100130
@session(default=False)
101131
def requirements(session):
132+
"""
133+
Update the project's pinned requirements. Commit the result.
134+
"""
102135
session.install("pip-tools")
103-
for each in [DOCS / "requirements.in"]:
136+
for each in REQUIREMENTS_IN:
104137
session.run(
105138
"pip-compile",
106139
"--resolver",
107140
"backtracking",
141+
"--strip-extras",
108142
"-U",
109143
each.relative_to(ROOT),
110144
)

pyproject.toml

+58-27
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ source = "vcs"
88
[project]
99
name = "sphinx_json_schema_spec"
1010
description = "Sphinx support for the JSON Schema specifications"
11+
requires-python = ">=3.11"
1112
readme = "README.rst"
1213
license = {text = "MIT"}
13-
requires-python = ">=3.11"
1414
keywords = ["json schema", "jsonschema", "data validation", "sphinx", "json"]
1515
authors = [
1616
{email = "[email protected]"},
@@ -31,61 +31,92 @@ classifiers = [
3131
"Topic :: File Formats :: JSON :: JSON Schema",
3232
]
3333
dynamic = ["version"]
34-
3534
dependencies = [
3635
"lxml",
3736
"sphinx>=5.1.1",
3837
]
3938

4039
[project.urls]
41-
Documentation = "https://sphinx-json-schema-spec.readthedocs.io/"
4240
Homepage = "https://github.com/python-jsonschema/sphinx-json-schema-spec"
41+
Documentation = "https://sphinx-json-schema-spec.readthedocs.io/"
4342
Issues = "https://github.com/python-jsonschema/sphinx-json-schema-spec/issues/"
4443
Funding = "https://github.com/sponsors/Julian"
4544
Source = "https://github.com/python-jsonschema/sphinx-json-schema-spec"
4645

4746
[tool.doc8]
4847
ignore = [
48+
"D000", # see PyCQA/doc8#125
4949
"D001", # one sentence per line, so max length doesn't make sense
5050
]
5151

5252
[tool.isort]
5353
combine_as_imports = true
54+
ensure_newline_before_comments = true
5455
from_first = true
5556
include_trailing_comma = true
5657
multi_line_output = 3
58+
use_parentheses = true
5759

5860
[tool.ruff]
5961
line-length = 79
60-
select = ["B", "D", "E", "F", "Q", "UP", "W"]
62+
select = ["ALL"]
6163
ignore = [
62-
# raise SomeException(...) is fine.
63-
"B904",
64-
# It's fine to not have docstrings for magic methods.
65-
"D105",
66-
# This rule makes diffs uglier when expanding docstrings (and it's uglier)
67-
"D200",
68-
# No blank lines before docstrings.
69-
"D203",
70-
# Start docstrings on the second line.
71-
"D212",
72-
# This rule misses sassy docstrings ending with ! or ?.
73-
"D400",
74-
# Section headers should end with a colon not a newline
75-
"D406",
76-
# Underlines aren't needed
77-
"D407",
78-
# Plz spaces after section headers
79-
"D412",
80-
# We support 3.8 + 3.9
81-
"UP007",
64+
"A001", # It's fine to shadow builtins
65+
"A002",
66+
"A003",
67+
"ARG", # This is all wrong whenever an interface is involved
68+
"ANN", # Just let the type checker do this
69+
"B006", # Mutable arguments require care but are OK if you don't abuse them
70+
"B008", # It's totally OK to call functions for default arguments.
71+
"B904", # raise SomeException(...) is fine.
72+
"B905", # No need for explicit strict, this is simply zip's default behavior
73+
"C408", # Calling dict is fine when it saves quoting the keys
74+
"C901", # Not really something to focus on
75+
"D105", # It's fine to not have docstrings for magic methods.
76+
"D107", # __init__ especially doesn't need a docstring
77+
"D200", # This rule makes diffs uglier when expanding docstrings
78+
"D203", # No blank lines before docstrings.
79+
"D212", # Start docstrings on the second line.
80+
"D400", # This rule misses sassy docstrings ending with ! or ?
81+
"D401", # This rule is too flaky.
82+
"D406", # Section headers should end with a colon not a newline
83+
"D407", # Underlines aren't needed
84+
"D412", # Plz spaces after section headers
85+
"EM101", # These don't bother me, it's fine there's some duplication.
86+
"EM102",
87+
"FBT", # It's worth avoiding boolean args but I don't care to enforce it
88+
"FIX", # Yes thanks, if I could it wouldn't be there
89+
"I001", # We can't yet use ruff's isort
90+
"N", # These naming rules are silly
91+
"PLR0912", # These metrics are fine to be aware of but not to enforce
92+
"PLR0913",
93+
"PLR0915",
94+
"PLW2901", # Shadowing for loop variables is occasionally fine.
95+
"PT006", # pytest parametrize takes strings as well
96+
"PYI025", # wat, I'm not confused, thanks.
97+
"RET502", # Returning None implicitly is fine
98+
"RET503",
99+
"RET505", # These push you to use `if` instead of `elif`, but for no reason
100+
"RET506",
101+
"RSE102", # Ha, what, who even knew you could leave the parens off. But no.
102+
"S", # Security warnings with lots of false positives, as usual
103+
"SIM300", # Not sure what heuristic this uses, but it's easily incorrect
104+
"SLF001", # Private usage within this package itself is fine
105+
"TD", # These TODO style rules are also silly
82106
]
83107
extend-exclude = ["suite"]
84108

109+
[tool.ruff.lint.flake8-pytest-style]
110+
mark-parentheses = false
111+
85112
[tool.ruff.flake8-quotes]
86113
docstring-quotes = "double"
87114

115+
[tool.ruff.lint.isort]
116+
combine-as-imports = true
117+
from-first = true
118+
88119
[tool.ruff.per-file-ignores]
89-
"docs/*" = ["ANN", "D"]
90-
"sphinx_json_schema_spec/tests/*" = ["ANN", "D"]
91-
"noxfile.py" = ["ANN", "D"]
120+
"noxfile.py" = ["ANN", "D100", "S101", "T201"]
121+
"docs/*" = ["ANN", "D", "INP001"]
122+
"sphinx_json_schema_spec/tests/*" = ["ANN", "D", "RUF012", "S", "PLR", "TRY"]

sphinx_json_schema_spec/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"validation": urljoin(BASE_URL, "json-schema-validation.html"),
1919
}
2020
HARDCODED = {
21-
"$dynamicRef": "https://json-schema.org/draft/2020-12/json-schema-core.html#dynamic-ref", # noqa: E501
21+
"$dynamicRef": "https://json-schema.org/draft/2020-12/json-schema-core.html#dynamic-ref",
2222
"$ref": "https://json-schema.org/draft/2020-12/json-schema-core.html#ref",
23-
"format": "https://json-schema.org/draft/2020-12/json-schema-validation.html#name-implementation-requirements", # noqa: E501
23+
"format": "https://json-schema.org/draft/2020-12/json-schema-validation.html#name-implementation-requirements",
2424
}
2525

2626

@@ -80,7 +80,7 @@ def fetch_or_load(cache_path, url):
8080
context = ssl.create_default_context()
8181
response = urllib.request.urlopen(request, context=context)
8282

83-
if response.code == 200:
83+
if response.code == 200: # noqa: PLR2004
8484
with cache_path.open("w+b") as out:
8585
out.writelines(response)
8686
out.seek(0)

0 commit comments

Comments
 (0)