Files
computer-playbook/roles/web-app-docs/files/python/infinito_docs/i18n.py
T
kevinveenbirkenbachandClaude Opus 5 aceb5295ef feat(docs): let the documentation build generate what make docs generated
Cosmos, Quick Setup and Credits follow from meta/services.yml, categories.yml
and galaxy_info.author, yet 279 role READMEs carried a copy that went stale
whenever the metadata moved and nobody re-ran make docs. The documentation
build now runs the generators itself, against its own scratch checkout, and
the committed READMEs keep only the prose a person writes.

utils.cache.PROJECT_ROOT derives from the module's location, so putting the
checkout first on PYTHONPATH makes the generator operate on the scratch tree.
i18n.py and builder.py add it; the one remaining coupling, a relative_to over
PROJECT_ROOT in a log line, is gone.

CI extracted the "### Production" block from the committed README with awk.
Stripping the section made guide_deployable() return "" for every role, which
selects no deploy row and turns nothing red: a fail-open regression. It now
asks _is_role_invokable, which matches the old condition exactly (178 roles
either way, both difference sets empty), and cli/build/docs/readme/production.py
renders the block for the two guide scripts. All 178 renders are byte-identical
to what HEAD served, and both scripts' extraction pipelines produce identical
output for a web app, a service and a desktop role.

test_readme.py inverts: the three sections are now a hard failure in a
committed README. readme_md.md documents what each is derived from.

Removed: the docs, cosmos, readme-generate, readme-index and readme-check
targets, the five aliases pointing at them, and docs from make quality.

Verified by running generate_commands() in series against a copy of the
checkout: every command exits 0, no README is left without Cosmos or Credits,
and exactly the 178 invokable roles get a Quick Setup. The ansible_roles step
needs pandoc, which only the docs image carries, so that one link of the chain
is unexercised here; it is unchanged by this commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-26 01:09:22 +02:00

83 lines
2.4 KiB
Python

"""Extract the messages of the documentation into the ``docs`` gettext template.
Usage:
python -m infinito_docs.i18n --src <checkout> --output <docs.pot> --jobs <n>
"""
from __future__ import annotations
import argparse
import os
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
from infinito_docs.commands import generate_commands
PACKAGE_DIR = Path(__file__).resolve().parent
DOMAIN = "docs"
def extract(src: Path, output: Path, jobs: int) -> None:
"""Generate the sources of ``src`` and write their messages to ``output``.
Args:
src: scratch checkout; the generators write into it.
output: path of the resulting ``.pot`` file.
jobs: parallel Sphinx processes.
"""
tooling = str(PACKAGE_DIR.parent)
inherited = [
path for path in os.environ.get("PYTHONPATH", "").split(os.pathsep) if path
]
with tempfile.TemporaryDirectory(prefix="infinito-docs-i18n-") as scratch:
conf = Path(scratch) / "conf"
out = Path(scratch) / "out"
shutil.copytree(PACKAGE_DIR, conf)
if (src / "assets" / "img").is_dir():
shutil.copytree(
src / "assets" / "img", conf / "assets" / "img", dirs_exist_ok=True
)
env = {
**os.environ,
"PYTHONPATH": os.pathsep.join([str(src), tooling, *inherited]),
}
for command in generate_commands(src):
subprocess.run(command, check=True, env=env, cwd=scratch)
subprocess.run(
[
sys.executable,
"-m",
"sphinx",
"-b",
"gettext",
"-q",
"-W",
str(src),
str(out),
"-c",
str(conf),
"-j",
str(jobs),
],
check=True,
env=env,
cwd=scratch,
)
shutil.copyfile(out / f"{DOMAIN}.pot", output)
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("--src", required=True, type=Path)
parser.add_argument("--output", required=True, type=Path)
parser.add_argument("--jobs", required=True, type=int)
args = parser.parse_args()
extract(args.src.resolve(), args.output.resolve(), args.jobs)
if __name__ == "__main__":
main()