-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable the rest of the ruff rulesets.
Bring the rest of the scaffolding up to date.
- Loading branch information
Showing
7 changed files
with
259 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,159 @@ | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
import os | ||
|
||
import nox | ||
|
||
ROOT = Path(__file__).parent | ||
TESTS = ROOT / "tests" | ||
PYPROJECT = ROOT / "pyproject.toml" | ||
DOCS = ROOT / "docs" | ||
|
||
REQUIREMENTS = dict( | ||
docs=DOCS / "requirements.txt", | ||
tests=TESTS / "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.8", "3.9", "3.10", "3.11", "3.12", "pypy3.10"] | ||
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.8", "3.9", "3.10", "3.11", "3.12", "pypy3"]) | ||
@session(python=SUPPORTED) | ||
def tests(session): | ||
session.install(ROOT, "-r", TESTS / "requirements.txt") | ||
if session.posargs == ["coverage"]: | ||
""" | ||
Run the test suite with a corresponding Python version. | ||
""" | ||
session.install("-r", REQUIREMENTS["tests"]) | ||
|
||
if session.posargs and session.posargs[0] == "coverage": | ||
if len(session.posargs) > 1 and session.posargs[1] == "github": | ||
github = Path(os.environ["GITHUB_STEP_SUMMARY"]) | ||
else: | ||
github = None | ||
|
||
session.install("coverage[toml]") | ||
session.run("coverage", "run", "-m", "pytest") | ||
session.run("coverage", "report") | ||
session.run("coverage", "run", "-m", "pytest", TESTS) | ||
if github is None: | ||
session.run("coverage", "report") | ||
else: | ||
with github.open("a") as summary: | ||
summary.write("### Coverage\n\n") | ||
summary.flush() # without a flush, output seems out of order. | ||
session.run( | ||
"coverage", | ||
"report", | ||
"--format=markdown", | ||
stdout=summary, | ||
) | ||
else: | ||
session.run("pytest", *session.posargs, TESTS) | ||
|
||
|
||
@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) | ||
session.run("twine", "check", "--strict", tmpdir + "/*") | ||
|
||
|
||
@session(tags=["style"]) | ||
def style(session): | ||
""" | ||
Check Python code style. | ||
""" | ||
session.install("ruff") | ||
session.run("ruff", "check", ROOT) | ||
|
||
|
||
@session(tags=["docs"]) | ||
@nox.parametrize( | ||
"builder", | ||
[ | ||
nox.param(name, id=name) | ||
for name in [ | ||
"dirhtml", | ||
"doctest", | ||
"linkcheck", | ||
"man", | ||
"spelling", | ||
] | ||
], | ||
) | ||
def docs(session, builder): | ||
""" | ||
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"] | ||
if builder != "spelling": | ||
argv += ["-q"] | ||
posargs = session.posargs or [tmpdir / builder] | ||
session.run( | ||
"python", | ||
"-m", | ||
"sphinx", | ||
"-b", | ||
builder, | ||
DOCS, | ||
*argv, | ||
*posargs, | ||
) | ||
|
||
|
||
@session(tags=["docs", "style"], name="docs(style)") | ||
def docs_style(session): | ||
""" | ||
Check the documentation style. | ||
""" | ||
session.install( | ||
"doc8", | ||
"pygments", | ||
"pygments-github-lexers", | ||
) | ||
session.run("python", "-m", "doc8", "--config", PYPROJECT, DOCS) | ||
|
||
|
||
@session(default=False) | ||
def requirements(session): | ||
""" | ||
Update the project's pinned requirements. Commit the result. | ||
""" | ||
session.install("pip-tools") | ||
for each in [TESTS / "requirements.in"]: | ||
for each in REQUIREMENTS_IN: | ||
session.run( | ||
"pip-compile", | ||
"--resolver", | ||
"backtracking", | ||
"--strip-extras", | ||
"-U", | ||
each.relative_to(ROOT), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.