Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ APPINFRA_DEV_CQ_DEAD ?= strict
APPINFRA_DEV_TEST_HEALTH ?= warn

# Test coverage threshold (percentage), measured over unit and integration tests
APPINFRA_PYTEST_COVERAGE_THRESHOLD ?= 95
APPINFRA_PYTEST_COVERAGE_THRESHOLD ?= 90
APPINFRA_PYTEST_COVERAGE_MARKERS ?= unit or integration

# Docstring coverage threshold (percentage)
Expand Down
5 changes: 5 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ one.
This repository builds a static site. In scope: the build tooling, the GitHub Actions workflows,
and the site shell (header, scripts, styles). Issues in a package's own code or docs belong to that
package's repository and its security policy.

The build trusts its inputs: `etc/docsite.yaml`, the `INFRA_*` environment variables that
override it, and the llm-works package repositories at the refs it names. It does not defend
against a malicious config or package repository (for example a symlink or path in a package's
docs pointing outside them); reports that need control of those inputs are out of scope.
7 changes: 4 additions & 3 deletions docsite/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from .config import BuildConfig, NavItem, Package
from .fetch import PackageFetcher, fetch_nav, fetch_text
from .links import link_to_repo
from .navtree import SectionIndex, index_sections, package_nav, page_title, render_section_index
from .reference import reference_modules, reference_nav, reference_pages
from .siteconf import render_site_config
Expand All @@ -32,7 +33,7 @@ def __init__(self, lg: Logger, cfg: BuildConfig) -> None:
self._cfg = cfg

def fetch(self) -> None:
"""Clone every package at its tag; download the nav partial and brand stylesheets."""
"""Clone every package at its ref; download the nav partial and brand stylesheets."""
fetcher = PackageFetcher(self._lg, self._cfg.site.build_dir)
for pkg in self._cfg.packages:
fetcher.fetch(pkg)
Expand Down Expand Up @@ -68,7 +69,7 @@ def stage(self) -> None:
def _stage_package(self, pkg: Package, stager: DocsStager, plan: dict[str, Source]) -> None:
"""Add a package's docs, its reference and its generated section pages to `plan`."""
checkout = self._cfg.site.build_dir / pkg.name
files = stager.files(pkg, checkout)
files = link_to_repo(self._lg, pkg, checkout, stager.files(pkg, checkout))
merge(plan, {f"{pkg.name}/{path}": src for path, src in files.items()}, pkg.name)
modules = self._reference_modules(pkg)
if modules is not None:
Expand All @@ -83,7 +84,7 @@ def nav(self) -> Path:
nav = self._cfg.nav
output = nav.output
output.parent.mkdir(parents=True, exist_ok=True)
header = render_header(nav_html, nav.site_origin, nav.docs_origin)
header = render_header(nav_html, nav.site_origin)
output.write_text(header, encoding="utf-8")
self._lg.info("header rendered", extra={"output": str(output)})
return output
Expand Down
4 changes: 2 additions & 2 deletions docsite/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from appinfra.app import AppBuilder

from .tools import BuildTool, FetchTool, NavTool, SiteConfigTool, StageTool
from .tools import BuildTool


def main() -> int:
Expand All @@ -18,7 +18,7 @@ def main() -> int:
.done()
.cli.with_all_flags()
.done()
.tools.with_tools(FetchTool(), StageTool(), NavTool(), SiteConfigTool(), BuildTool())
.tools.with_tools(BuildTool())
.done()
.build()
)
Expand Down
96 changes: 14 additions & 82 deletions docsite/cli/tools.py
Original file line number Diff line number Diff line change
@@ -1,111 +1,43 @@
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Copyright 2026 The llm-works-docs Authors

"""One CLI tool per build step."""
"""The CLI's one tool: the build."""

import tomllib
from typing import Any, ClassVar
from typing import Any

from appinfra.app.tools import Tool, ToolConfig
from pydantic import ValidationError

from ..build import Build
from ..config import load_build_config
from ..fetch import FetchError
from ..navtree import NavTreeError
from ..reference import ReferenceSourceError
from ..siteconf import SiteConfigError
from ..sitenav import NavMarkupError
from ..stage import StageError

_STEP_ERRORS = (
ValidationError,
# ValueError covers an invalid config, the nav markup, the docs tree and the base TOML
_BUILD_ERRORS = (
ValueError,
FetchError,
StageError,
NavMarkupError,
NavTreeError,
SiteConfigError,
ReferenceSourceError,
tomllib.TOMLDecodeError,
OSError,
)


class _StepTool(Tool):
"""Loads the build config and runs one step; a failed step exits 1."""

name: ClassVar[str]
help_text: ClassVar[str]
class BuildTool(Tool):
"""Fetch, stage, and render the header and the Zensical config; a failure exits 1."""

def __init__(self, parent: Any = None) -> None:
"""Register under the subclass's step name."""
super().__init__(parent, ToolConfig(name=self.name, help_text=self.help_text))
"""Register as `build`."""
help_text = "Fetch, stage, and render the header and the Zensical config"
super().__init__(parent, ToolConfig(name="build", help_text=help_text))

def run(self, **kwargs: Any) -> int:
"""Run the step; log and return 1 on a config, fetch, stage or nav error."""
"""Run every build step; log and return 1 on a known error."""
try:
build = Build(self.lg, load_build_config(self.app.config))
self._step(build)
except _STEP_ERRORS as e:
self.lg.error("build step failed", extra={"step": self.name, "exception": e})
Build(self.lg, load_build_config(self.app.config)).all()
except _BUILD_ERRORS as e:
self.lg.error("build failed", extra={"exception": e})
return 1
return 0

def _step(self, build: Build) -> None:
"""The step itself; each subclass calls one Build method."""
raise NotImplementedError


class FetchTool(_StepTool):
"""Clone packages at their tags and download the nav partial."""

name = "fetch"
help_text = "Clone each package at its tag and download the main site's nav"

def _step(self, build: Build) -> None:
"""Run Build.fetch."""
build.fetch()


class StageTool(_StepTool):
"""Assemble the docs directory from the site's pages and the packages' docs."""

name = "stage"
help_text = "Rebuild the docs directory from the site pages and each package's docs"

def _step(self, build: Build) -> None:
"""Run Build.stage."""
build.stage()


class NavTool(_StepTool):
"""Render the docs header from the fetched nav."""

name = "nav"
help_text = "Render the docs header from the fetched nav"

def _step(self, build: Build) -> None:
"""Run Build.nav."""
build.nav()


class SiteConfigTool(_StepTool):
"""Render the Zensical config with each package's docs tree in the nav."""

name = "config"
help_text = "Render the Zensical config from the base config and the packages"

def _step(self, build: Build) -> None:
"""Run Build.site_config."""
build.site_config()


class BuildTool(_StepTool):
"""Run every step."""

name = "build"
help_text = "Fetch, stage, and render the header and the Zensical config"

def _step(self, build: Build) -> None:
"""Run Build.all."""
build.all()
Loading