Repository navigation
Expand file tree
/
Copy pathnoxfile.py
More file actions
129 lines (91 loc) · 3.29 KB
/
Copy pathnoxfile.py
File metadata and controls
129 lines (91 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# SPDX-FileCopyrightText: 2012 Hynek Schlawack <hs@ox.cx>
#
# SPDX-License-Identifier: MIT
from __future__ import annotations
import os
import re
import shutil
import sys
from pathlib import Path
import nox
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
DEFAULT_PYTHON = Path(".python-version-default").read_text().strip()
nox.options.sessions = ["pre_commit", "tests", "docs", "mypy"]
nox.options.reuse_existing_virtualenvs = True
nox.options.error_on_external_run = True
nox.needs_version = ">=2024.3.2"
nox.options.default_venv_backend = "uv|virtualenv"
MATCH_PYTHON = re.compile(r"\s+python\: \"(\d\.\d\d)\"").match
# Avoid dependency on a YAML lib using a questionable hack.
for line in Path(".readthedocs.yaml").read_text().splitlines():
if m := MATCH_PYTHON(line):
DOCS_PYTHON = m.group(1)
break
pyp = tomllib.loads(Path("pyproject.toml").read_text())
ALL_SUPPORTED = [
pv.rsplit(" ")[-1]
for pv in pyp["project"]["classifiers"]
if pv.startswith("Programming Language :: Python :: ")
]
@nox.session
def pre_commit(session: nox.Session) -> None:
session.install("prek")
session.run("prek", "run", "--all-files")
@nox.session(python=["pypy3.10", *ALL_SUPPORTED])
def tests(session: nox.Session) -> None:
session.install(".", "--group", "tests")
# Ensure that rich doesn't add format sequences.
env = {"TERM": "dumb"}
session.run("coverage", "run", "-m", "pytest", *session.posargs, env=env)
session.run("coverage", "run", "-m", "doc2dash", "--version")
if os.environ.get("CI") != "true":
session.notify("coverage_report")
@nox.session
def coverage_report(session: nox.Session) -> None:
session.install("coverage[toml]")
session.run("coverage", "combine")
session.run("coverage", "report")
@nox.session(python=DEFAULT_PYTHON)
def mypy(session: nox.Session) -> None:
session.install(".", "--group", "typing", "nox")
session.run("mypy", "src", "noxfile.py")
@nox.session
def rebuild_sample_docs(session: nox.Session) -> None:
session.install(".", "sphinx")
session.chdir(
Path("tests") / "parsers" / "intersphinx" / "example-sphinx-docs"
)
# Awkward name to avoid "_build" / "build" from .gitignore.
session.run("sphinx-build", "-M", "html", "source", "built_docs")
# Clean up stuff we don't need.
built = Path("built_docs")
html = built / "html"
shutil.rmtree(built / "doctrees")
shutil.rmtree(html / "_sources")
shutil.rmtree(html / "_static")
(html / ".buildinfo").unlink()
(html / "searchindex.js").unlink()
@nox.session(python=DOCS_PYTHON)
def docs(session: nox.Session) -> None:
# Needs to be separate when using hashes.
session.install("-r", "requirements/docs.txt")
session.install("-e", ".")
if session.posargs:
session.run("zensical", *session.posargs)
else:
session.run("zensical", "build", "--clean", "--strict")
@nox.session(python=DOCS_PYTHON)
def pin_docs(session: nox.Session) -> None:
session.install("uv")
session.run(
"uv", "pip", "compile",
"--upgrade",
"--group", "docs",
"--index-url", "https://pypi.org/simple",
"--generate-hashes",
"--output-file", "requirements/docs.txt",
"pyproject.toml",
) # fmt: skip