Skip to content

Commit 3f6575d

Browse files
committed
WIP: some additions
Signed-off-by: Henry Schreiner <[email protected]>
1 parent f23a60a commit 3f6575d

File tree

4 files changed

+80
-32
lines changed

4 files changed

+80
-32
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ for family, grp in itertools.groupby(collected.checks.items(), key=lambda x: x[1
336336
- [`RTD101`](https://learn.scientific-python.org/development/guides/docs#RTD101): You have to set the RTD version number to 2
337337
- [`RTD102`](https://learn.scientific-python.org/development/guides/docs#RTD102): You have to set the RTD build image
338338
- [`RTD103`](https://learn.scientific-python.org/development/guides/docs#RTD103): You have to set the RTD python version
339+
- [`RTD104`](https://learn.scientific-python.org/development/guides/docs#RTD104): You have to specify a build configuration now for readthedocs.
339340

340341
### GitHub Actions
341342
- [`GH100`](https://learn.scientific-python.org/development/guides/gha-basic#GH100): Has GitHub Actions config

docs/pages/guides/docs.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,14 @@ Ideally, software documentation should include:
6464
6565
<!-- [[[cog
6666
from cog_helpers import code_fence, render_cookie, Matcher
67-
with render_cookie() as package:
67+
with render_cookie(backend="hatch", docs="sphinx") as package:
6868
docs_conf_py = package.joinpath("docs/conf.py").read_text(encoding="utf-8").strip()
6969
docs_index_md = package.joinpath("docs/index.md").read_text(encoding="utf-8").strip()
7070
readthedocs_yaml = package.joinpath(".readthedocs.yaml").read_text(encoding="utf-8").strip()
7171
noxfile = Matcher.from_file(package / "noxfile.py")
72+
with render_cookie(backend="hatch", docs="sphinx") as package:
73+
noxfile_mkdocs = Matcher.from_file(package / "noxfile.py")
74+
readthedocs_yaml_mkdocs = package.joinpath(".readthedocs.yaml").read_text(encoding="utf-8").strip()
7275
]]] -->
7376
<!-- [[[end]]] -->
7477

@@ -494,7 +497,7 @@ build:
494497

495498
<!-- [[[cog
496499
with code_fence("yaml"):
497-
print(readthedocs_yaml)
500+
print(readthedocs_yaml_mkdocs)
498501
]]] -->
499502
<!-- prettier-ignore-start -->
500503
```yaml
@@ -591,7 +594,7 @@ autobuild will rebuild if you change a file while serving.
591594

592595
<!-- [[[cog
593596
with code_fence("python"):
594-
print(noxfile.get_source("docs"))
597+
print(noxfile_mkdocs.get_source("docs"))
595598
]]] -->
596599
<!-- prettier-ignore-start -->
597600
```python

noxfile.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import difflib
1616
import email.parser
1717
import email.policy
18+
import enum
1819
import functools
1920
import json
2021
import os
@@ -38,6 +39,11 @@
3839
nox.options.default_venv_backend = "uv|virtualenv"
3940

4041

42+
class Docs(enum.Enum):
43+
Sphinx = "sphinx"
44+
MkDocs = "mkdocs"
45+
46+
4147
DIR = Path(__file__).parent.resolve()
4248
with DIR.joinpath("cookiecutter.json").open() as f:
4349
BACKENDS = json.load(f)["backend"]
@@ -47,6 +53,7 @@
4753
project_name: cookie-{backend}
4854
backend: {backend}
4955
vcs: {vcs}
56+
docs: {docs}
5057
"""
5158

5259

@@ -66,7 +73,7 @@ def get_expected_version(backend: str, vcs: bool) -> str:
6673
return "0.2.3" if vcs and backend not in {"maturin", "mesonpy", "uv"} else "0.1.0"
6774

6875

69-
def make_copier(session: nox.Session, backend: str, vcs: bool) -> Path:
76+
def make_copier(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> Path:
7077
package_dir = Path(f"copy-{backend}")
7178
if package_dir.exists():
7279
rmtree_ro(package_dir)
@@ -86,20 +93,21 @@ def make_copier(session: nox.Session, backend: str, vcs: bool) -> Path:
8693
8794
"--data=license=BSD",
8895
f"--data=vcs={vcs}",
96+
f"--data=docs={docs.value}",
8997
)
9098

9199
init_git(session, package_dir)
92100

93101
return package_dir
94102

95103

96-
def make_cookie(session: nox.Session, backend: str, vcs: bool) -> Path:
104+
def make_cookie(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> Path:
97105
package_dir = Path(f"cookie-{backend}")
98106
if package_dir.exists():
99107
rmtree_ro(package_dir)
100108

101109
Path("input.yml").write_text(
102-
JOB_FILE.format(backend=backend, vcs=vcs), encoding="utf-8"
110+
JOB_FILE.format(backend=backend, vcs=vcs, docs=docs.value), encoding="utf-8"
103111
)
104112

105113
session.run(
@@ -114,7 +122,7 @@ def make_cookie(session: nox.Session, backend: str, vcs: bool) -> Path:
114122
return package_dir
115123

116124

117-
def make_cruft(session: nox.Session, backend: str, vcs: bool) -> Path:
125+
def make_cruft(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> Path:
118126
package_dir = Path(f"cruft-{backend}")
119127
if package_dir.exists():
120128
rmtree_ro(package_dir)
@@ -124,7 +132,8 @@ def make_cruft(session: nox.Session, backend: str, vcs: bool) -> Path:
124132

125133
session.cd(tmp_dir)
126134
Path("input.yml").write_text(
127-
JOB_FILE.format(backend=backend, pkg=package_dir, vcs=vcs), encoding="utf-8"
135+
JOB_FILE.format(backend=backend, pkg=package_dir, vcs=vcs, docs=docs),
136+
encoding="utf-8",
128137
)
129138
session.run(
130139
"cruft",
@@ -189,14 +198,15 @@ def diff_files(p1: Path, p2: Path) -> bool:
189198

190199

191200
@nox.session(default=False)
201+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
192202
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
193203
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
194-
def lint(session: nox.Session, backend: str, vcs: bool) -> None:
204+
def lint(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
195205
session.install("cookiecutter", "pre-commit")
196206

197207
tmp_dir = session.create_tmp()
198208
session.cd(tmp_dir)
199-
cookie = make_cookie(session, backend, vcs)
209+
cookie = make_cookie(session, backend, vcs, docs)
200210
session.chdir(cookie)
201211

202212
session.run(
@@ -215,22 +225,23 @@ def autoupdate(session: nox.Session, backend: str) -> None:
215225

216226
tmp_dir = session.create_tmp()
217227
session.cd(tmp_dir)
218-
cookie = make_cookie(session, backend, True)
228+
cookie = make_cookie(session, backend, True, Docs.Sphinx)
219229
session.chdir(cookie)
220230

221231
session.run("pre-commit", "autoupdate")
222232
session.run("git", "diff", "--exit-code", external=True)
223233

224234

225235
@nox.session(default=False)
236+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
226237
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
227238
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
228-
def tests(session: nox.Session, backend: str, vcs: bool) -> None:
239+
def tests(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
229240
session.install("cookiecutter")
230241

231242
tmp_dir = session.create_tmp()
232243
session.cd(tmp_dir)
233-
cookie = make_cookie(session, backend, vcs)
244+
cookie = make_cookie(session, backend, vcs, docs)
234245
session.chdir(cookie)
235246

236247
name = f"cookie-{backend}"
@@ -249,14 +260,15 @@ def tests(session: nox.Session, backend: str, vcs: bool) -> None:
249260

250261

251262
@nox.session(default=False)
263+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
252264
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
253265
@nox.parametrize("backend", ("poetry", "pdm", "hatch"), ids=("poetry", "pdm", "hatch"))
254-
def native(session: nox.Session, backend: str, vcs: bool) -> None:
266+
def native(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
255267
session.install("cookiecutter", backend)
256268

257269
tmp_dir = session.create_tmp()
258270
session.cd(tmp_dir)
259-
cookie = make_cookie(session, backend, vcs)
271+
cookie = make_cookie(session, backend, vcs, docs)
260272
session.chdir(cookie)
261273

262274
if backend == "hatch":
@@ -270,14 +282,15 @@ def native(session: nox.Session, backend: str, vcs: bool) -> None:
270282

271283

272284
@nox.session(default=False)
285+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
273286
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
274287
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
275-
def dist(session: nox.Session, backend: str, vcs: bool) -> None:
288+
def dist(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
276289
session.install("cookiecutter", "build", "twine")
277290

278291
tmp_dir = session.create_tmp()
279292
session.cd(tmp_dir)
280-
cookie = make_cookie(session, backend, vcs)
293+
cookie = make_cookie(session, backend, vcs, docs)
281294
session.chdir(cookie)
282295

283296
session.run("python", "-m", "build", silent=True)
@@ -333,14 +346,15 @@ def dist(session: nox.Session, backend: str, vcs: bool) -> None:
333346

334347

335348
@nox.session(name="nox", default=False)
349+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
336350
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
337351
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
338-
def nox_session(session: nox.Session, backend: str, vcs: bool) -> None:
352+
def nox_session(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
339353
session.install("cookiecutter", "nox")
340354

341355
tmp_dir = session.create_tmp()
342356
session.cd(tmp_dir)
343-
cookie = make_cookie(session, backend, vcs)
357+
cookie = make_cookie(session, backend, vcs, docs)
344358
session.chdir(cookie)
345359

346360
if session.posargs:
@@ -358,13 +372,14 @@ def compare_copier(session):
358372

359373
for backend in BACKENDS:
360374
for vcs in (False, True):
361-
cookie = make_cookie(session, backend, vcs)
362-
copier = make_copier(session, backend, vcs)
375+
for docs in Docs:
376+
cookie = make_cookie(session, backend, vcs, docs)
377+
copier = make_copier(session, backend, vcs, docs)
363378

364-
if diff_files(cookie, copier):
365-
session.log(f"{backend} {vcs=} passed")
366-
else:
367-
session.error(f"{backend} {vcs=} files are not the same!")
379+
if diff_files(cookie, copier):
380+
session.log(f"{backend} {vcs=} passed")
381+
else:
382+
session.error(f"{backend} {vcs=} files are not the same!")
368383

369384

370385
@nox.session(default=False)
@@ -376,13 +391,14 @@ def compare_cruft(session):
376391

377392
for backend in BACKENDS:
378393
for vcs in (False, True):
379-
cookie = make_cookie(session, backend, vcs)
380-
cruft = make_cruft(session, backend, vcs)
381-
382-
if diff_files(cookie, cruft):
383-
session.log(f"{backend} {vcs=} passed")
384-
else:
385-
session.error(f"{backend} {vcs=} files are not the same!")
394+
for docs in Docs:
395+
cookie = make_cookie(session, backend, vcs, docs)
396+
cruft = make_cruft(session, backend, vcs, docs)
397+
398+
if diff_files(cookie, cruft):
399+
session.log(f"{backend} {vcs=} passed")
400+
else:
401+
session.error(f"{backend} {vcs=} files are not the same!")
386402

387403

388404
PC_VERS = re.compile(

src/sp_repo_review/checks/readthedocs.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,34 @@ def check(readthedocs: dict[str, Any]) -> bool:
104104
return False
105105

106106

107+
class RTD104(ReadTheDocs):
108+
"You have to specify a build configuration now for readthedocs."
109+
110+
requires = {"RTD100"}
111+
112+
@staticmethod
113+
def check(readthedocs: dict[str, Any]) -> bool:
114+
"""
115+
You must set `sphinx: configuration:`, `mkdocs: configuration:` or
116+
`build: commands:`. Skipping it is no longer allowed. Example:
117+
118+
```yaml
119+
sphinx:
120+
configuration: docs/conf.py
121+
```
122+
"""
123+
124+
match readthedocs:
125+
case {"build": {"commands": list()}}:
126+
return True
127+
case {"sphinx": {"configuration": str()}}:
128+
return True
129+
case {"mkdocs": {"configuration": str()}}:
130+
return True
131+
case _:
132+
return False
133+
134+
107135
def readthedocs(root: Traversable) -> dict[str, Any]:
108136
for path in (".readthedocs.yaml", ".readthedocs.yml"):
109137
readthedocs_path = root.joinpath(path)

0 commit comments

Comments
 (0)