Skip to content

Commit

Permalink
Some extra style rules and docstrings for the noxfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Oct 23, 2023
1 parent a177b74 commit 1e79632
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
27 changes: 25 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
nox.options.sessions = []


def session(default=True, **kwargs):
def session(default=True, **kwargs): # noqa: D103
def _session(fn):
if default:
nox.options.sessions.append(kwargs.get("name", fn.__name__))
Expand All @@ -24,19 +24,28 @@ def _session(fn):

@session(python=["3.8", "3.9", "3.10", "3.11", "3.12", "pypy3"])
def tests(session):
"""
Run the test suite with a corresponding Python version.
"""
session.install("pytest", ROOT)
env = dict(os.environ, PYTHONWARNDEFAULTENCODING="1")
session.run("pytest", "--verbosity=3", "--pythonwarnings=error", env=env)


@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 @@ -45,12 +54,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", ROOT)
session.run("python", "-m", "mypy", PACKAGE)

Expand All @@ -70,26 +85,33 @@ def typing(session):
],
)
def docs(session, builder):
"""
Build the documentation using a specific Sphinx builder.
"""
session.install("-r", DOCS / "requirements.txt")
with TemporaryDirectory() as tmpdir_str:
tmpdir = Path(tmpdir_str)
argv = ["-n", "-T", "-W"]
if builder != "spelling":
argv += ["-q"]
posargs = session.posargs or [tmpdir / builder]
session.run(
"python",
"-m",
"sphinx",
"-b",
builder,
DOCS,
tmpdir / builder,
*argv,
*posargs,
)


@session(tags=["docs", "style"], name="docs(style)")
def docs_style(session):
"""
Check the documentation style.
"""
session.install(
"doc8",
"pygments",
Expand All @@ -109,6 +131,7 @@ def requirements(session):
"pip-compile",
"--resolver",
"backtracking",
"--strip-extras",
"-U",
each.relative_to(ROOT),
)
13 changes: 10 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ authors = [
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
Expand Down Expand Up @@ -82,7 +83,7 @@ multi_line_output = 3
[tool.ruff]
line-length = 79
target-version = "py38"
select = ["ANN", "B", "D", "E", "F", "Q", "UP", "W"]
select = ["ANN", "B", "D", "D204", "E", "F", "Q", "RUF", "SIM", "UP", "W"]
ignore = [
# Wat, type annotations for self and cls, why is this a thing?
"ANN101",
Expand All @@ -91,10 +92,16 @@ ignore = [
"ANN202",
# I don't know how to more properly annotate "pass along all arguments".
"ANN401",
# It's totally OK to call functions for default arguments.
"B008",
# raise SomeException(...) is fine.
"B904",
# There's no need for explicit strict, this is simply zip's default behavior.
"B905",
# It's fine to not have docstrings for magic methods.
"D105",
# __init__ especially doesn't need a docstring
"D107",
# This rule makes diffs uglier when expanding docstrings (and it's uglier)
"D200",
# No blank lines before docstrings.
Expand All @@ -118,6 +125,6 @@ extend-exclude = ["suite"]
docstring-quotes = "double"

[tool.ruff.per-file-ignores]
"noxfile.py" = ["ANN", "D100"]
"docs/*" = ["ANN", "D"]
"jsonschema_specifications/tests/*" = ["ANN", "D"]
"noxfile.py" = ["ANN", "D"]
"jsonschema_specifications/tests/*" = ["ANN", "D", "RUF012"]

0 comments on commit 1e79632

Please sign in to comment.