From 26bddb7d5fa8cce2be252b4eec1b118640325aff Mon Sep 17 00:00:00 2001
From: Daniel Lemm <61800298+ffe4@users.noreply.github.com>
Date: Mon, 16 Mar 2020 00:24:10 +0100
Subject: [PATCH 1/7] Add test for package readme syntax errors
Fixes #445
---
dev-requirements.txt | 1 +
scripts/eachdist.py | 6 ++++
tests/check_for_valid_readme.py | 52 +++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+)
create mode 100644 tests/check_for_valid_readme.py
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 6ce54793067..7cd934ddfb3 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/scripts/eachdist.py b/scripts/eachdist.py
index 406afb6ebfd..a0feb9a68f8 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 tests/check_for_valid_readme.py {}", "--all",),
+ )
+ )
def test_args(args):
diff --git a/tests/check_for_valid_readme.py b/tests/check_for_valid_readme.py
new file mode 100644
index 00000000000..00228e5fd74
--- /dev/null
+++ b/tests/check_for_valid_readme.py
@@ -0,0 +1,52 @@
+"""Test script to check README.rst files for syntax errors."""
+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 f:
+ markup = f.read()
+ if readme_renderer.rst.render(markup) is None:
+ return False
+ return True
+
+
+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()
+
+
+if __name__ == "__main__":
+ args = parse_args()
+
+ error = False
+ all_readmes_found = True
+
+ for path in [Path(path) for path in args.paths]:
+ readme = path / "README.rst"
+ if not readme.exists():
+ all_readmes_found = False
+ print("✗ No README.rst in", str(path))
+ continue
+ if not is_valid_rst(readme):
+ error = True
+ print("✗ RST syntax errors in", readme)
+ continue
+ if args.verbose:
+ print("✓", readme)
+
+ if error:
+ sys.exit(1)
+ if all_readmes_found:
+ print("All clear.")
+ print("No errors found but not all packages have a README.rst")
From 9ddbfd8abc776de63eeb0d5e85e434586bb67c8b Mon Sep 17 00:00:00 2001
From: Daniel Lemm <61800298+ffe4@users.noreply.github.com>
Date: Mon, 16 Mar 2020 10:34:44 +0100
Subject: [PATCH 2/7] Fix README and make tests pass
Fixes invalid references in README and fixes errors in 26bddb7
---
ext/opentelemetry-ext-otcollector/README.rst | 4 ++--
tests/check_for_valid_readme.py | 3 ++-
tox.ini | 1 +
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/ext/opentelemetry-ext-otcollector/README.rst b/ext/opentelemetry-ext-otcollector/README.rst
index 200ec9a91d0..bf7c9b70e07 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
------------
@@ -95,4 +95,4 @@ References
----------
* `OpenTelemetry Collector `_
-* `OpenTelemetry Project `_
+* `OpenTelemetry `_
diff --git a/tests/check_for_valid_readme.py b/tests/check_for_valid_readme.py
index 00228e5fd74..661148eb780 100644
--- a/tests/check_for_valid_readme.py
+++ b/tests/check_for_valid_readme.py
@@ -49,4 +49,5 @@ def parse_args():
sys.exit(1)
if all_readmes_found:
print("All clear.")
- print("No errors found but not all packages have a README.rst")
+ else:
+ print("No errors found but not all packages have a README.rst")
diff --git a/tox.ini b/tox.ini
index 52c82eba075..5495c582c3a 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
From 3106f85d4ed7027102574f0ffda2553a1cf1dcbd Mon Sep 17 00:00:00 2001
From: Daniel Lemm <61800298+ffe4@users.noreply.github.com>
Date: Wed, 25 Mar 2020 10:14:40 +0100
Subject: [PATCH 3/7] Update dev-requirements.txt
---
dev-requirements.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 7cd934ddfb3..3d7a4e2656f 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -8,4 +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
+readme-renderer~=24.0
From c85cea40436c6aecfca9b77a0b038d6ce75e254e Mon Sep 17 00:00:00 2001
From: Daniel <61800298+ffe4@users.noreply.github.com>
Date: Thu, 26 Mar 2020 14:53:51 +0100
Subject: [PATCH 4/7] Apply suggestions from code review
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Commit via GitHub web interface.
Co-Authored-By: Christian Neumüller
---
tests/check_for_valid_readme.py | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/tests/check_for_valid_readme.py b/tests/check_for_valid_readme.py
index 661148eb780..0b52b9146b4 100644
--- a/tests/check_for_valid_readme.py
+++ b/tests/check_for_valid_readme.py
@@ -10,9 +10,7 @@ def is_valid_rst(path):
"""Checks if RST can be rendered on PyPI."""
with open(path) as f:
markup = f.read()
- if readme_renderer.rst.render(markup) is None:
- return False
- return True
+ return readme_renderer.rst.render(markup) is not None
def parse_args():
@@ -32,7 +30,7 @@ def parse_args():
error = False
all_readmes_found = True
- for path in [Path(path) for path in args.paths]:
+ for path in map(Path, args.path):
readme = path / "README.rst"
if not readme.exists():
all_readmes_found = False
From d549f38f0de6791b52be092263a431a56f2be678 Mon Sep 17 00:00:00 2001
From: Daniel Lemm <61800298+ffe4@users.noreply.github.com>
Date: Thu, 26 Mar 2020 16:00:24 +0100
Subject: [PATCH 5/7] Apply changes suggestions from code review
Also adds README.rst for testutil package to pass new test.
---
ext/opentelemetry-ext-testutil/README.rst | 9 +++++++
tests/check_for_valid_readme.py | 32 +++++++++++------------
2 files changed, 25 insertions(+), 16 deletions(-)
create mode 100644 ext/opentelemetry-ext-testutil/README.rst
diff --git a/ext/opentelemetry-ext-testutil/README.rst b/ext/opentelemetry-ext-testutil/README.rst
new file mode 100644
index 00000000000..58a75149bd7
--- /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/tests/check_for_valid_readme.py b/tests/check_for_valid_readme.py
index 0b52b9146b4..3ae65dd8fda 100644
--- a/tests/check_for_valid_readme.py
+++ b/tests/check_for_valid_readme.py
@@ -1,4 +1,4 @@
-"""Test script to check README.rst files for syntax errors."""
+"""Test script to check given paths for valid README.rst files."""
import argparse
import sys
from pathlib import Path
@@ -24,28 +24,28 @@ def parse_args():
return parser.parse_args()
-if __name__ == "__main__":
+def main():
args = parse_args()
-
error = False
- all_readmes_found = True
- for path in map(Path, args.path):
+ for path in map(Path, args.paths):
readme = path / "README.rst"
- if not readme.exists():
- all_readmes_found = False
- print("✗ No README.rst in", str(path))
- continue
- if not is_valid_rst(readme):
+ try:
+ if not is_valid_rst(readme):
+ error = True
+ print("FAILED: RST syntax errors in", readme)
+ continue
+ except FileNotFoundError:
error = True
- print("✗ RST syntax errors in", readme)
+ print("FAILED: README.rst not found in", path)
continue
if args.verbose:
- print("✓", readme)
+ print("PASSED:", readme)
if error:
sys.exit(1)
- if all_readmes_found:
- print("All clear.")
- else:
- print("No errors found but not all packages have a README.rst")
+ print("All clear.")
+
+
+if __name__ == "__main__":
+ main()
From 05aafa00dfdbdce957cb8f951a3c6167788ae7f5 Mon Sep 17 00:00:00 2001
From: Daniel Lemm <61800298+ffe4@users.noreply.github.com>
Date: Thu, 26 Mar 2020 17:25:54 +0100
Subject: [PATCH 6/7] Move check_for_valid_readme.py to ./scripts
---
{tests => scripts}/check_for_valid_readme.py | 0
scripts/eachdist.py | 2 +-
2 files changed, 1 insertion(+), 1 deletion(-)
rename {tests => scripts}/check_for_valid_readme.py (100%)
diff --git a/tests/check_for_valid_readme.py b/scripts/check_for_valid_readme.py
similarity index 100%
rename from tests/check_for_valid_readme.py
rename to scripts/check_for_valid_readme.py
diff --git a/scripts/eachdist.py b/scripts/eachdist.py
index a0feb9a68f8..f1c5e18b60b 100755
--- a/scripts/eachdist.py
+++ b/scripts/eachdist.py
@@ -485,7 +485,7 @@ def lint_args(args):
execute_args(
parse_subargs(
args,
- ("exec", "python tests/check_for_valid_readme.py {}", "--all",),
+ ("exec", "python scripts/check_for_valid_readme.py {}", "--all",),
)
)
From 14867bc3e6a01da74ce7e911019e1b187968cd99 Mon Sep 17 00:00:00 2001
From: Daniel Lemm <61800298+ffe4@users.noreply.github.com>
Date: Thu, 26 Mar 2020 17:48:15 +0100
Subject: [PATCH 7/7] Fix linting in check_for_valid_readme.py
---
scripts/check_for_valid_readme.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/check_for_valid_readme.py b/scripts/check_for_valid_readme.py
index 3ae65dd8fda..edf94d9c3e1 100644
--- a/scripts/check_for_valid_readme.py
+++ b/scripts/check_for_valid_readme.py
@@ -8,8 +8,8 @@
def is_valid_rst(path):
"""Checks if RST can be rendered on PyPI."""
- with open(path) as f:
- markup = f.read()
+ with open(path) as readme_file:
+ markup = readme_file.read()
return readme_renderer.rst.render(markup) is not None