mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-31 22:23:12 +08:00
lint: Add test for package readme syntax errors (#492)
Add a test to ensure readmes render properly Also adds README.rst for testutil package to pass new test. Co-authored-by: Christian Neumüller <christian+github@neumueller.me>
This commit is contained in:
51
scripts/check_for_valid_readme.py
Normal file
51
scripts/check_for_valid_readme.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
"""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()
|
@ -482,6 +482,12 @@ def lint_args(args):
|
|||||||
args, ("exec", "pylint {}", "--all", "--mode", "lintroots")
|
args, ("exec", "pylint {}", "--all", "--mode", "lintroots")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
execute_args(
|
||||||
|
parse_subargs(
|
||||||
|
args,
|
||||||
|
("exec", "python scripts/check_for_valid_readme.py {}", "--all",),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_args(args):
|
def test_args(args):
|
||||||
|
Reference in New Issue
Block a user