Files
computer-playbook/roles/web-app-docs/files/python/infinito_docs/identity.py
T
kevinveenbirkenbachandClaude Opus 5 ee632c7f9c test(web-app-docs): mirror the identity reader and take its path from the SPOT
identity.py built the services.yml path by hand, which test_file_spot.py names: utils/roles/mapping.py:175 holds ROLE_FILE_META_SERVICES, and bed4b3c84f already uses it in this role. The module meant to make services.yml the single source had duplicated a path of its own.

test_mirrored_unit_tests.py also required the matching test. It proves three things against a synthetic tree rather than the real values, so it cannot pass tautologically: the configured values arrive under the environment names conf.py reads, an undefined group variable is refused instead of rendering empty, and the repository's own configuration resolves with no {{ left in any value.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-16 00:33:17 +02:00

47 lines
1.7 KiB
Python

"""Resolve the Sphinx identity the documentation is configured with.
``conf.py`` takes project, copyright and author from the environment, which the
role's ``env.j2`` fills from ``services.docs.sphinx``. Callers that run outside
that container - the host side of ``make i18n-extract`` and the unit tests -
read the same configuration through here instead of repeating its values.
"""
from __future__ import annotations
from pathlib import Path
from jinja2 import Environment, StrictUndefined, select_autoescape
from utils.cache.yaml import load_yaml_str
from utils.roles.mapping import ROLE_FILE_META_SERVICES
ROLE = "web-app-docs"
GENERAL_FILE = Path("group_vars") / "all" / "00_general.yml"
def docs_sphinx_identity(root: Path) -> dict[str, str]:
"""Render ``services.docs.sphinx`` into the environment ``conf.py`` reads.
Args:
root: repository root holding the role and the group variables.
Returns:
``{"DOCS_SPHINX_PROJECT": ..., "DOCS_SPHINX_COPYRIGHT": ...,
"DOCS_SPHINX_AUTHOR": ...}``, with the group variables the configured
values reference substituted.
"""
services_file = root / "roles" / ROLE / ROLE_FILE_META_SERVICES
services = load_yaml_str(services_file.read_text(encoding="utf-8"))
general = load_yaml_str((root / GENERAL_FILE).read_text(encoding="utf-8"))
context = {key: value for key, value in general.items() if isinstance(value, str)}
environment = Environment(
undefined=StrictUndefined,
autoescape=select_autoescape(["html", "xml"]),
)
return {
f"DOCS_SPHINX_{key.upper()}": environment.from_string(str(value)).render(
**context
)
for key, value in services["docs"]["sphinx"].items()
}