Skip to content

GH-136155: Fail the EPUB check on fatal errors #137351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions .github/workflows/reusable-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@ jobs:
--fail-if-regression \
--fail-if-improved \
--fail-if-new-news-nit
- name: 'Build EPUB documentation'
continue-on-error: true
run: |
set -Eeuo pipefail
make -C Doc/ PYTHON=../python SPHINXOPTS="--quiet" epub
pip install epubcheck
epubcheck Doc/build/epub/Python.epub &> Doc/epubcheck.txt
- name: 'Check for fatal errors in EPUB'
if: github.event_name == 'pull_request'
continue-on-error: true # until gh-136155 is fixed
run: |
python Doc/tools/check-epub.py

# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
doctest:
Expand Down Expand Up @@ -114,3 +102,30 @@ jobs:
# Use "xvfb-run" since some doctest tests open GUI windows
- name: 'Run documentation doctest'
run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="--fail-on-warning" doctest

check-epub:
name: 'Check EPUB'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: 'Set up Python'
uses: actions/setup-python@v5
with:
python-version: '3'
cache: 'pip'
cache-dependency-path: 'Doc/requirements.txt'
- name: 'Install build dependencies'
run: |
make -C Doc/ venv
python -m pip install epubcheck
- name: 'Build EPUB documentation'
run: make -C Doc/ PYTHON=../python epub
- name: 'Run epubcheck'
continue-on-error: true
run: epubcheck Doc/build/epub/Python.epub &> Doc/epubcheck.txt
- run: cat Doc/epubcheck.txt
- name: 'Check for fatal errors in EPUB'
run: python Doc/tools/check-epub.py
36 changes: 21 additions & 15 deletions Doc/tools/check-epub.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import sys
from pathlib import Path

CPYTHON_ROOT = Path(
__file__, # cpython/Doc/tools/check-epub.py
'..', # cpython/Doc/tools
'..', # cpython/Doc
'..', # cpython
).resolve()
EPUBCHECK_PATH = CPYTHON_ROOT / 'Doc' / 'epubcheck.txt'
Comment on lines +3 to +8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
CPYTHON_ROOT = Path(
__file__, # cpython/Doc/tools/check-epub.py
'..', # cpython/Doc/tools
'..', # cpython/Doc
'..', # cpython
).resolve()
CPYTHON_ROOT = Path(__file__).parents[2] # cpython/Doc/tools/check-epub.py -> cpython/


def main() -> int:
wrong_directory_msg = "Must run this script from the repo root"
if not Path("Doc").exists() or not Path("Doc").is_dir():
raise RuntimeError(wrong_directory_msg)

with Path("Doc/epubcheck.txt").open(encoding="UTF-8") as f:
messages = [message.split(" - ") for message in f.read().splitlines()]

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

if fatal_errors:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
errors = [line for line in lines if line.startswith('ERROR')]
if errors:
print()
print(f'Warning: epubcheck reported {len(errors)} error(s):')
print()
print('\n'.join(errors))

Could we start to display errors as warnings for informational purposes?

print("\nError: must not contain fatal errors:\n")
for error in fatal_errors:
print(" - ".join(error))
err_count = len(fatal_errors)
s = 's' * (err_count != 1)
print()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
s = 's' * (err_count != 1)
s = 's' if err_count > 1 else ''

nit-picky: for readability/verbosity

print(f'Error: epubcheck reported {err_count} fatal error{s}:')
print()
print('\n'.join(fatal_errors))
return 1

return len(fatal_errors)
print('Success: no fatal errors found.')
return 0


if __name__ == "__main__":
sys.exit(main())
if __name__ == '__main__':
raise SystemExit(main())
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy