Skip to content

Commit 28426ba

Browse files
authored
Implement validation (#10)
* Introduce "docbuild validate" command * Add XML checks * Taken from docserv repo, share/validate-product-config/checks/ * Add tests for positive and negative outcome * Add xmlnode fixture * Add decorator to registry XML checks * Add factory_registry() and RegistryDecorator * Add pytest-asyncio as test requirement * VSCode: Add "tmp/" in files.exclude * Update doc sources * Add RNC schema and stylesheet * Add product config schema * Add simplify.xsl stylesheet * Update `pyproject.toml` to include rnc and xslt from docbuild.xml.data * Resolve XIncludes with xmllint and validate with jing Although Jing does know XIncludes to some degree by using the Xerces parser, Xerces does not fully understand XPointers. To circumvent this issue, we need to use xmllint to the rescue. It knows more XPointer expressions and can resolve them correctly. Algorithm: 1. Create an (async) subprocess with xmllint calling "xmllint --xinclude FILE". Output result to an intermediate temporary file. Unfortunately, this is needed as the current "jing" script on openSUSE doesn't support reading from stdin. 2. Check if return code is zero. If not, return 3. Create an (async) subprocess with jing. It uses the output from step 1 and validates it with the RNC schema.
1 parent faeb742 commit 28426ba

38 files changed

Lines changed: 4224 additions & 24 deletions

.coveragerc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
[run]
22
concurrency = multiprocessing
33
parallel = true
4+
5+
[report]
6+
precision = 1
7+
exclude_lines =
8+
pragma: no cover
9+
raise NotImplementedError
10+
if TYPE_CHECKING:
11+
if __name__ == .__main__.:
12+
if 0:
13+
if False:

.pytest.ini

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ addopts =
1919
--cov=docbuild
2020
--cov-branch
2121
--cov-report=term-missing
22-
--cov-fail-under=90
2322
--doctest-glob='*.rst'
2423
--doctest-modules
2524
--doctest-report ndiff
25+
26+
# See https://docs.python.org/3/library/doctest.html#option-flags-and-directives
27+
doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL
28+
29+
# From pytest-asyncio:
30+
asyncio_mode = auto

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
".pytest_cache/": true,
1111
".ruff_cache/": true,
1212
".venv*/": true,
13-
"**/*.egg-info/": true
13+
"**/*.egg-info/": true,
14+
"tmp/": true
1415
},
1516
"python.analysis.diagnosticsSource": "Pyright",
1617
"python.analysis.typeCheckingMode": "standard",

IDEAS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ This is a unsorted collection of ideas what could be implemented.
1313

1414
* `Deliverable`
1515
support subdeliverables?
16+
17+
* Implement a "check environment" function.
18+
Before we really do anything, this check some prerequisites:
19+
* Checks if certain commands are available (e.g. `git`, `jing`)
20+
* Check if commands have a minimum version
21+
* Check if the available space is enough (can be customized in the envconfig)
22+
* More...?
23+
24+
This should help that it breaks in the middle of, for example, a build operation.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Implement :command:`validate` subcommand
2+
3+
This subcommand is used to validate XML configuration files against a RelaxNG schema. It checks both the structure and semantic correctness of the XML files to ensure they conform to the expected format.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
docbuild.cli.cmd_validate
2+
=========================
3+
4+
.. py:module:: docbuild.cli.cmd_validate
5+
6+
.. autoapi-nested-parse::
7+
8+
CLI interface to validate XML configuration files.
9+
10+
11+
12+
Functions
13+
---------
14+
15+
.. autoapisummary::
16+
17+
docbuild.cli.cmd_validate.validate
18+
19+
20+
Module Contents
21+
---------------
22+
23+
.. py:function:: validate(ctx: click.Context, xmlfiles: tuple | collections.abc.Iterator[pathlib.Path]) -> None
24+
25+
Subcommand to validate XML configuration files.
26+
27+
:param ctx: The Click context object.
28+
29+

docs/source/reference/_autoapi/docbuild/cli/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Submodules
2727
/reference/_autoapi/docbuild/cli/cmd_build/index
2828
/reference/_autoapi/docbuild/cli/cmd_c14n/index
2929
/reference/_autoapi/docbuild/cli/cmd_cli/index
30+
/reference/_autoapi/docbuild/cli/cmd_validate/index
3031
/reference/_autoapi/docbuild/cli/config/index
3132
/reference/_autoapi/docbuild/cli/context/index
3233
/reference/_autoapi/docbuild/cli/defaults/index

docs/source/reference/_autoapi/docbuild/config/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ docbuild.config
55
66
.. autoapi-nested-parse::
77

8-
Configuration for app and env config.
8+
Tools for app, env, and XML config.
99

1010

1111

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
docbuild.config.xml.checks.CheckResult
2+
======================================
3+
4+
.. py:class:: docbuild.config.xml.checks.CheckResult
5+
6+
Result of a validation check.
7+
8+
9+
.. py:method:: __bool__() -> bool
10+
11+
Return True if the check was successful, False otherwise.
12+
13+

0 commit comments

Comments
 (0)