-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for package readme syntax errors
Fixes #445
- Loading branch information
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |