From 5fbf9996149208aee9ca8a1e1a585d2cf12edf11 Mon Sep 17 00:00:00 2001 From: Daniel <61800298+ffe4@users.noreply.github.com> Date: Sat, 28 Mar 2020 05:45:15 +0100 Subject: [PATCH] lint: Add test for package readme syntax errors (#492) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- dev-requirements.txt | 1 + ext/opentelemetry-ext-otcollector/README.rst | 2 +- ext/opentelemetry-ext-testutil/README.rst | 9 ++++ scripts/check_for_valid_readme.py | 51 ++++++++++++++++++++ scripts/eachdist.py | 6 +++ tox.ini | 1 + 6 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 ext/opentelemetry-ext-testutil/README.rst create mode 100644 scripts/check_for_valid_readme.py diff --git a/dev-requirements.txt b/dev-requirements.txt index 6ce5479306..3d7a4e2656 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -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 diff --git a/ext/opentelemetry-ext-otcollector/README.rst b/ext/opentelemetry-ext-otcollector/README.rst index 1a0e3c330e..916c64ffe6 100644 --- a/ext/opentelemetry-ext-otcollector/README.rst +++ b/ext/opentelemetry-ext-otcollector/README.rst @@ -6,7 +6,7 @@ OpenTelemetry Collector Exporter .. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-otcollector.svg :target: https://pypi.org/project/opentelemetry-ext-otcollector/ -This library allows to export data to `OpenTelemetry Collector `_ , currently using OpenCensus receiver in Collector side. +This library allows to export data to `OpenTelemetry Collector`_ , currently using OpenCensus receiver in Collector side. Installation ------------ diff --git a/ext/opentelemetry-ext-testutil/README.rst b/ext/opentelemetry-ext-testutil/README.rst new file mode 100644 index 0000000000..58a75149bd --- /dev/null +++ b/ext/opentelemetry-ext-testutil/README.rst @@ -0,0 +1,9 @@ +OpenTelemetry Test Utilities +============================ + +Test utilities for OpenTelemetry unit tests + + +References +---------- +* `OpenTelemetry Project `_ diff --git a/scripts/check_for_valid_readme.py b/scripts/check_for_valid_readme.py new file mode 100644 index 0000000000..edf94d9c3e --- /dev/null +++ b/scripts/check_for_valid_readme.py @@ -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() diff --git a/scripts/eachdist.py b/scripts/eachdist.py index 406afb6ebf..f1c5e18b60 100755 --- a/scripts/eachdist.py +++ b/scripts/eachdist.py @@ -482,6 +482,12 @@ def lint_args(args): args, ("exec", "pylint {}", "--all", "--mode", "lintroots") ) ) + execute_args( + parse_subargs( + args, + ("exec", "python scripts/check_for_valid_readme.py {}", "--all",), + ) + ) def test_args(args): diff --git a/tox.ini b/tox.ini index 2eb35491da..3c0023bd47 100644 --- a/tox.ini +++ b/tox.ini @@ -188,6 +188,7 @@ deps = isort black psutil + readme_renderer commands_pre = python scripts/eachdist.py install --editable