diff --git a/docsite/config.py b/docsite/config.py index 585e3ae..d6959bc 100644 --- a/docsite/config.py +++ b/docsite/config.py @@ -69,12 +69,15 @@ class BrandConfig(_Frozen): class Reference(_Frozen): - """A generated API reference: one page per top-level module of `package`, with submodules.""" + """A generated API reference: one page per package and subpackage of `package`.""" # The import name, e.g. appinfra or llm_saia package: str # The checkout directory that holds the package directory source: str = "." + # Subpackages left out of the reference with everything under them, as dotted paths relative + # to the package (examples, cli.tools). The packages ship their runnable examples as one. + exclude: tuple[str, ...] = ("examples",) class Package(_Frozen): diff --git a/docsite/navtree.py b/docsite/navtree.py index 9ac92e8..804cf91 100644 --- a/docsite/navtree.py +++ b/docsite/navtree.py @@ -32,8 +32,27 @@ class SectionIndex: def package_nav(pkg: Package) -> list[NavItem]: - """The package's docs tree with renames applied, paths relative to the package's directory.""" - return map_paths(pkg.docs, pkg.site_path) + """The package's docs tree with renames applied, paths relative to the package's directory. + Files staged under another name than .md, such as an image a page shows, are published but + are not pages, so they and sections left empty are not in it.""" + return _pages_only(map_paths(pkg.docs, pkg.site_path)) + + +def _pages_only(items: Sequence[NavItem]) -> list[NavItem]: + """The tree without its non-.md paths and the sections that held only those.""" + out: list[NavItem] = [] + for item in items: + if isinstance(item, str): + if item.endswith(".md"): + out.append(item) + continue + ((title, value),) = item.items() + if isinstance(value, str): + if value.endswith(".md"): + out.append(item) + elif kept := _pages_only(value): + out.append({title: kept}) + return out def map_paths(items: Sequence[NavItem], fn: Callable[[str], str]) -> list[NavItem]: diff --git a/docsite/reexports.py b/docsite/reexports.py index a5ffcf9..adb4bcc 100644 --- a/docsite/reexports.py +++ b/docsite/reexports.py @@ -38,7 +38,9 @@ class Exports(Extension): def on_package(self, *, pkg: Module, loader: GriffeLoader, **kwargs: Any) -> None: """Rewrite every package of the loaded package.""" for package in _packages(pkg): - rows = [_row(name, *place) for name, place in _take_exports(package)] + # Alphabetical, as mkdocstrings orders the members (zensical.base.toml) + taken = sorted(_take_exports(package), key=lambda item: item[0]) + rows = [_row(name, *place) for name, place in taken] if rows: _append(package, _HEADER + "\n".join(rows), loader) diff --git a/docsite/reference.py b/docsite/reference.py index 19cc9f2..a5aac62 100644 --- a/docsite/reference.py +++ b/docsite/reference.py @@ -30,18 +30,20 @@ def reference_modules(checkout: Path, ref: Reference) -> list[str]: root = checkout / ref.source / ref.package if not (root / "__init__.py").is_file() or root.is_symlink(): raise ReferenceSourceError(f"{root} is not a package directory") - return _walk(root, ref.package) + return _walk(root, ref.package, {f"{ref.package}.{name}" for name in ref.exclude}) -def _walk(folder: Path, dotted: str) -> list[str]: - """The public subpackages under `folder`, the package `dotted`, recursively.""" +def _walk(folder: Path, dotted: str, exclude: set[str]) -> list[str]: + """The public subpackages under `folder`, the package `dotted`, recursively; an excluded + one is skipped with everything under it.""" packages = [] for entry in sorted(folder.iterdir()): - if entry.name.startswith("_") or entry.is_symlink(): + name = f"{dotted}.{entry.name}" + if entry.name.startswith("_") or entry.is_symlink() or name in exclude: continue if (entry / "__init__.py").is_file(): - packages.append(f"{dotted}.{entry.name}") - packages += _walk(entry, f"{dotted}.{entry.name}") + packages.append(name) + packages += _walk(entry, name, exclude) return packages diff --git a/etc/docsite.yaml b/etc/docsite.yaml index 5a2492e..85f25d7 100644 --- a/etc/docsite.yaml +++ b/etc/docsite.yaml @@ -41,14 +41,16 @@ brand: # Packages by name. Each is fetched at its git `ref`: a release tag for the published site; for a # preview, a branch or @ (pushed), set in a gitignored Makefile.local as # `serve: export INFRA_PACKAGES__REF := develop@9843ff` (NAME upper-cased, - as _). -# `docs_root` is its docs directory in the repo (default: docs). The package's docs are the source and are published as they are; the -# arrangement is the site's. `docs` is the package's tree in the site nav and its allowlist at -# once: only the files it lists are published, in that order. An entry is a path (titled by the -# page's heading), {Title: path}, or {Section: [entries]}. No wildcards: a new file must be -# listed to ship. `rename` stages a file under another name. `reference` adds an API reference -# generated from the package's docstrings. Each package also needs a landing page, -# pages//index.md, and an entry {: /index.md} under Packages in -# zensical.base.toml. +# `docs_root` is its docs directory in the repo (default: docs). The package's docs are the source +# and are published as they are; the arrangement is the site's. `docs` is the package's tree in +# the site nav and its allowlist at once: only the files it lists are published, in that order. +# An entry is a path (titled by the page's heading), {Title: path}, or {Section: [entries]}. A +# file that is not a page, such as an image a page shows, is published but stays out of the nav. +# No wildcards: a new file must be listed to ship. `rename` stages a file under another name. +# `reference` adds an API reference generated from the package's docstrings; its `exclude` lists +# subpackages to leave out, as dotted paths relative to the package (default: [examples]). Each +# package also needs a landing page, pages//index.md, and an entry +# {: /index.md} under Packages in zensical.base.toml. packages: appinfra: repo: https://github.com/llm-works/appinfra.git @@ -115,3 +117,66 @@ packages: - Security policy: SECURITY.md # The docs are published under appinfra's licence (Apache 2.0), which ships with them - License: LICENSE + + llm-infer: + repo: https://github.com/llm-works/llm-infer.git + ref: v0.9.0 + reference: + package: llm_infer + docs: + - usage.md + - client.md + - config.md + - engines.md + - adapters.md + - architecture.md + - api.md + - known-issues.md + + llm-saia: + repo: https://github.com/llm-works/llm-saia.git + ref: v0.6.3 + reference: + package: llm_saia + docs: + - INTRO.md + # A section without a page of its own: the site generates guides/index.md, listing them + - Guides: + - pydantic.md + - custom-verbs.md + - backend.md + - tool-gates.md + - production.md + - demo/demo.gif + + llm-kelt: + repo: https://github.com/llm-works/llm-kelt.git + ref: v0.5.1 + # Zensical takes a README.md as the folder's index, which is the landing page here + rename: + README.md: overview.md + reference: + package: llm_kelt + docs: + - README.md + - quickstart.md + - concepts.md + - atomic-memory.md + - knowledge-graph.md + - context-and-rag.md + - conversation.md + - multi-schema.md + - training.md + - cli.md + - glossary.md + + llm-gent: + repo: https://github.com/llm-works/llm-gent.git + ref: v0.4.1 + # index.md is the landing page here (pages/llm-gent/index.md) + rename: + index.md: guide.md + reference: + package: llm_gent + docs: + - index.md diff --git a/pages/llm-gent/index.md b/pages/llm-gent/index.md index 5d94dcb..c0d6107 100644 --- a/pages/llm-gent/index.md +++ b/pages/llm-gent/index.md @@ -1,9 +1,28 @@ +--- +hide: + - toc +--- + # llm-gent Composable agent framework: agents are built from traits that provide capabilities such as LLM access, storage and learning, and run standalone or as services through the HTTP runtime. +{ .lw-lead } + +
+ +- :lucide-book-open:{ .lw-card-icon } + + **[Guide](guide.md)** + + Agents, traits and their lifecycle, and flow composition. + +- :lucide-braces:{ .lw-card-icon } + + **[API reference](reference/index.md)** + + Every public module, class and function, generated from the source at the release tag. -!!! info "Coming soon" - The llm-gent guides and API reference. +
Source: [llm-works/llm-gent](https://github.com/llm-works/llm-gent) diff --git a/pages/llm-infer/index.md b/pages/llm-infer/index.md index a3412f9..a7c3015 100644 --- a/pages/llm-infer/index.md +++ b/pages/llm-infer/index.md @@ -1,10 +1,42 @@ +--- +hide: + - toc +--- + # llm-infer One client for OpenAI, Anthropic, Google and any OpenAI-compatible server, with routing, cross-provider fallback, retries and rate limiting; plus `llm-infer serve`, which puts local models behind one OpenAI-compatible endpoint. +{ .lw-lead } + +
+ +- :lucide-book-open:{ .lw-card-icon } + + **[Usage guide](usage.md)** + + Running `llm-infer serve`: setup, CLI commands, the OpenAI SDK against it, tuning and + debugging. + +- :lucide-settings:{ .lw-card-icon } + + **[Configuration](config.md)** + + The server's configuration: backend selection, engine configs, API and request settings. + +- :lucide-compass:{ .lw-card-icon } + + **[Architecture](architecture.md)** + + The server's layers and engine backends, a request's lifecycle, memory and batching. + +- :lucide-braces:{ .lw-card-icon } + + **[API reference](reference/index.md)** + + Every public module, class and function, generated from the source at the release tag. -!!! info "Coming soon" - The llm-infer guides and API reference. +
Source: [llm-works/llm-infer](https://github.com/llm-works/llm-infer) diff --git a/pages/llm-kelt/index.md b/pages/llm-kelt/index.md index 8084c45..414d200 100644 --- a/pages/llm-kelt/index.md +++ b/pages/llm-kelt/index.md @@ -1,10 +1,41 @@ +--- +hide: + - toc +--- + # llm-kelt Persistent memory and fine-tuning data for LLM applications, backed by Postgres: store facts, feedback and preferences, retrieve them for prompts and RAG, and train LoRA and DPO adapters from them. +{ .lw-lead } + +
+ +- :lucide-book-open:{ .lw-card-icon } + + **[Overview](overview.md)** + + Every document and when to read it. + +- :lucide-rocket:{ .lw-card-icon } + + **[Quickstart](quickstart.md)** + + Postgres, install and config, then record a first fact and inject it into a prompt. + +- :lucide-compass:{ .lw-card-icon } + + **[Concepts](concepts.md)** + + Context keys, schemas, atomic memory versus the knowledge graph, and the clients. + +- :lucide-braces:{ .lw-card-icon } + + **[API reference](reference/index.md)** + + Every public module, class and function, generated from the source at the release tag. -!!! info "Coming soon" - The llm-kelt guides and API reference. +
Source: [llm-works/llm-kelt](https://github.com/llm-works/llm-kelt) diff --git a/pages/llm-saia/index.md b/pages/llm-saia/index.md index c97da07..c7376d1 100644 --- a/pages/llm-saia/index.md +++ b/pages/llm-saia/index.md @@ -1,9 +1,34 @@ +--- +hide: + - toc +--- + # llm-saia Structured verbs for LLM interactions: verify, critique, decompose, extract, synthesize and more, each returning a typed result instead of free text. +{ .lw-lead } + +
+ +- :lucide-book-open:{ .lw-card-icon } + + **[Introduction](INTRO.md)** + + Typed contracts for LLM outputs: what the verbs are and how they are used. + +- :lucide-compass:{ .lw-card-icon } + + **[Guides](guides/index.md)** + + Pydantic schemas, custom verbs, backends, tool gates and production use. + +- :lucide-braces:{ .lw-card-icon } + + **[API reference](reference/index.md)** + + Every public module, class and function, generated from the source at the release tag. -!!! info "Coming soon" - The llm-saia guides and API reference. +
Source: [llm-works/llm-saia](https://github.com/llm-works/llm-saia) diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py index 231a2c4..3627257 100644 --- a/tests/integration/test_cli.py +++ b/tests/integration/test_cli.py @@ -116,16 +116,10 @@ def test_build_runs_every_step( # The staged directory, relative to zensical.toml assert config["project"]["docs_dir"] == "docs" entry = config["project"]["nav"][1]["Packages"][1]["pkg"] - assert entry[:3] == [ - "pkg/index.md", - {"Introduction": "pkg/intro.md"}, - {"Demo": ["pkg/demo/index.md", "pkg/demo/demo.gif"]}, - ] - assert entry[3]["API reference"][0] == "pkg/reference/index.md" - # The Demo section has no page of its own: one is generated, listing its entries - assert (docs / "pkg" / "demo" / "index.md").read_text(encoding="utf-8") == ( - "# Demo\n\n- [Demo](demo.gif)\n" - ) + # The Demo section holds only an image: published above, but no pages, so not in the nav + assert entry[:2] == ["pkg/index.md", {"Introduction": "pkg/intro.md"}] + assert entry[2]["API reference"][0] == "pkg/reference/index.md" + assert not (docs / "pkg" / "demo" / "index.md").exists() python = config["project"]["plugins"]["mkdocstrings"]["handlers"]["python"] assert python["paths"] == [(tmp_path / "build" / "pkg").as_posix()] diff --git a/tests/integration/test_reference_modules.py b/tests/integration/test_reference_modules.py index 016b7fa..d9b6ae3 100644 --- a/tests/integration/test_reference_modules.py +++ b/tests/integration/test_reference_modules.py @@ -39,6 +39,24 @@ def test_public_subpackages_at_every_depth(tmp_path: Path) -> None: assert reference_modules(tmp_path, ref) == ["mypkg.sub", "mypkg.sub.deep"] +def test_excluded_subpackages_are_left_out_with_their_subpackages(tmp_path: Path) -> None: + """examples is excluded by default; a nested entry (sub.deep) leaves out only that part.""" + pkg = _package(tmp_path) + for rel in ("examples/__init__.py", "examples/demo/__init__.py"): + (pkg / rel).parent.mkdir(parents=True, exist_ok=True) + (pkg / rel).write_text("", encoding="utf-8") + assert reference_modules(tmp_path, Reference(package="mypkg", source="src")) == [ + "mypkg.sub", + "mypkg.sub.deep", + ] + ref = Reference(package="mypkg", source="src", exclude=("sub.deep",)) + assert reference_modules(tmp_path, ref) == [ + "mypkg.examples", + "mypkg.examples.demo", + "mypkg.sub", + ] + + def test_missing_package_fails(tmp_path: Path) -> None: """The reference config must point at a package directory.""" with pytest.raises(ReferenceSourceError, match="not a package"): diff --git a/tests/unit/test_navtree.py b/tests/unit/test_navtree.py index 1800fb7..f06d43f 100644 --- a/tests/unit/test_navtree.py +++ b/tests/unit/test_navtree.py @@ -26,6 +26,15 @@ def test_package_nav_applies_renames_at_any_depth() -> None: assert package_nav(pkg) == [{"Guide": "guide.md"}, {"Sub": ["sub/overview.md", "sub/x.md"]}] +def test_package_nav_leaves_out_files_that_are_not_pages() -> None: + """An image a page shows is published with the docs but has no place in the nav; a + plain-text file staged as .md (LICENSE as license.md) is a page and keeps its place.""" + docs = ["intro.md", "demo/demo.gif", {"Media": ["img/a.png"]}, {"License": "LICENSE"}] + packages = {"pkg": package_dict(docs=docs, rename={"LICENSE": "license.md"})} + pkg = load_build_config(build_dict(packages=packages)).packages[0] + assert package_nav(pkg) == ["intro.md", {"License": "license.md"}] + + def test_index_sections_adds_a_page_to_sections_without_one() -> None: """A section gets a generated page first, at its titles slugged; nested sections too.""" tree = ["intro.md", {"Guides": [{"Dev tooling": ["g/a.md"]}, {"B": "g/b.md"}]}] diff --git a/zensical.base.toml b/zensical.base.toml index 63eeeca..1369bb8 100644 --- a/zensical.base.toml +++ b/zensical.base.toml @@ -104,7 +104,11 @@ custom_templates = "overrides/mkdocstrings" # and lists a package's re-exported names, linked, instead of documenting them a second time extensions = ["docsite/docstring_code.py:CodeBlocks", "docsite/reexports.py:Exports"] docstring_style = "google" -members_order = "source" +# Members by kind (attributes, classes, functions; in a class: attributes, then methods), each +# kind alphabetical. On a package page, source order would be the order of __init__'s imports. +# The Exports table (docsite/reexports.py) is alphabetical too. +group_by_category = true +members_order = "alphabetical" # Each package has its own page (docsite/reference.py), so a page holds only its own members show_submodules = false # Private and special (dunder) members stay out of the reference; merge_init_into_class keeps