Skip to content

Commit 2ed3ece

Browse files
committed
Clean
1 parent d41cb20 commit 2ed3ece

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

exts/coding_guidelines/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from . import std_role
77
from . import fls_linking
88
from . import guidelines_checks
9+
from . import rust_examples_test
910

1011
from sphinx_needs.api import add_dynamic_function
1112
from sphinx.errors import SphinxError
@@ -60,6 +61,7 @@ def setup(app):
6061
)
6162

6263
app.connect('env-check-consistency', guidelines_checks.validate_required_fields)
64+
app.connect('env-check-consistency', rust_examples_test.execute_tests)
6365

6466
app.connect('env-check-consistency', fls_checks.check_fls)
6567

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-License-Identifier: MIT OR Apache-2.0
2+
# SPDX-FileCopyrightText: The Coding Guidelines Subcommittee Contributors
3+
4+
import re
5+
from sphinx.errors import SphinxError
6+
from sphinx_needs.data import SphinxNeedsData
7+
import logging
8+
9+
logger = logging.getLogger('sphinx')
10+
11+
class ExecuteRustExamples(SphinxError):
12+
category = "Integrity Check Error"
13+
14+
def execute_tests(app, env):
15+
"""
16+
Aggregate and test rust examples
17+
"""
18+
logger.debug("Testing examples")
19+
data = SphinxNeedsData(env)
20+
needs = data.get_needs_view()
21+
22+
required_fields = app.config.required_guideline_fields # Access the configured values
23+
24+
for key, value in needs.items():
25+
print("======++++++++")
26+
27+
# print(key, " -- ", value)
28+
if key.startswith("non_compl_ex") or key.startswith("compl_ex"):
29+
30+
text = value.get("content", "")
31+
match = re.search(
32+
r"\.\. code-block:: rust\s*\n\n((?: {2,}.*\n?)+)", text, re.DOTALL
33+
)
34+
if match:
35+
code_block = match.group(1)
36+
code_lines = [line[2:] if line.startswith(" ") else line for line in code_block.splitlines()]
37+
rust_code = "\n".join(code_lines)
38+
print("Extracted Rust code:\n")
39+
print(rust_code)
40+
else:
41+
print("No Rust code block found.")

0 commit comments

Comments
 (0)