Skip to content

Commit

Permalink
Enable the rest of the ruff rulesets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Jan 5, 2024
1 parent 29e2270 commit 3d778d6
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 36 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def entire_domain(host):
linkcheck_ignore = [
entire_domain("img.shields.io"),
"https://github.com/python-jsonschema/sphinx-json-schema-spec/actions",
"https://github.com/python-jsonschema/sphinx-json-schema-spec/workflows/CI/badge.svg", # noqa: E501
"https://github.com/python-jsonschema/sphinx-json-schema-spec/workflows/CI/badge.svg",
]

# = Extensions =
Expand Down
44 changes: 39 additions & 5 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,51 @@
DOCS = ROOT / "docs"
PACKAGE = ROOT / "sphinx_json_schema_spec"

REQUIREMENTS = dict(
docs=DOCS / "requirements.txt",
)
REQUIREMENTS_IN = [ # this is actually ordered, as files depend on each other
path.parent / f"{path.stem}.in" for path in REQUIREMENTS.values()
]

SUPPORTED = ["3.11", "3.12"]
LATEST = "3.12"

nox.options.sessions = []


def session(default=True, **kwargs):
def session(default=True, python=LATEST, **kwargs): # noqa: D103
def _session(fn):
if default:
nox.options.sessions.append(kwargs.get("name", fn.__name__))
return nox.session(**kwargs)(fn)
return nox.session(python=python, **kwargs)(fn)

return _session


@session(python=["3.11", "3.12"])
@session(python=SUPPORTED)
def tests(session):
"""
Run the test suite with a corresponding Python version.
"""
session.install("pytest", ROOT)
session.run("pytest", *session.posargs, PACKAGE)


@session()
def audit(session):
"""
Audit dependencies for vulnerabilities.
"""
session.install("pip-audit", ROOT)
session.run("python", "-m", "pip_audit")


@session(tags=["build"])
def build(session):
"""
Build a distribution suitable for PyPI and check its validity.
"""
session.install("build", "twine")
with TemporaryDirectory() as tmpdir:
session.run("python", "-m", "build", ROOT, "--outdir", tmpdir)
Expand All @@ -43,12 +61,18 @@ def build(session):

@session(tags=["style"])
def style(session):
"""
Check Python code style.
"""
session.install("ruff")
session.run("ruff", "check", ROOT)


@session()
def typing(session):
"""
Check static typing.
"""
session.install("mypy", "types-docutils", "types-lxml", ROOT)
session.run("python", "-m", "mypy", PACKAGE)

Expand All @@ -68,7 +92,10 @@ def typing(session):
],
)
def docs(session, builder):
session.install("-r", DOCS / "requirements.txt")
"""
Build the documentation using a specific Sphinx builder.
"""
session.install("-r", REQUIREMENTS["docs"])
with TemporaryDirectory() as tmpdir_str:
tmpdir = Path(tmpdir_str)
argv = ["-n", "-T", "-W"]
Expand All @@ -89,6 +116,9 @@ def docs(session, builder):

@session(tags=["docs", "style"], name="docs(style)")
def docs_style(session):
"""
Check the documentation style.
"""
session.install(
"doc8",
"pygments",
Expand All @@ -99,12 +129,16 @@ def docs_style(session):

@session(default=False)
def requirements(session):
"""
Update the project's pinned requirements. Commit the result.
"""
session.install("pip-tools")
for each in [DOCS / "requirements.in"]:
for each in REQUIREMENTS_IN:
session.run(
"pip-compile",
"--resolver",
"backtracking",
"--strip-extras",
"-U",
each.relative_to(ROOT),
)
85 changes: 58 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ source = "vcs"
[project]
name = "sphinx_json_schema_spec"
description = "Sphinx support for the JSON Schema specifications"
requires-python = ">=3.11"
readme = "README.rst"
license = {text = "MIT"}
requires-python = ">=3.11"
keywords = ["json schema", "jsonschema", "data validation", "sphinx", "json"]
authors = [
{email = "Julian+sphinx-json-schema-spec@GrayVines.com"},
Expand All @@ -31,61 +31,92 @@ classifiers = [
"Topic :: File Formats :: JSON :: JSON Schema",
]
dynamic = ["version"]

dependencies = [
"lxml",
"sphinx>=5.1.1",
]

[project.urls]
Documentation = "https://sphinx-json-schema-spec.readthedocs.io/"
Homepage = "https://github.com/python-jsonschema/sphinx-json-schema-spec"
Documentation = "https://sphinx-json-schema-spec.readthedocs.io/"
Issues = "https://github.com/python-jsonschema/sphinx-json-schema-spec/issues/"
Funding = "https://github.com/sponsors/Julian"
Source = "https://github.com/python-jsonschema/sphinx-json-schema-spec"

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

[tool.isort]
combine_as_imports = true
ensure_newline_before_comments = true
from_first = true
include_trailing_comma = true
multi_line_output = 3
use_parentheses = true

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

[tool.ruff.lint.flake8-pytest-style]
mark-parentheses = false

[tool.ruff.flake8-quotes]
docstring-quotes = "double"

[tool.ruff.lint.isort]
combine-as-imports = true
from-first = true

[tool.ruff.per-file-ignores]
"docs/*" = ["ANN", "D"]
"sphinx_json_schema_spec/tests/*" = ["ANN", "D"]
"noxfile.py" = ["ANN", "D"]
"noxfile.py" = ["ANN", "D100", "S101", "T201"]
"docs/*" = ["ANN", "D", "INP001"]
"sphinx_json_schema_spec/tests/*" = ["ANN", "D", "RUF012", "S", "PLR", "TRY"]
6 changes: 3 additions & 3 deletions sphinx_json_schema_spec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"validation": urljoin(BASE_URL, "json-schema-validation.html"),
}
HARDCODED = {
"$dynamicRef": "https://json-schema.org/draft/2020-12/json-schema-core.html#dynamic-ref", # noqa: E501
"$dynamicRef": "https://json-schema.org/draft/2020-12/json-schema-core.html#dynamic-ref",
"$ref": "https://json-schema.org/draft/2020-12/json-schema-core.html#ref",
"format": "https://json-schema.org/draft/2020-12/json-schema-validation.html#name-implementation-requirements", # noqa: E501
"format": "https://json-schema.org/draft/2020-12/json-schema-validation.html#name-implementation-requirements",
}


Expand Down Expand Up @@ -80,7 +80,7 @@ def fetch_or_load(cache_path, url):
context = ssl.create_default_context()
response = urllib.request.urlopen(request, context=context)

if response.code == 200:
if response.code == 200: # noqa: PLR2004
with cache_path.open("w+b") as out:
out.writelines(response)
out.seek(0)
Expand Down

0 comments on commit 3d778d6

Please sign in to comment.