Skip to content

Commit c64d08f

Browse files
Copilothenryiii
andauthored
fix: accept build.jobs as valid ReadTheDocs configuration in RTD104 (#691)
* Initial plan * Add support for build.jobs in RTD103 and RTD104 checks Co-authored-by: henryiii <[email protected]> * Reorder pattern matching to prioritize build.jobs over build.commands Co-authored-by: henryiii <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: henryiii <[email protected]>
1 parent 52b3bca commit c64d08f

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/sp_repo_review/checks/readthedocs.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ def check(readthedocs: dict[str, Any]) -> bool:
9898
match readthedocs:
9999
case {"build": {"tools": {"python": object()}}}:
100100
return True
101+
case {"build": {"jobs": object()}}:
102+
return True
101103
case {"build": {"commands": object()}}:
102104
return True
103105
case _:
@@ -112,8 +114,10 @@ class RTD104(ReadTheDocs):
112114
@staticmethod
113115
def check(readthedocs: dict[str, Any]) -> bool:
114116
"""
115-
You must set `sphinx: configuration:`, `mkdocs: configuration:` or
116-
`build: commands:`. Skipping it is no longer allowed. Example:
117+
You must set `sphinx: configuration:`, `mkdocs: configuration:`,
118+
`build: commands:`, or `build: jobs:`. Skipping it is no longer allowed.
119+
Note: `build: jobs:` is preferred over `build: commands:`.
120+
Example:
117121
118122
```yaml
119123
sphinx:
@@ -122,6 +126,8 @@ def check(readthedocs: dict[str, Any]) -> bool:
122126
"""
123127

124128
match readthedocs:
129+
case {"build": {"jobs": dict()}}:
130+
return True
125131
case {"build": {"commands": list()}}:
126132
return True
127133
case {"sphinx": {"configuration": str()}}:

tests/test_readthedocs.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,62 @@ def test_rtd103_commands() -> None:
6161
assert compute_check("RTD103", readthedocs=readthedocs).result
6262

6363

64+
def test_rtd103_jobs() -> None:
65+
readthedocs = yaml.safe_load("""
66+
build:
67+
jobs:
68+
pre_build:
69+
- echo "pre build"
70+
""")
71+
assert compute_check("RTD103", readthedocs=readthedocs).result
72+
73+
6474
def test_rtd103_false() -> None:
6575
readthedocs = yaml.safe_load("""
6676
build:
6777
os: ubuntu-22.04
6878
""")
6979
assert not compute_check("RTD103", readthedocs=readthedocs).result
80+
81+
82+
def test_rtd104_sphinx() -> None:
83+
readthedocs = yaml.safe_load("""
84+
sphinx:
85+
configuration: docs/conf.py
86+
""")
87+
assert compute_check("RTD104", readthedocs=readthedocs).result
88+
89+
90+
def test_rtd104_mkdocs() -> None:
91+
readthedocs = yaml.safe_load("""
92+
mkdocs:
93+
configuration: mkdocs.yml
94+
""")
95+
assert compute_check("RTD104", readthedocs=readthedocs).result
96+
97+
98+
def test_rtd104_commands() -> None:
99+
readthedocs = yaml.safe_load("""
100+
build:
101+
commands:
102+
- echo "build"
103+
""")
104+
assert compute_check("RTD104", readthedocs=readthedocs).result
105+
106+
107+
def test_rtd104_jobs() -> None:
108+
readthedocs = yaml.safe_load("""
109+
build:
110+
jobs:
111+
pre_build:
112+
- echo "pre build"
113+
""")
114+
assert compute_check("RTD104", readthedocs=readthedocs).result
115+
116+
117+
def test_rtd104_false() -> None:
118+
readthedocs = yaml.safe_load("""
119+
build:
120+
os: ubuntu-22.04
121+
""")
122+
assert not compute_check("RTD104", readthedocs=readthedocs).result

0 commit comments

Comments
 (0)