|
| 1 | +docbuild.cli.process_validation |
| 2 | +=============================== |
| 3 | + |
| 4 | +.. py:module:: docbuild.cli.process_validation |
| 5 | +
|
| 6 | +.. autoapi-nested-parse:: |
| 7 | + |
| 8 | + Module for processing XML validation in DocBuild. |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | +Functions |
| 13 | +--------- |
| 14 | + |
| 15 | +.. autoapisummary:: |
| 16 | + |
| 17 | + docbuild.cli.process_validation.display_results |
| 18 | + docbuild.cli.process_validation.run_command |
| 19 | + docbuild.cli.process_validation.validate_rng |
| 20 | + docbuild.cli.process_validation.run_python_checks |
| 21 | + docbuild.cli.process_validation.process_file |
| 22 | + docbuild.cli.process_validation.process |
| 23 | + |
| 24 | + |
| 25 | +Module Contents |
| 26 | +--------------- |
| 27 | + |
| 28 | +.. py:function:: display_results(shortname: str, check_results: list[tuple[str, docbuild.config.xml.checks.CheckResult]], verbose: int, max_len: int) -> None |
| 29 | +
|
| 30 | + Display validation results based on verbosity level using rich. |
| 31 | + |
| 32 | + :param shortname: Shortened name of the XML file being processed. |
| 33 | + :param check_results: List of tuples containing check names and their results. |
| 34 | + :param verbose: Verbosity level (0, 1, 2) |
| 35 | + :param max_len: Maximum length for formatting the output. |
| 36 | + |
| 37 | + |
| 38 | +.. py:function:: run_command(*args: str, env: dict[str, str] | None = None) -> tuple[int, str, str] |
| 39 | + :async: |
| 40 | + |
| 41 | + |
| 42 | + Run an external command and capture its output. |
| 43 | + |
| 44 | + :param args: The command and its arguments separated as tuple elements. |
| 45 | + :param env: A dictionary of environment variables for the new process. |
| 46 | + :return: A tuple of (returncode, stdout, stderr). |
| 47 | + :raises FileNotFoundError: if the command is not found. |
| 48 | + |
| 49 | + |
| 50 | +.. py:function:: validate_rng(xmlfile: pathlib.Path, rng_schema_path: pathlib.Path = PRODUCT_CONFIG_SCHEMA, *, xinclude: bool = True) -> tuple[bool, str] |
| 51 | + :async: |
| 52 | + |
| 53 | + |
| 54 | + Validate an XML file against a RELAX NG schema using jing. |
| 55 | + |
| 56 | + If `xinclude` is True (the default), this function resolves XIncludes by |
| 57 | + running `xmllint --xinclude` and piping its output to `jing`. This is |
| 58 | + more robust for complex XInclude statements, including those with XPointer. |
| 59 | + |
| 60 | + :param xmlfile: The path to the XML file to validate. |
| 61 | + :param rng_schema_path: The path to the RELAX NG schema file. It supports |
| 62 | + both RNC and RNG formats. |
| 63 | + :param xinclude: If True, resolve XIncludes with `xmllint` before validation. |
| 64 | + :return: A tuple containing a boolean success status and any output message. |
| 65 | + |
| 66 | + |
| 67 | +.. py:function:: run_python_checks(tree: lxml.etree._ElementTree) -> list[tuple[str, docbuild.config.xml.checks.CheckResult]] |
| 68 | + :async: |
| 69 | + |
| 70 | + |
| 71 | + Run all registered Python-based checks against a parsed XML tree. |
| 72 | + |
| 73 | + :param tree: The parsed XML element tree. |
| 74 | + :return: A list of tuples containing check names and their results. |
| 75 | + |
| 76 | + |
| 77 | +.. py:function:: process_file(filepath: pathlib.Path | str, context: docbuild.cli.context.DocBuildContext, max_len: int) -> int |
| 78 | + :async: |
| 79 | + |
| 80 | + |
| 81 | + Process a single file: RNG validation then Python checks. |
| 82 | + |
| 83 | + :param filepath: The path to the XML file to process. |
| 84 | + :param context: The DocBuildContext. |
| 85 | + :param max_len: Maximum length for formatting the output. |
| 86 | + :param rng_schema_path: Optional path to an RNG schema for validation. |
| 87 | + :return: An exit code (0 for success, non-zero for failure). |
| 88 | + |
| 89 | + |
| 90 | +.. py:function:: process(context: docbuild.cli.context.DocBuildContext, xmlfiles: tuple[pathlib.Path | str, Ellipsis] | collections.abc.Iterator[pathlib.Path]) -> int |
| 91 | + :async: |
| 92 | + |
| 93 | + |
| 94 | + Asynchronous function to process validation. |
| 95 | + |
| 96 | + :param context: The DocBuildContext containing environment configuration. |
| 97 | + :param xmlfiles: A tuple or iterator of XML file paths to validate. |
| 98 | + :raises ValueError: If no envconfig is found or if paths are not |
| 99 | + configured correctly. |
| 100 | + :return: 0 if all files passed validation, 1 if any failures occurred. |
| 101 | + |
| 102 | + |
0 commit comments