Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fbf999

Browse files
ffe4Oberon00
andauthored
lint: Add test for package readme syntax errors (open-telemetry#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 <[email protected]>
1 parent 046057d commit 5fbf999

File tree

6 files changed

+69
-1
lines changed

6 files changed

+69
-1
lines changed

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ sphinx-rtd-theme~=0.4
88
sphinx-autodoc-typehints~=1.10.2
99
pytest!=5.2.3
1010
pytest-cov>=2.8
11+
readme-renderer~=24.0

ext/opentelemetry-ext-otcollector/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ OpenTelemetry Collector Exporter
66
.. |pypi| image:: https://badge.fury.io/py/opentelemetry-ext-otcollector.svg
77
:target: https://pypi.org/project/opentelemetry-ext-otcollector/
88

9-
This library allows to export data to `OpenTelemetry Collector <https://github.com/open-telemetry/opentelemetry-collector/>`_ , currently using OpenCensus receiver in Collector side.
9+
This library allows to export data to `OpenTelemetry Collector`_ , currently using OpenCensus receiver in Collector side.
1010

1111
Installation
1212
------------
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
OpenTelemetry Test Utilities
2+
============================
3+
4+
Test utilities for OpenTelemetry unit tests
5+
6+
7+
References
8+
----------
9+
* `OpenTelemetry Project <https://opentelemetry.io/>`_

scripts/check_for_valid_readme.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""Test script to check given paths for valid README.rst files."""
2+
import argparse
3+
import sys
4+
from pathlib import Path
5+
6+
import readme_renderer.rst
7+
8+
9+
def is_valid_rst(path):
10+
"""Checks if RST can be rendered on PyPI."""
11+
with open(path) as readme_file:
12+
markup = readme_file.read()
13+
return readme_renderer.rst.render(markup) is not None
14+
15+
16+
def parse_args():
17+
parser = argparse.ArgumentParser(
18+
description="Checks README.rst file in path for syntax errors."
19+
)
20+
parser.add_argument(
21+
"paths", nargs="+", help="paths containing a README.rst to test"
22+
)
23+
parser.add_argument("-v", "--verbose", action="store_true")
24+
return parser.parse_args()
25+
26+
27+
def main():
28+
args = parse_args()
29+
error = False
30+
31+
for path in map(Path, args.paths):
32+
readme = path / "README.rst"
33+
try:
34+
if not is_valid_rst(readme):
35+
error = True
36+
print("FAILED: RST syntax errors in", readme)
37+
continue
38+
except FileNotFoundError:
39+
error = True
40+
print("FAILED: README.rst not found in", path)
41+
continue
42+
if args.verbose:
43+
print("PASSED:", readme)
44+
45+
if error:
46+
sys.exit(1)
47+
print("All clear.")
48+
49+
50+
if __name__ == "__main__":
51+
main()

scripts/eachdist.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@ def lint_args(args):
482482
args, ("exec", "pylint {}", "--all", "--mode", "lintroots")
483483
)
484484
)
485+
execute_args(
486+
parse_subargs(
487+
args,
488+
("exec", "python scripts/check_for_valid_readme.py {}", "--all",),
489+
)
490+
)
485491

486492

487493
def test_args(args):

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ deps =
188188
isort
189189
black
190190
psutil
191+
readme_renderer
191192

192193
commands_pre =
193194
python scripts/eachdist.py install --editable

0 commit comments

Comments
 (0)