Skip to content

Instantly share code, notes, and snippets.

@akaszynski
Created March 23, 2022 15:05
Show Gist options
  • Save akaszynski/e82c1e1c9977b32242e947f3c5bf08c0 to your computer and use it in GitHub Desktop.
Save akaszynski/e82c1e1c9977b32242e947f3c5bf08c0 to your computer and use it in GitHub Desktop.
Print errors redirected from sphinx.
"""Read errors output from a sphinx build and remove duplicate groups"""
import os
import pathlib
import sys
sys.tracebacklimit = 0
my_path = pathlib.Path(__file__).parent.resolve()
errors = set()
error_file = os.path.join(my_path, "build_errors.txt")
if os.path.isfile(error_file):
with open(error_file) as fid:
group = []
for line in fid.readlines():
line = line.strip()
if line:
group.append(line)
else:
errors.add("\n".join(group))
group = []
errors.add("\n".join(group))
for error in list(errors):
print(error)
print()
# There should be no errors here since sphinx will have exited
print()
if errors:
raise Exception(f"Sphinx reported unique {len(errors)} warnings\n\n")
print(f"Sphinx Reported no warnings\n\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment