Skip to content

Commit df147c6

Browse files
committed
WIP: some additions
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 42e8afc commit df147c6

File tree

4 files changed

+84
-34
lines changed

4 files changed

+84
-34
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
@@ -36,6 +37,11 @@
3637
nox.options.default_venv_backend = "uv|virtualenv"
3738

3839

40+
class Docs(enum.Enum):
41+
Sphinx = "sphinx"
42+
MkDocs = "mkdocs"
43+
44+
3945
DIR = Path(__file__).parent.resolve()
4046
with DIR.joinpath("cookiecutter.json").open() as f:
4147
BACKENDS = json.load(f)["backend"]
@@ -45,6 +51,7 @@
4551
project_name: cookie-{backend}
4652
backend: {backend}
4753
vcs: {vcs}
54+
docs: {docs}
4855
"""
4956

5057

@@ -64,7 +71,7 @@ def get_expected_version(backend: str, vcs: bool) -> str:
6471
return "0.2.3" if vcs and backend not in {"maturin", "mesonpy", "uv"} else "0.1.0"
6572

6673

67-
def make_copier(session: nox.Session, backend: str, vcs: bool) -> Path:
74+
def make_copier(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> Path:
6875
package_dir = Path(f"copy-{backend}")
6976
if package_dir.exists():
7077
rmtree_ro(package_dir)
@@ -84,20 +91,21 @@ def make_copier(session: nox.Session, backend: str, vcs: bool) -> Path:
8491
8592
"--data=license=BSD",
8693
f"--data=vcs={vcs}",
94+
f"--data=docs={docs.value}",
8795
)
8896

8997
init_git(session, package_dir)
9098

9199
return package_dir
92100

93101

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

99107
Path("input.yml").write_text(
100-
JOB_FILE.format(backend=backend, vcs=vcs), encoding="utf-8"
108+
JOB_FILE.format(backend=backend, vcs=vcs, docs=docs.value), encoding="utf-8"
101109
)
102110

103111
session.run(
@@ -112,7 +120,7 @@ def make_cookie(session: nox.Session, backend: str, vcs: bool) -> Path:
112120
return package_dir
113121

114122

115-
def make_cruft(session: nox.Session, backend: str, vcs: bool) -> Path:
123+
def make_cruft(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> Path:
116124
package_dir = Path(f"cruft-{backend}")
117125
if package_dir.exists():
118126
rmtree_ro(package_dir)
@@ -122,7 +130,8 @@ def make_cruft(session: nox.Session, backend: str, vcs: bool) -> Path:
122130

123131
session.cd(tmp_dir)
124132
Path("input.yml").write_text(
125-
JOB_FILE.format(backend=backend, pkg=package_dir, vcs=vcs), encoding="utf-8"
133+
JOB_FILE.format(backend=backend, pkg=package_dir, vcs=vcs, docs=docs),
134+
encoding="utf-8",
126135
)
127136
session.run(
128137
"cruft",
@@ -187,14 +196,15 @@ def diff_files(p1: Path, p2: Path) -> bool:
187196

188197

189198
@nox.session(default=False)
199+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
190200
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
191201
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
192-
def lint(session: nox.Session, backend: str, vcs: bool) -> None:
202+
def lint(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
193203
session.install("cookiecutter", "pre-commit")
194204

195205
tmp_dir = session.create_tmp()
196206
session.cd(tmp_dir)
197-
cookie = make_cookie(session, backend, vcs)
207+
cookie = make_cookie(session, backend, vcs, docs)
198208
session.chdir(cookie)
199209

200210
session.run(
@@ -213,22 +223,23 @@ def autoupdate(session: nox.Session, backend: str) -> None:
213223

214224
tmp_dir = session.create_tmp()
215225
session.cd(tmp_dir)
216-
cookie = make_cookie(session, backend, True)
226+
cookie = make_cookie(session, backend, True, Docs.Sphinx)
217227
session.chdir(cookie)
218228

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

222232

223233
@nox.session(default=False)
234+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
224235
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
225236
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
226-
def tests(session: nox.Session, backend: str, vcs: bool) -> None:
237+
def tests(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
227238
session.install("cookiecutter")
228239

229240
tmp_dir = session.create_tmp()
230241
session.cd(tmp_dir)
231-
cookie = make_cookie(session, backend, vcs)
242+
cookie = make_cookie(session, backend, vcs, docs)
232243
session.chdir(cookie)
233244

234245
name = f"cookie-{backend}"
@@ -247,14 +258,15 @@ def tests(session: nox.Session, backend: str, vcs: bool) -> None:
247258

248259

249260
@nox.session(default=False)
261+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
250262
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
251263
@nox.parametrize("backend", ("poetry", "pdm", "hatch"), ids=("poetry", "pdm", "hatch"))
252-
def native(session: nox.Session, backend: str, vcs: bool) -> None:
264+
def native(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
253265
session.install("cookiecutter", backend)
254266

255267
tmp_dir = session.create_tmp()
256268
session.cd(tmp_dir)
257-
cookie = make_cookie(session, backend, vcs)
269+
cookie = make_cookie(session, backend, vcs, docs)
258270
session.chdir(cookie)
259271

260272
if backend == "hatch":
@@ -268,14 +280,15 @@ def native(session: nox.Session, backend: str, vcs: bool) -> None:
268280

269281

270282
@nox.session(default=False)
283+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
271284
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
272285
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
273-
def dist(session: nox.Session, backend: str, vcs: bool) -> None:
286+
def dist(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
274287
session.install("cookiecutter", "build", "twine")
275288

276289
tmp_dir = session.create_tmp()
277290
session.cd(tmp_dir)
278-
cookie = make_cookie(session, backend, vcs)
291+
cookie = make_cookie(session, backend, vcs, docs)
279292
session.chdir(cookie)
280293

281294
session.run("python", "-m", "build", silent=True)
@@ -331,14 +344,15 @@ def dist(session: nox.Session, backend: str, vcs: bool) -> None:
331344

332345

333346
@nox.session(name="nox", default=False)
347+
@nox.parametrize("docs", list(Docs), ids=[d.value for d in Docs])
334348
@nox.parametrize("vcs", [False, True], ids=["novcs", "vcs"])
335349
@nox.parametrize("backend", BACKENDS, ids=BACKENDS)
336-
def nox_session(session: nox.Session, backend: str, vcs: bool) -> None:
350+
def nox_session(session: nox.Session, backend: str, vcs: bool, docs: Docs) -> None:
337351
session.install("cookiecutter", "nox")
338352

339353
tmp_dir = session.create_tmp()
340354
session.cd(tmp_dir)
341-
cookie = make_cookie(session, backend, vcs)
355+
cookie = make_cookie(session, backend, vcs, docs)
342356
session.chdir(cookie)
343357

344358
if session.posargs:
@@ -356,13 +370,14 @@ def compare_copier(session):
356370

357371
for backend in BACKENDS:
358372
for vcs in (False, True):
359-
cookie = make_cookie(session, backend, vcs)
360-
copier = make_copier(session, backend, vcs)
373+
for docs in Docs:
374+
cookie = make_cookie(session, backend, vcs, docs)
375+
copier = make_copier(session, backend, vcs, docs)
361376

362-
if diff_files(cookie, copier):
363-
session.log(f"{backend} {vcs=} passed")
364-
else:
365-
session.error(f"{backend} {vcs=} files are not the same!")
377+
if diff_files(cookie, copier):
378+
session.log(f"{backend} {vcs=} passed")
379+
else:
380+
session.error(f"{backend} {vcs=} files are not the same!")
366381

367382

368383
@nox.session(default=False)
@@ -374,13 +389,14 @@ def compare_cruft(session):
374389

375390
for backend in BACKENDS:
376391
for vcs in (False, True):
377-
cookie = make_cookie(session, backend, vcs)
378-
cruft = make_cruft(session, backend, vcs)
379-
380-
if diff_files(cookie, cruft):
381-
session.log(f"{backend} {vcs=} passed")
382-
else:
383-
session.error(f"{backend} {vcs=} files are not the same!")
392+
for docs in Docs:
393+
cookie = make_cookie(session, backend, vcs, docs)
394+
cruft = make_cruft(session, backend, vcs, docs)
395+
396+
if diff_files(cookie, cruft):
397+
session.log(f"{backend} {vcs=} passed")
398+
else:
399+
session.error(f"{backend} {vcs=} files are not the same!")
384400

385401

386402
PC_VERS = re.compile(

src/sp_repo_review/checks/readthedocs.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from __future__ import annotations
22

3-
from typing import Any
3+
from typing import TYPE_CHECKING, Any
44

55
import yaml
66

7-
from .._compat.importlib.resources.abc import Traversable
87
from . import mk_url
98

9+
if TYPE_CHECKING:
10+
from .._compat.importlib.resources.abc import Traversable
11+
1012

1113
class ReadTheDocs:
1214
family = "docs"
@@ -102,6 +104,34 @@ def check(readthedocs: dict[str, Any]) -> bool:
102104
return False
103105

104106

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+
105135
def readthedocs(root: Traversable) -> dict[str, Any]:
106136
for path in (".readthedocs.yaml", ".readthedocs.yml"):
107137
readthedocs_path = root.joinpath(path)

0 commit comments

Comments
 (0)