Skip to content

Commit 6fae821

Browse files
committed
Unpin rstcheck dependency and update to version 6.x
- Updated the rstcheck.py script to handle changes in the rstcheck-core API and output format. Signed-off-by: Ganesh Hubale <[email protected]>
1 parent 634e6d0 commit 6fae821

File tree

2 files changed

+29
-54
lines changed

2 files changed

+29
-54
lines changed

tests/checkers/rstcheck.py

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,34 @@
1-
"""Sanity test using rstcheck and sphinx."""
2-
from __future__ import annotations
3-
4-
import re
5-
import subprocess
1+
from rstcheck_core.runner import RstcheckMainRunner
2+
from rstcheck_core.config import RstcheckConfig
3+
import pathlib
64
import sys
75

8-
96
def main():
10-
paths = sys.argv[1:] or sys.stdin.read().splitlines()
11-
12-
encoding = 'utf-8'
13-
14-
ignore_substitutions = (
15-
'br',
7+
# Define the paths to check (passed as CLI arguments or from stdin)
8+
paths = [pathlib.Path(p) for p in (sys.argv[1:] or sys.stdin.read().splitlines())]
9+
10+
# Define the configuration for rstcheck
11+
config = RstcheckConfig(
12+
ignore_roles=[
13+
"ansplugin", "ansopt", "ansretval", "ansval", "ansenvvar", "ansenvvarref"
14+
],
15+
ignore_substitutions=["br"],
16+
report_level="warning", # Adjust report level as needed -> ["info": 1, "warning": 2, "error": 3,"severe": 4, "none": 5,]
17+
recursive=True, # Set to True to check directories recursively
1618
)
1719

18-
cmd = [
19-
sys.executable,
20-
'-c', 'import rstcheck; rstcheck.main();',
21-
'--report', 'warning',
22-
'--ignore-roles', 'ansplugin,ansopt,ansretval,ansval,ansenvvar,ansenvvarref',
23-
'--ignore-substitutions', ','.join(ignore_substitutions),
24-
] + paths
25-
26-
process = subprocess.run(cmd,
27-
stdin=subprocess.DEVNULL,
28-
stdout=subprocess.PIPE,
29-
stderr=subprocess.PIPE,
30-
check=False,
31-
)
32-
33-
if process.stdout:
34-
raise Exception(process.stdout)
35-
36-
pattern = re.compile(r'^(?P<path>[^:]*):(?P<line>[0-9]+): \((?P<level>INFO|WARNING|ERROR|SEVERE)/[0-4]\) (?P<message>.*)$')
37-
38-
results = parse_to_list_of_dict(pattern, process.stderr.decode(encoding))
39-
40-
for result in results:
41-
print('%s:%s:%s: %s' % (result['path'], result['line'], 0, result['message']))
42-
43-
44-
def parse_to_list_of_dict(pattern, value):
45-
matched = []
46-
unmatched = []
47-
48-
for line in value.splitlines():
49-
match = re.search(pattern, line)
50-
51-
if match:
52-
matched.append(match.groupdict())
53-
else:
54-
unmatched.append(line)
55-
56-
if unmatched:
57-
raise Exception('Pattern "%s" did not match values:\n%s' % (pattern, '\n'.join(unmatched)))
20+
# Initialize the runner
21+
runner = RstcheckMainRunner(
22+
check_paths=paths,
23+
rstcheck_config=config,
24+
overwrite_config=True,
25+
)
5826

59-
return matched
27+
# Run the checks
28+
exit_code = runner.run()
6029

30+
# Exit with the appropriate code
31+
sys.exit(exit_code)
6132

62-
if __name__ == '__main__':
33+
if __name__ == "__main__":
6334
main()

tests/constraints-base.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Known limitations for indirect/transitive dependencies.
2+
3+
rstcheck>=6.2.4
4+
sphinx-rtd-theme>=2.0.0 # Fix 404 pages with new sphinx -- https://github.com/ansible/ansible-documentation/issues/678

0 commit comments

Comments
 (0)