| 1 |
from pathlib import Path |
| 2 |
|
| 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' |
| 10 |
|
| 11 |
|
| 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')] |
| 15 |
|
| 16 |
if fatal_errors: |
| 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 |
| 24 |
|
| 25 |
print('Success: no fatal errors found.') |
| 26 |
return 0 |
| 27 |
|
| 28 |
|
| 29 |
if __name__ == '__main__': |
| 30 |
raise SystemExit(main()) |