Skip to content

Commit 1b324a6

Browse files
feat: add readthedocs config check (#545)
* feat: add readthedocs config check Signed-off-by: Henry Schreiner <[email protected]> * style: pre-commit fixes --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 1e0b5d6 commit 1b324a6

File tree

5 files changed

+124
-4
lines changed

5 files changed

+124
-4
lines changed

README.md

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

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

docs/pages/guides/docs.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ modern Ubuntu should be fine) {% rr RTD102 %}, a `tools` table (we'll use Python
319319
{% rr RTD103 %}, several languages are supported here).
320320

321321
Adding a `sphinx` table tells Read the Docs to enable Sphinx integration. MkDocs
322-
is supported too.
322+
is supported too. You must include one of these unless you use build commands
323+
{% rr RTD104 %}.
323324

324325
Finally, we have a `python` table with an `install` key to describe how to
325326
install our project. This will enable our "docs" extra.

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ extend-select = [
164164
]
165165
ignore = [
166166
"PLR", # Design related pylint codes
167-
"PT004", # Incorrect check, usefixtures is the correct way to do this
168167
"RUF012", # Would require a lot of ClassVar's
169168
]
170169

@@ -180,5 +179,5 @@ ignore = [
180179
[tool.ruff.lint.per-file-ignores]
181180
"src/sp_repo_review/_compat/**.py" = ["TID251"]
182181

183-
[tool.repo-review]
184-
ignore = ["RTD103"]
182+
[tool.repo-review.ignore]
183+
RTD103 = "Using Ruby instead of Python for docs"

src/sp_repo_review/checks/readthedocs.py

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

102102

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

tests/test_readthedocs.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
import yaml
5+
from repo_review.testing import compute_check
6+
7+
8+
@pytest.mark.parametrize("readthedocs", [".readthedocs.yml", ".readthedocs.yaml"])
9+
def test_rtd100(tmp_path: Path, readthedocs: str) -> None:
10+
simple = tmp_path / "simple"
11+
simple.mkdir()
12+
simple.joinpath(readthedocs).touch()
13+
assert compute_check("RTD100", root=simple).result
14+
15+
16+
def test_rtd101_true() -> None:
17+
readthedocs = yaml.safe_load("""
18+
version: 2
19+
""")
20+
assert compute_check("RTD101", readthedocs=readthedocs).result
21+
22+
23+
def test_rtd101_false() -> None:
24+
readthedocs = yaml.safe_load("""
25+
other: 2
26+
""")
27+
assert not compute_check("RTD101", readthedocs=readthedocs).result
28+
29+
30+
def test_rtd102_true() -> None:
31+
readthedocs = yaml.safe_load("""
32+
build:
33+
os: ubuntu-22.04
34+
""")
35+
assert compute_check("RTD102", readthedocs=readthedocs).result
36+
37+
38+
def test_rtd102_false() -> None:
39+
readthedocs = yaml.safe_load("""
40+
build:
41+
python: "3.12"
42+
""")
43+
assert not compute_check("RTD102", readthedocs=readthedocs).result
44+
45+
46+
def test_rtd103_true() -> None:
47+
readthedocs = yaml.safe_load("""
48+
build:
49+
tools:
50+
python: "3.12"
51+
""")
52+
assert compute_check("RTD103", readthedocs=readthedocs).result
53+
54+
55+
def test_rtd103_false() -> None:
56+
readthedocs = yaml.safe_load("""
57+
build:
58+
os: ubuntu-22.04
59+
""")
60+
assert not compute_check("RTD103", readthedocs=readthedocs).result
61+
62+
63+
def test_rtd104_commands() -> None:
64+
readthedocs = yaml.safe_load("""
65+
build:
66+
commands: []
67+
""")
68+
assert compute_check("RTD104", readthedocs=readthedocs).result
69+
70+
71+
def test_rtd104_sphinx() -> None:
72+
readthedocs = yaml.safe_load("""
73+
sphinx:
74+
configuration: docs/conf.py
75+
""")
76+
assert compute_check("RTD104", readthedocs=readthedocs).result
77+
78+
79+
def test_rtd104_mkdocs() -> None:
80+
readthedocs = yaml.safe_load("""
81+
mkdocs:
82+
configuration: docs/mkdocs.yml
83+
""")
84+
assert compute_check("RTD104", readthedocs=readthedocs).result
85+
86+
87+
def test_rtd104_false() -> None:
88+
readthedocs = yaml.safe_load("""
89+
build:
90+
""")
91+
assert not compute_check("RTD104", readthedocs=readthedocs).result

0 commit comments

Comments
 (0)