Skip to content

Commit c200fa7

Browse files
authored
Merge pull request #1682 from croth1/beautify_linkcheck_output
2 parents 3366232 + 9233252 commit c200fa7

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

.ci_scripts/display_linkcheck.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import argparse
2+
import json
3+
from collections import defaultdict
4+
from termcolor import colored
5+
6+
status_colors = dict(
7+
broken='red',
8+
redirected='yellow',
9+
working='green',
10+
ignored='white',
11+
unchecked='white',
12+
)
13+
14+
def create_parser():
15+
parser = argparse.ArgumentParser('display_linkcheck')
16+
parser.add_argument('linkcheck_json')
17+
return parser
18+
19+
20+
def main():
21+
parser = create_parser()
22+
args = parser.parse_args()
23+
buffer = defaultdict(list)
24+
with open(args.linkcheck_json) as fh:
25+
for line in fh:
26+
data = json.loads(line)
27+
buffer[data['status']].append(data)
28+
29+
for status, color in status_colors.items():
30+
if status not in buffer:
31+
continue
32+
for data in buffer[status]:
33+
34+
print_tokens = [
35+
colored(f'[{data["status"]}]', color),
36+
colored(data['uri'], 'magenta'),
37+
f'{data["filename"]}:{data["lineno"]}',
38+
]
39+
if data['info'] != '':
40+
print_tokens.append(f'({data["info"]})')
41+
42+
print(*print_tokens)
43+
44+
if __name__ == '__main__':
45+
main()

.ci_scripts/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies:
1616
- python-dateutil
1717
- pip
1818
- python-rapidjson
19+
- termcolor
1920
# uncomment to restore search
2021
# - elm
2122
# - nodejs

.ci_scripts/update_docs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ pushd src
3030
# -W --keep-going: list all warnings but fail build in case there are any
3131
# -n: check validity of all links
3232
make html SPHINXOPTS="-W --keep-going -n"
33-
make linkcheck
33+
linkcheck_failed=0
34+
make linkcheck > /dev/null || linkcheck_failed=1
35+
python ../.ci_scripts/display_linkcheck.py _build/linkcheck/output.json
36+
test "$linkcheck_failed" -eq 0
3437
mv _build/html ../docs
3538
rm -rf _build
3639
popd

0 commit comments

Comments
 (0)