Skip to content

Commit 1afd55f

Browse files
committed
docs for link checking, only test internal links in CI
1 parent ab7041d commit 1afd55f

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ To watch documentation sources and build continuously:
135135
python scripts/docs.py --watch
136136
```
137137

138+
To check internal links in the docs after building:
139+
140+
```bash
141+
python scripts/docs.py --check --local-only
142+
```
143+
144+
To check internal _and_ external links in the docs after building:
145+
146+
```bash
147+
python scripts/docs.py --check
148+
```
149+
150+
> Note: you may get spurious failures due to rate limiting, especially in CI,
151+
> but it's good to test locally
152+
138153
### Browser-based Acceptance Tests
139154

140155
The browser tests will launch JupyterLab on a random port and exercise the

ci/job.docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ jobs:
4040
targetPath: docs/_build
4141
artifactName: Docs $(Build.BuildId)
4242

43-
- script: ${{ platform.activate }} jupyterlab-lsp && python scripts/docs.py --check
44-
displayName: check URLs in docs
43+
- script: ${{ platform.activate }} jupyterlab-lsp && python scripts/docs.py --check --local-only
44+
displayName: check local URLs in docs

scripts/docs.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,53 @@
33
import shutil
44
import sys
55
from pathlib import Path
6-
from subprocess import check_call
6+
from subprocess import call
77
from tempfile import TemporaryDirectory
88

99
ROOT = Path(__file__).parent.parent
1010
DOCS = ROOT / "docs"
1111

12+
CHECK_INI = """
13+
[pytest]
14+
addopts =
15+
--check-links
16+
-k "not ipynb {extra_k}"
1217
13-
def docs(watch=False, check=False):
18+
junit_family = xunit2
19+
20+
filterwarnings =
21+
ignore::PendingDeprecationWarning
22+
"""
23+
24+
25+
def docs(watch=False, check=False, local_only=False):
1426
""" build (and test) docs.
1527
1628
because readthedocs, this gets called twice from inside sphinx
1729
"""
1830
if watch:
19-
check_call(["sphinx-autobuild", ".", "_build"], cwd=DOCS)
20-
return 0
31+
return call(["sphinx-autobuild", ".", "_build"], cwd=DOCS)
2132

22-
if check:
33+
elif check:
34+
ini = CHECK_INI.format(extra_k="and not http" if local_only else "")
2335
# do this in a temporary directory to avoid surprises
2436
with TemporaryDirectory() as td:
2537
tdp = Path(td)
2638
dest = tdp / "a" / "deep" / "path"
2739
dest.parent.mkdir(parents=True)
28-
shutil.copytree(DOCS / "_build", dest)
29-
check_call(["pytest-check-links", "-vv", "-k", "not ipynb"], cwd=dest)
40+
shutil.copytree(DOCS / "_build" / "html", dest)
41+
(dest / "pytest.ini").write_text(ini)
3042

31-
check_call(["sphinx-build", "-M", "html", ".", "_build"], cwd=DOCS)
32-
return 0
43+
return call(["pytest"], cwd=dest)
44+
else:
45+
return call(["sphinx-build", "-M", "html", ".", "_build"], cwd=DOCS)
3346

3447

3548
if __name__ == "__main__":
36-
sys.exit(docs(watch="--watch" in sys.argv, check="--check" in sys.argv))
49+
sys.exit(
50+
docs(
51+
watch="--watch" in sys.argv,
52+
check="--check" in sys.argv,
53+
local_only="--local-only" in sys.argv,
54+
)
55+
)

0 commit comments

Comments
 (0)