|
| 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