Skip to content

Commit 09128c2

Browse files
doc
1 parent 15131a4 commit 09128c2

File tree

6 files changed

+91
-44
lines changed

6 files changed

+91
-44
lines changed

.github/workflows/checks.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,11 @@ jobs:
3939
run: |
4040
poetry run -- nox -s docs:build
4141
42-
Documentation-Links:
43-
name: Doc Links Check
44-
runs-on: ubuntu-24.04
45-
permissions:
46-
contents: read
47-
steps:
48-
- name: SCM Checkout
49-
uses: actions/checkout@v4
50-
51-
- name: Setup Python & Poetry Environment
52-
uses: ./.github/actions/python-environment
53-
5442
- name: Link Check
5543
run: |
5644
poetry run -- nox -s docs:links:check
5745
46+
5847
Changelog:
5948
name: Changelog Update Check
6049
runs-on: ubuntu-24.04

doc/changes/unreleased.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,30 @@
22

33
## Summary
44

5+
### Links in the Documentation
6+
This version of the PTB adds nox tasks to check links present in our documentation:
7+
8+
docs:link - List all the links within the documentation
9+
docs:links:check - Checks whether all links in the documentation are accessible
10+
11+
`docs:links:check` is run in the CI `checks.yml`. If this step fails in the CI,
12+
please check the output & manually resolve the issues. There might be some cases
13+
where you need to update your doc/conf.py with specific values for the allowed
14+
options for the Linkcheck Builder.
15+
16+
We recommend the following values be added:
17+
18+
linkcheck_rate_limit_timeout = 40
19+
linkcheck_timeout = 10
20+
linkcheck_delay = 20
21+
linkcheck_retries = 2
22+
linkcheck_anchors = False
23+
linkcheck_ignore: list[str] = []
24+
linkcheck_allowed_redirects = {
25+
# All HTTP redirections from the source URI to
26+
# the canonical URI will be treated as "working".
27+
r"https://github\.com/.*": r"https://github\.com/login*"
28+
}
29+
530
## ✨ Features
631
* #409: Doc link & checks

exasol/toolbox/nox/_documentation.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def _docs_list_links(doc_config: Path):
101101
doc_config,
102102
tmpdir,
103103
],
104-
capture_output= True,
105-
text= True
104+
capture_output=True,
105+
text=True,
106106
)
107107
if sp.returncode >= 2:
108108
return sp.returncode, sp.stderr
@@ -116,17 +116,9 @@ def _docs_list_links(doc_config: Path):
116116
file_links.append(line)
117117
file_links.sort(key=lambda file: file["filename"])
118118
return 0, "\n".join(
119-
f"filename: {fl['filename']}:{fl['lineno']} -> uri: {fl['uri']}" for fl in file_links
120-
)
121-
122-
123-
@nox.session(name="docs:links", python=False)
124-
def docs_list_links(session: Session) -> None:
125-
"""List all the links within the documentation."""
126-
r_code, text = _docs_list_links(PROJECT_CONFIG.doc)
127-
print(text)
128-
if r_code != 0:
129-
session.error()
119+
f"filename: {fl['filename']}:{fl['lineno']} -> uri: {fl['uri']}"
120+
for fl in file_links
121+
)
130122

131123

132124
def _docs_links_check(doc_config: Path, args):
@@ -146,7 +138,18 @@ def _docs_links_check(doc_config: Path, args):
146138
dst = Path(args.output) / "link-check-output.json"
147139
shutil.copyfile(result_json, dst)
148140
print(f"file generated at path: {result_json.resolve()}")
149-
return sp.returncode, None if sp.returncode >= 2 else (tmpdir / "output.txt").read_text()
141+
return sp.returncode, (
142+
None if sp.returncode >= 2 else (tmpdir / "output.txt").read_text()
143+
)
144+
145+
146+
@nox.session(name="docs:links", python=False)
147+
def docs_list_links(session: Session) -> None:
148+
"""List all the links within the documentation."""
149+
r_code, text = _docs_list_links(PROJECT_CONFIG.doc)
150+
print(text)
151+
if r_code != 0:
152+
session.error()
150153

151154

