Skip to content

Commit

Permalink
Add test for package readme syntax errors
Browse files Browse the repository at this point in the history
Fixes #445
  • Loading branch information
ffe4 committed Mar 15, 2020
1 parent f52468b commit 26bddb7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ sphinx-rtd-theme~=0.4
sphinx-autodoc-typehints~=1.10.2
pytest!=5.2.3
pytest-cov>=2.8
readme-renderer==24.0
6 changes: 6 additions & 0 deletions scripts/eachdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,12 @@ def lint_args(args):
args, ("exec", "pylint {}", "--all", "--mode", "lintroots")
)
)
execute_args(
parse_subargs(
args,
("exec", "python tests/check_for_valid_readme.py {}", "--all",),
)
)


def test_args(args):
Expand Down
52 changes: 52 additions & 0 deletions tests/check_for_valid_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Test script to check README.rst files for syntax errors."""
import argparse
import sys
from pathlib import Path

import readme_renderer.rst


def is_valid_rst(path):
"""Checks if RST can be rendered on PyPI."""
with open(path) as f:
markup = f.read()
if readme_renderer.rst.render(markup) is None:
return False
return True


def parse_args():
parser = argparse.ArgumentParser(
description="Checks README.rst file in path for syntax errors."
)
parser.add_argument(
"paths", nargs="+", help="paths containing a README.rst to test"
)
parser.add_argument("-v", "--verbose", action="store_true")
return parser.parse_args()


if __name__ == "__main__":
args = parse_args()

error = False
all_readmes_found = True

for path in [Path(path) for path in args.paths]:
readme = path / "README.rst"
if not readme.exists():
all_readmes_found = False
print("✗ No README.rst in", str(path))
continue
if not is_valid_rst(readme):
error = True
print("✗ RST syntax errors in", readme)
continue
if args.verbose:
print("✓", readme)

if error:
sys.exit(1)
if all_readmes_found:
print("All clear.")
print("No errors found but not all packages have a README.rst")

0 comments on commit 26bddb7

Please sign in to comment.