Files
opentelemetry-python-contrib/scripts/check_for_valid_readme.py
Yusuke Tsutsumi b2aa82cd95 starlette instrumentation (#777)
adding an initial starlette instrumentation.

tox does exact match on fields delimited by a dash. Thus,
any instrumentation that includes "instrumentation" in the name
would collide with testing of the "opentelemetry-instrumentation"
package.

Renaming opentelemetry-instrumentation to opentelemetry-instrumentation-base to fix that.

Co-authored-by: Leighton Chen <lechen@microsoft.com>
Co-authored-by: alrex <aboten@lightstep.com>
2020-06-15 13:59:57 -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, stream=sys.stderr) 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()