Skip to content

Commit 86b8efc

Browse files
committed
Fix Unpin rstcheck
Signed-off-by: Ganesh Hubale <ganeshhubale03@gmail.com>
1 parent 634e6d0 commit 86b8efc

File tree

3 files changed

+43
-52
lines changed

3 files changed

+43
-52
lines changed

tests/checkers/rstcheck.py

+38-52
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,49 @@
1-
"""Sanity test using rstcheck and sphinx."""
1+
"""Sanity test using rstcheck-core and sphinx."""
22
from __future__ import annotations
33

4-
import re
5-
import subprocess
4+
from rstcheck_core.runner import RstcheckMainRunner
5+
from rstcheck_core.config import RstcheckConfig
6+
import pathlib
67
import sys
78

89

910
def main():
10-
paths = sys.argv[1:] or sys.stdin.read().splitlines()
11-
12-
encoding = 'utf-8'
13-
14-
ignore_substitutions = (
15-
'br',
11+
# Read input paths from CLI arguments or stdin
12+
if sys.argv[1:]:
13+
raw_paths = sys.argv[1:]
14+
else:
15+
raw_paths = sys.stdin.read().splitlines()
16+
17+
# Convert to pathlib.Path objects
18+
paths = [pathlib.Path(p) for p in raw_paths]
19+
20+
# Handle case where no paths are provided
21+
if not paths:
22+
print("No files or directories provided for checking.", file=sys.stderr)
23+
sys.exit(1)
24+
25+
# Define the configuration for rstcheck
26+
config = RstcheckConfig(
27+
ignore_roles=[
28+
"ansplugin", "ansopt", "ansretval", "ansval", "ansenvvar", "ansenvvarref"
29+
],
30+
ignore_substitutions=["br"],
31+
report_level="warning", # Adjust report level as needed: "info", "warning", "error", "severe", "none"
32+
recursive=True, # Set to True to check directories recursively
1633
)
1734

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)))
58-
59-
return matched
60-
35+
# Initialize the runner
36+
runner = RstcheckMainRunner(
37+
check_paths=paths,
38+
rstcheck_config=config,
39+
overwrite_config=True,
40+
)
41+
42+
# Run the checks
43+
exit_code = runner.run()
44+
45+
# Exit with the appropriate code
46+
sys.exit(exit_code)
6147

6248
if __name__ == '__main__':
6349
main()

tests/requirements.in

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sphinx-notfound-page # extension used for the custom 404 page (cowsay)
1111
sphinx-ansible-theme # extension used for the custom docs theme
1212
sphinx-rtd-theme
1313
rstcheck
14+
rstcheck-core
1415
sphinx-copybutton
1516
jinja2 # used by hacking/build_library/build_ansible/command_plugins/generate_man.py and dump_keywords.py
1617
pyyaml # used by ansible-core

tests/requirements.txt

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ docutils==0.18.1
6868
# antsibull-docs
6969
# antsibull-docutils
7070
# rstcheck
71+
# rstcheck-core
7172
# sphinx
7273
# sphinx-rtd-theme
7374
frozenlist==1.5.0
@@ -112,6 +113,7 @@ pydantic==2.10.5
112113
# via
113114
# antsibull-core
114115
# antsibull-docs
116+
# rstcheck-core
115117
pydantic-core==2.27.2
116118
# via pydantic
117119
pygments==2.19.1
@@ -138,6 +140,8 @@ rstcheck==5.0.0
138140
# -r tests/requirements.in
139141
# antsibull-changelog
140142
# antsibull-docs
143+
rstcheck-core==1.2.1
144+
# via -r tests/requirements.in
141145
semantic-version==2.10.0
142146
# via
143147
# antsibull-changelog

0 commit comments

Comments
 (0)