152155
@nox.session(name="docs:links:check", python=False)
@@ -158,15 +161,15 @@ def docs_links_check(session: Session) -> None:
158161
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
159162
)
160163
parser.add_argument(
161-
"-o", "--output", type=Path, help="path to output file", default=None
164+
"-o", "--output", type=Path, help="path to copy the output json", default=None
162165
)
163166
args = parser.parse_args(session.posargs)
164167
r_code, problems = _docs_links_check(PROJECT_CONFIG.doc, args)
165168
if r_code >= 2:
166169
session.error(2)
167170
if r_code == 1 or problems != "":
168-
escape_rot = "\033[31m"
169-
print(escape_rot + "errors:")
171+
escape_red = "\033[31m"
172+
print(escape_red + "errors:")
170173
print(problems)
171174
session.error(1)
172175

exasol/toolbox/templates/github/workflows/checks.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ jobs:
3838
run: |
3939
poetry run -- nox -s docs:build
4040
41+
- name: Link Check
42+
run: |
43+
poetry run -- nox -s docs:links:check
44+
4145
build-matrix:
4246
name: Generate Build Matrix
4347
uses: ./.github/workflows/matrix-python.yml

project-template/{{cookiecutter.repo_name}}/doc/conf.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,16 @@
7676
"github_url": "https://github.com/exasol/{{cookiecutter.repo_name}}",
7777
"accent_color": "grass",
7878
}
79+
7980
# -- Configure link checking behavior ----------------------------------------
80-
linkcheck_rate_limit_timeout = 15
81+
linkcheck_rate_limit_timeout = 40
82+
linkcheck_timeout = 10
83+
linkcheck_delay = 20
84+
linkcheck_retries = 2
85+
linkcheck_anchors = False
86+
linkcheck_ignore: list[str] = []
87+
linkcheck_allowed_redirects = {
88+
# All HTTP redirections from the source URI to
89+
# the canonical URI will be treated as "working".
90+
r"https://github\.com/.*": r"https://github\.com/login*"
91+
}

test/unit/documentation_test.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
import shutil
2+
from unittest.mock import (
3+
MagicMock,
4+
patch,
5+
)
6+
17
import pytest
2-
from unittest.mock import patch, MagicMock
8+
39
import exasol.toolbox.nox._documentation
410
from exasol.toolbox.nox._documentation import (
11+
_docs_links_check,
512
_docs_list_links,
6-
_docs_links_check
713
)
8-
import shutil
914
from noxconfig import Config
1015

1116

@@ -28,9 +33,10 @@ def index():
2833
2934
file"""
3035

36+
3137
@pytest.fixture()
3238
def expected1():
33-
return """filename: file.rst:2 -> uri: https://examle.invalid"""
39+
return """filename: file.rst:2 -> uri: https://examle.invalid"""
3440

3541

3642
def config(index, file, tmp_path):
@@ -55,27 +61,36 @@ def test_docs_links(index, file1, expected1, tmp_path):
5561
@pytest.mark.parametrize(
5662
"file2, expected2",
5763
[
58-
(
59-
"https://httpbin.org/status/200",
60-
(0, "")
61-
),
64+
("https://httpbin.org/status/200", (0, "")),
6265
(
6366
"https://httpbin.org/status/301",
64-
(0, "file.rst:1: [redirected with Found] https://httpbin.org/status/301 to https://httpbin.org/get\n")
67+
(
68+
0,
69+
"file.rst:1: [redirected with Found] https://httpbin.org/status/301 to https://httpbin.org/get\n",
70+
),
6571
),
6672
(
6773
"https://httpbin.org/status/302",
68-
(0, "file.rst:1: [redirected with Found] https://httpbin.org/status/302 to https://httpbin.org/get\n")
74+
(
75+
0,
76+
"file.rst:1: [redirected with Found] https://httpbin.org/status/302 to https://httpbin.org/get\n",
77+
),
6978
),
7079
(
7180
"https://httpbin.org/status/303",
72-
(0, "file.rst:1: [redirected with Found] https://httpbin.org/status/303 to https://httpbin.org/get\n")
81+
(
82+
0,
83+
"file.rst:1: [redirected with Found] https://httpbin.org/status/303 to https://httpbin.org/get\n",
84+
),
7385
),
7486
(
7587
"https://httpbin.org/status/404",
76-
(1, "file.rst:1: [broken] https://httpbin.org/status/404: 404 Client Error: NOT FOUND for url: https://httpbin.org/status/404\n")
77-
)
78-
]
88+
(
89+
1,
90+
"file.rst:1: [broken] https://httpbin.org/status/404: 404 Client Error: NOT FOUND for url: https://httpbin.org/status/404\n",
91+
),
92+
),
93+
],
7994
)
8095
def test_docs_links_check(index, file2, expected2, tmp_path):
8196
config(index, file2, tmp_path)

0 commit comments

Comments
 (0)