Skip to content

Commit b4a1974

Browse files
authored
GH-136155: Fail the EPUB check on fatal errors (#137351)
1 parent 25518f5 commit b4a1974

File tree

2 files changed

+48
-27
lines changed

2 files changed

+48
-27
lines changed

.github/workflows/reusable-docs.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,6 @@ jobs:
7575
--fail-if-regression \
7676
--fail-if-improved \
7777
--fail-if-new-news-nit
78-
- name: 'Build EPUB documentation'
79-
continue-on-error: true
80-
run: |
81-
set -Eeuo pipefail
82-
make -C Doc/ PYTHON=../python SPHINXOPTS="--quiet" epub
83-
pip install epubcheck
84-
epubcheck Doc/build/epub/Python.epub &> Doc/epubcheck.txt
85-
- name: 'Check for fatal errors in EPUB'
86-
if: github.event_name == 'pull_request'
87-
continue-on-error: true # until gh-136155 is fixed
88-
run: |
89-
python Doc/tools/check-epub.py
9078
9179
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
9280
doctest:
@@ -114,3 +102,30 @@ jobs:
114102
# Use "xvfb-run" since some doctest tests open GUI windows
115103
- name: 'Run documentation doctest'
116104
run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="--fail-on-warning" doctest
105+
106+
check-epub:
107+
name: 'Check EPUB'
108+
runs-on: ubuntu-latest
109+
timeout-minutes: 30
110+
steps:
111+
- uses: actions/checkout@v4
112+
with:
113+
persist-credentials: false
114+
- name: 'Set up Python'
115+
uses: actions/setup-python@v5
116+
with:
117+
python-version: '3'
118+
cache: 'pip'
119+
cache-dependency-path: 'Doc/requirements.txt'
120+
- name: 'Install build dependencies'
121+
run: |
122+
make -C Doc/ venv
123+
python -m pip install epubcheck
124+
- name: 'Build EPUB documentation'
125+
run: make -C Doc/ PYTHON=../python epub
126+
- name: 'Run epubcheck'
127+
continue-on-error: true
128+
run: epubcheck Doc/build/epub/Python.epub &> Doc/epubcheck.txt
129+
- run: cat Doc/epubcheck.txt
130+
- name: 'Check for fatal errors in EPUB'
131+
run: python Doc/tools/check-epub.py

Doc/tools/check-epub.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
1-
import sys
21
from pathlib import Path
32

3+
CPYTHON_ROOT = Path(
4+
__file__, # cpython/Doc/tools/check-epub.py
5+
'..', # cpython/Doc/tools
6+
'..', # cpython/Doc
7+
'..', # cpython
8+
).resolve()
9+
EPUBCHECK_PATH = CPYTHON_ROOT / 'Doc' / 'epubcheck.txt'
410

5-
def main() -> int:
6-
wrong_directory_msg = "Must run this script from the repo root"
7-
if not Path("Doc").exists() or not Path("Doc").is_dir():
8-
raise RuntimeError(wrong_directory_msg)
9-
10-
with Path("Doc/epubcheck.txt").open(encoding="UTF-8") as f:
11-
messages = [message.split(" - ") for message in f.read().splitlines()]
1211

13-
fatal_errors = [message for message in messages if message[0] == "FATAL"]
12+
def main() -> int:
13+
lines = EPUBCHECK_PATH.read_text(encoding='utf-8').splitlines()
14+
fatal_errors = [line for line in lines if line.startswith('FATAL')]
1415

1516
if fatal_errors:
16-
print("\nError: must not contain fatal errors:\n")
17-
for error in fatal_errors:
18-
print(" - ".join(error))
17+
err_count = len(fatal_errors)
18+
s = 's' * (err_count != 1)
19+
print()
20+
print(f'Error: epubcheck reported {err_count} fatal error{s}:')
21+
print()
22+
print('\n'.join(fatal_errors))
23+
return 1
1924

20-
return len(fatal_errors)
25+
print('Success: no fatal errors found.')
26+
return 0
2127

2228

23-
if __name__ == "__main__":
24-
sys.exit(main())
29+
if __name__ == '__main__':
30+
raise SystemExit(main())

0 commit comments

Comments
 (0)