Files
opentelemetry-python-contrib/scripts/check_for_valid_readme.py
Mauricio Vásquez fc4620c5b8 Add eachdist and move tox to root folder (#29)
Move tox and other configuration files to root folder. Add eachdist to make it
easier to handle operations with different packages.

The eachdist is taken from opentelemetry but slighty modified to avoid ignoring
a given path.
2020-04-09 10:06:59 -07:00

52 lines
1.3 KiB
Python

"""Test script to check given paths for valid README.rst files."""
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 readme_file:
markup = readme_file.read()
return readme_renderer.rst.render(markup) is not None
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()
def main():
args = parse_args()
error = False
for path in map(Path, args.paths):
readme = path / "README.rst"
try:
if not is_valid_rst(readme):
error = True
print("FAILED: RST syntax errors in", readme)
continue
except FileNotFoundError:
error = True
print("FAILED: README.rst not found in", path)
continue
if args.verbose:
print("PASSED:", readme)
if error:
sys.exit(1)
print("All clear.")
if __name__ == "__main__":
main()