Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
#!/usr/bin/env python3
"""Generate the README's "supported printers" breadth block from the
source of truth.
The source of truth for *which printers Kiln supports* is
``kiln/src/kiln/data/printer_intelligence.json`` (one entry per model) plus
the canonical brand map (kept in sync with
``kiln.design_intelligence._MANUFACTURER_PREFIXES`` by
``tests/test_supported_printers.py``). This script reads that data, groups
models by brand, drops any model that is missing a required sibling profile
(so we never advertise a half-finished printer), and rewrites the marked
printer-breadth block in ``README.md``.
This is the auto-maintain hook: add a model to ``printer_intelligence.json``
(with its safety, slicer, and material-compatibility profiles) and rerun this
script — the README names the new model with zero hand-editing.
Usage::
python3 scripts/generate_supported_printers.py # write the block
python3 scripts/generate_supported_printers.py --check # CI gate: exit 1 if stale
Wire ``--check`` into pre-commit / CI so the committed block can never drift
from the data (the same guarantee ``check_doc_counts.py`` gives the README).
"""
from __future__ import annotations
import argparse
import json
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
DATA = ROOT / "kiln" / "src" / "kiln" / "data"
INTEL = DATA / "printer_intelligence.json"
README = ROOT / "README.md"
# kiln/README.md renders as the PyPI project page, which is where most people
# who are not already on GitHub meet the printer roster. It carried the
# catalogue LINK but never the size of the catalogue, so the one number a
# stranger wants ("do you cover my machine?") was the one number no surface
# there stated. Same data, same generator, so it cannot drift on its own.
PYPI_README = ROOT / "kiln" / "README.md"
RM_BEGIN = "<!-- BEGIN SUPPORTED PRINTERS (auto-generated by scripts/generate_supported_printers.py) -->"
RM_END = "<!-- END SUPPORTED PRINTERS -->"
# Required sibling surfaces. A model present in printer_intelligence.json but
# missing any of these is *incomplete* — we refuse to advertise it until its
# support is full-fledged. (kiln-pro's check_doc_counts.py is the hard parity
# gate across all five surfaces; this is the marketing-side safety net.)
REQUIRED_SURFACES = {
"safety": DATA / "safety_profiles.json",
"slicer": DATA / "slicer_profiles.json",
"material-compat": DATA / "design_knowledge" / "printer_material_compatibility.json",
}
# Generic fallback profiles, not real purchasable models — never advertised.
EXCLUDED_IDS = {"default", "klipper_generic"}
# Canonical printer_id-prefix -> manufacturer map. MUST stay identical to
# kiln.design_intelligence._MANUFACTURER_PREFIXES; that invariant is pinned by
# tests/test_supported_printers.py so the two can never silently drift. Order
# matters: more specific prefixes first.
MANUFACTURER_PREFIXES: list[tuple[str, str]] = [
("bambu_", "Bambu Lab"),
("elegoo_", "Elegoo"),
("prusa_", "Prusa Research"),
("voron_", "Voron"),
("anker", "AnkerMake"),
("artillery", "Artillery"),
("flashforge", "FlashForge"),
("qidi", "QIDI"),
("ratrig", "RatRig"),
("sovol", "Sovol"),
("creality_hi", "Creality"),
("cr10", "Creality"),
("ender", "Creality"),
("k1", "Creality"),
("k2", "Creality"),
("sparkx", "SparkX"),
("visionminer", "Vision Miner"),
("klipper_generic", "Generic"),
]
def derive_manufacturer(printer_id: str, display_name: str) -> str:
pid = printer_id.lower()
for prefix, mfr in MANUFACTURER_PREFIXES:
if pid.startswith(prefix):
return mfr
return display_name.split()[0] if display_name.strip() else "Unknown"
def _load(path: Path) -> dict:
return json.loads(path.read_text())
def build_surface() -> tuple[dict, list[tuple[str, list[str]]]]:
intel = _load(INTEL)
siblings = {name: _load(path) for name, path in REQUIRED_SURFACES.items()}
incomplete: list[tuple[str, list[str]]] = []
by_brand: dict[str, list[dict]] = {}
for pid, entry in intel.items():
if pid.startswith("_") or pid in EXCLUDED_IDS:
continue
name = entry.get("display_name", pid)
missing = [s for s, data in siblings.items() if pid not in data]
if missing:
incomplete.append((pid, missing))
continue
brand = derive_manufacturer(pid, name)
# PUBLIC SURFACE — name + id only. NEVER add per-model engineering specs
# (build volume, temps, materials, ...) here: this JSON ships to the
# crawlable /printers page, and the curated catalog detail stays in Kiln Pro.
# Pinned by test_public_surface_exposes_only_name_not_specs.
by_brand.setdefault(brand, []).append(
{"id": pid, "name": name}
)
# Brands ordered by breadth (most models first), then alphabetically;
# models alphabetically. Fully deterministic so --check is stable.
brands = []
for brand in sorted(by_brand, key=lambda b: (-len(by_brand[b]), b)):
models = sorted(by_brand[brand], key=lambda m: m["name"])
brands.append(
{
"brand": brand,
"slug": brand.lower().replace(" ", "-"),
"model_count": len(models),
"models": models,
}
)
payload = {
"_comment": (
"AUTO-GENERATED by scripts/generate_supported_printers.py — DO NOT EDIT BY HAND. "
"Add a model to kiln/src/kiln/data/printer_intelligence.json (plus its safety, "
"slicer, and material-compatibility profiles) and rerun the generator."
),
"total_brands": len(brands),
"total_models": sum(b["model_count"] for b in brands),
"brands": brands,
}
return payload, incomplete
def render_readme_block(payload: dict) -> str:
"""One-line, auto-maintained breadth summary for the README, between markers.
The link carries the same source/medium tags the rest of the README's
outbound kiln3d.com links do (b157b96b). It lives here rather than in
the README because this block is regenerated: tagging the rendered
output by hand meant the next run of this script silently stripped the
attribution back off.
"""
brands = ", ".join(b["brand"] for b in payload["brands"])
return (
f"{RM_BEGIN}\n"
f"Kiln ships **tuned profiles for {payload['total_models']} models across "
f"{payload['total_brands']} brands** — {brands}. "
f"[See the full searchable list →]"
f"(https://kiln3d.com/printers?utm_source=github&utm_medium=readme)\n"
f"{RM_END}"
)
def render_pypi_block(payload: dict) -> str:
"""The same breadth fact for the PyPI project page, without the brand list.
Deliberately NOT the root README's rendering. That one names all fifteen
brands in model-count order, and kiln/README.md is a surface the printer
brand-order ledger governs: dropping a second, differently-ordered brand
list into it would put the file in disagreement with itself, which is the
exact defect that ledger exists to catch. The count and the link carry
the value; the roster already lives in the backend table above.
utm tagging matches the line this replaced (pypi / package-page) and lives
here rather than in the file, because a regenerated block strips anything
hand-added to it.
"""
return (
f"{RM_BEGIN}\n"
f"The full searchable list of **{payload['total_models']} tuned printer "
f"profiles across {payload['total_brands']} brands** is at "
f"[kiln3d.com/printers]"
f"(https://kiln3d.com/printers?utm_source=pypi&utm_medium=package-page).\n"
f"{RM_END}"
)
def sync_readme(block: str, path: Path = README, *, check: bool):
"""Replace the marked block in ``path``. Returns True if up to date, False
if stale (check mode), or None if the file has no markers (not wired)."""
import re
if not path.exists():
return None
text = path.read_text()
if RM_BEGIN not in text or RM_END not in text:
return None
new_text = re.sub(
re.escape(RM_BEGIN) + ".*?" + re.escape(RM_END),
lambda _m: block,
text,
flags=re.DOTALL,
)
if check:
return new_text == text
if new_text != text:
path.write_text(new_text)
return True
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--check",
action="store_true",
help="exit 1 if the committed surface is stale (CI/pre-commit drift gate)",
)
args = parser.parse_args()
payload, incomplete = build_surface()
for pid, missing in incomplete:
print(
f"warning: '{pid}' is in printer_intelligence.json but missing "
f"{', '.join(missing)} — not advertised until complete.",
file=sys.stderr,
)
# Both surfaces state the same breadth fact in their own voice. Adding
# one to the loop is the whole cost of keeping a new surface honest.
surfaces = [
(README, render_readme_block(payload)),
(PYPI_README, render_pypi_block(payload)),
]
tally = (
f"{payload['total_models']} models across {payload['total_brands']} brands"
)
if args.check:
stale = [
path for path, block in surfaces
if sync_readme(block, path, check=True) is False
]
if stale:
for path in stale:
print(
f"DRIFT: {path.relative_to(ROOT)} (printer block) stale. "
f"Run: python3 scripts/generate_supported_printers.py",
file=sys.stderr,
)
sys.exit(1)
print(f"OK: every README printer block matches the data ({tally}).")
return
for path, block in surfaces:
synced = sync_readme(block, path, check=False)
print(
(
f"Wrote {path.relative_to(ROOT)} printer block"
if synced is not None
else f"{path.relative_to(ROOT)} has no printer-block markers "
"— nothing written"
)
+ f": {tally}."
)
if __name__ == "__main__":
main()
005fd12ceThis file is pinned to the selected release. Download the original to open it in your design tool.