Skip to content

Commit

Permalink
Add more robust document checking
Browse files Browse the repository at this point in the history
  • Loading branch information
avylove committed Aug 26, 2020
1 parent 2e0997e commit 22f9e88
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Fedora and EL8 (RHEL/CentOS/Scientific)
$ dnf install python3-enlighten
EL7 (RHEL/CentOS/Scientific)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

(EPEL_ repositories must be configured_)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ source-dir = doc
build-dir = build/doc
all_files = True
fresh-env = True
warning-is-error = True

[aliases]
spelling=build_sphinx --builder spelling
Expand Down
31 changes: 31 additions & 0 deletions setup_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@ def spelling_clean_dir(path):
os.unlink(os.path.join(path, filename))


def check_rst2html(path):
"""
Checks for warnings when doing ReST to HTML conversion
"""

# pylint: disable=import-error,import-outside-toplevel
from contextlib import redirect_stderr # Import here because it breaks <= Python 3.4
from docutils.core import publish_file # Import here because only available in doc tests

stderr = io.StringIO()

# This will exit with status if there is a bad enough error
with redirect_stderr(stderr):
output = publish_file(source_path=path, writer_name='html',
enable_exit_status=True, destination_path='/dev/null')

warning_text = stderr.getvalue()

if warning_text or not output:
print(warning_text)
return 1

return 0


if __name__ == '__main__':

# Do nothing if no arguments were given
Expand All @@ -100,6 +125,12 @@ def spelling_clean_dir(path):
else:
sys.exit(print_all_spelling_errors(DIR_SPELLING))

# Check file for Rest to HTML conversion
if sys.argv[1] == 'rst2html':
if len(sys.argv) < 3:
sys.exit('Missing filename for ReST to HTML check')
sys.exit(check_rst2html(sys.argv[2]))

# Unknown option
else:
sys.stderr.write('Unknown option: %s' % sys.argv[1])
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,4 @@ commands=
{envpython} setup.py spelling
{envpython} setup_helpers.py spelling
{envpython} setup.py html
{envpython} setup_helpers.py rst2html README.rst

0 comments on commit 22f9e88

Please sign in to comment.