Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

fix(release): compute the Python the archive needs, stop listing it (#1298)

Vincenzo Fornaro74a5c8dd83ef
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 23bab690..d0e95ee2 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -141,13 +141,14 @@ jobs:
# without a model (#1241). coli.cmd is both the double-click entry
# point and what `coli chat ...` resolves to in cmd/PowerShell.
if [ "${{ matrix.ext }}" = ".exe" ]; then cp c/coli.cmd dist/; fi
- cp c/version.py dist/
- cp c/openai_server.py dist/
- cp c/v4_dsml.py dist/ # openai_server imports v4_dsml (vendored DeepSeek V4 DSML primitives); without it the packaged server won't import
- cp c/family_registry.py dist/ # authoritative model-family dispatch/capability registry
- cp c/resource_plan.py dist/
- cp c/doctor.py dist/
- cp c/autotune.py dist/
+ # I file Python non sono piu' elencati qui. Erano sette, scelti a mano,
+ # con i commenti che spiegavano quale importava quale: un inseguimento
+ # del codice fatto a occhio, e il codice era avanti. #1296: mancavano
+ # quattro script invocati da coli e tre moduli importati, fra cui
+ # qwen38_image, per cui mandare un'immagine al pacchetto pubblicato
+ # rispondeva "image support needs Pillow and numpy" mentre il file
+ # semplicemente non era stato spedito.
+ python3 c/tools/pack_python.py c dist
cp LICENSE dist/
# web/dist sits NEXT TO coli in the archive; both coli and openai_server.py
# probe that layout as well as the source checkout's one-level-up form.
@@ -188,6 +189,12 @@ jobs:
# Kimi K3 needs tokenizer.json synthesized from tiktoken.model; without this
# script in the archive the engine ships but cannot be driven by coli chat.
test -f tools/k3_tokenizer.py || { echo "FAIL: k3_tokenizer.py missing from archive"; exit 1; }
+ # E tutto cio' che coli raggiunge, import e sottoprocessi. Il controllo
+ # qui sopra guarda l'unico file che il passo di copia aveva appena
+ # scritto: conferma se stesso, ed e' il motivo per cui la v1.10.0 e'
+ # uscita verde con quattro comandi rotti dentro.
+ python3 ../c/tools/pack_python.py ../c . --check \
+ || { echo "FAIL: the archive is missing Python that coli needs"; exit 1; }
# encoding='utf-8' explicitly: on Windows open() defaults to the ANSI code
# page (cp1252), which cannot decode this UTF-8 file, so the v1.4.0 tag build
# failed here with a UnicodeDecodeError while the file itself was perfectly
diff --git a/c/tests/test_family_registry.py b/c/tests/test_family_registry.py
index c1784c37..bdd16975 100644
--- a/c/tests/test_family_registry.py
+++ b/c/tests/test_family_registry.py
@@ -1,5 +1,6 @@
import json
import re
+import sys
import tempfile
import unittest
from dataclasses import replace
@@ -1169,6 +1170,52 @@ class FamilyRegistryTest(unittest.TestCase):
f"({family.id}); a reader in that language cannot "
f"tell the family is supported")
+ def test_release_ships_everything_coli_reaches(self):
+ """L'archivio deve contenere ogni file Python che coli raggiunge.
+
+ #1296: il pacchetto v1.10.0 aveva quattro comandi rotti. release.yml
+ copiava sette .py scelti a mano piu' un solo file in tools/, e il
+ codice era andato avanti. Mancavano convert_fp8_to_int4.py,
+ eval_glm.py, fetch_benchmarks.py, mirror_plan.py, e i moduli cluster,
+ glm53_image, qwen38_image.
+
+ Ora la lista la calcola c/tools/pack_python.py. Questo test fissa i
+ due punti ciechi che avevano fatto passare il difetto, perche' sono i
+ due modi in cui un file sfugge a chi guarda a occhio:
+
+ - un import dentro una funzione, dopo un sys.path.insert. E' il caso
+ di qwen38_image in openai_server.py, e l'ImportError li' e'
+ catturato e riscritto come "image support needs Pillow and numpy":
+ nel pacchetto pubblicato mandare un'immagine dava la colpa
+ all'ambiente dell'utente per un file che non avevamo spedito.
+ - un sottoprocesso scritto con lo spazio dopo la virgola,
+ os.path.join(TOOLS, "mirror_plan.py"). La mia prima grep cercava
+ TOOLS," senza spazio e non lo vedeva: quattro invocazioni, non tre.
+ """
+ repo = Path(__file__).resolve().parents[2]
+ sys.path.insert(0, str(repo / "c" / "tools"))
+ try:
+ import pack_python
+ finally:
+ sys.path.pop(0)
+
+ reached = {path.name for path in pack_python.needed(repo / "c")}
+
+ # I sette file che mancavano davvero dall'archivio v1.10.0.
+ for name in ("convert_fp8_to_int4.py", "eval_glm.py",
+ "fetch_benchmarks.py", "mirror_plan.py",
+ "cluster.py", "glm53_image.py", "qwen38_image.py"):
+ self.assertIn(name, reached,
+ f"{name} mancava dall'archivio v1.10.0 e il calcolo "
+ f"non lo ritrova: #1296 si ripeterebbe")
+
+ release = (repo / ".github" / "workflows" / "release.yml").read_text(
+ encoding="utf-8")
+ self.assertIn("pack_python.py c dist", release,
+ "release.yml non calcola piu' i file da copiare")
+ self.assertIn("--check", release,
+ "release.yml non verifica piu' l'archivio estratto")
+
def test_the_python_job_builds_every_engine_a_test_skips_without(self):
"""Un test protetto da skipUnless(ENGINE.exists()) sparisce se il job
non compila quel motore, e sparisce in silenzio: la classe si salta,
@@ -1314,8 +1361,21 @@ class FamilyRegistryTest(unittest.TestCase):
else:
self.assertIn("deepseek-v4", ci)
self.assertIn("cp c/deepseek_v4", release)
- for text in (makefile, release, docker):
+ for text in (makefile, docker):
self.assertIn("family_registry.py", text)
+ # release.yml non nomina piu' i singoli .py: da #1296 la lista la
+ # calcola pack_python.py seguendo gli import a partire da coli. Il
+ # contratto qui e' sempre lo stesso -- family_registry.py deve finire
+ # nell'archivio -- ma va verificato alla fonte nuova, se no si
+ # controlla che esista una riga invece che il file venga spedito.
+ sys.path.insert(0, str(repo / "c" / "tools"))
+ try:
+ import pack_python
+ finally:
+ sys.path.pop(0)
+ shipped = {path.name for path in pack_python.needed(repo / "c")}
+ self.assertIn("family_registry.py", shipped,
+ "l'archivio non spedirebbe family_registry.py")
if __name__ == "__main__":
diff --git a/c/tools/pack_python.py b/c/tools/pack_python.py
new file mode 100644
index 00000000..018ddb3f
--- /dev/null
+++ b/c/tools/pack_python.py
@@ -0,0 +1,114 @@
+#!/usr/bin/env python3
+"""Quali file Python deve contenere un archivio di release, calcolati.
+
+#1296: `coli convert` nel pacchetto v1.10.0 moriva con "can't open file
+'tools/convert_fp8_to_int4.py'". Il workflow copiava una lista scritta a mano,
+e la lista era indietro rispetto al codice. Tre script invocati da coli e tre
+moduli importati non c'erano.
+
+Uno dei tre e' istruttivo: openai_server.py fa
+
+ _sys.path.insert(0, str(_Path(__file__).resolve().parent / "tools"))
+ from qwen38_image import preprocess
+
+dentro una funzione, e l'ImportError e' catturato e riscritto come "image
+support needs Pillow and numpy". Nel pacchetto pubblicato mandare un'immagine
+rispondeva quindi che mancavano delle dipendenze all'utente, mentre il file non
+era stato spedito. Un import cercato con una regex, o a occhio, non lo trova:
+per questo qui si usa ast.
+
+Due modi di raggiungere un file, ed entrambi contano:
+ - import, seguiti in chiusura a partire da coli
+ - subprocess, cioe' os.path.join(TOOLS, "qualcosa.py")
+
+Uso:
+ pack_python.py <c-dir> <dist-dir> copia
+ pack_python.py <c-dir> <dist-dir> --check verifica, esce 1 se manca
+"""
+import ast
+import pathlib
+import re
+import shutil
+import sys
+
+
+def local_modules(src):
+ """I nostri moduli per nome. Tutto il resto e' stdlib o terze parti."""
+ found = {p.stem: p for p in src.glob("*.py")}
+ for path in (src / "tools").glob("*.py"):
+ found.setdefault(path.stem, path)
+ return found
+
+
+def imports_of(path):
+ """I nomi importati da un file, comunque sia scritto l'import: dentro una
+ funzione, dopo un sys.path.insert, in un try. ast li vede tutti."""
+ try:
+ tree = ast.parse(path.read_text(encoding="utf-8", errors="ignore"))
+ except SyntaxError:
+ return set()
+ names = set()
+ for node in ast.walk(tree):
+ if isinstance(node, ast.Import):
+ names.update(alias.name.split(".")[0] for alias in node.names)
+ elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module:
+ names.add(node.module.split(".")[0])
+ return names
+
+
+def invoked_scripts(path):
+ """Gli script lanciati come processo, non importati: os.path.join(TOOLS, "x.py")."""
+ text = path.read_text(encoding="utf-8", errors="ignore")
+ return set(re.findall(r'TOOLS,\s*"([a-z0-9_]+\.py)"', text))
+
+
+def needed(src):
+ """Tutto cio' che coli raggiunge, come percorsi sotto <c-dir>."""
+ local = local_modules(src)
+ reached, queue = set(), [src / "coli"]
+ scripts = set()
+ while queue:
+ path = queue.pop()
+ scripts |= invoked_scripts(path)
+ for name in imports_of(path):
+ if name in local and name not in reached:
+ reached.add(name)
+ queue.append(local[name])
+ paths = {local[name] for name in reached}
+ for script in sorted(scripts):
+ candidate = src / "tools" / script
+ if not candidate.exists():
+ raise SystemExit(f"FAIL: coli invokes tools/{script}, which does not exist")
+ paths.add(candidate)
+ return sorted(paths)
+
+
+def main(argv):
+ if len(argv) < 3:
+ raise SystemExit(__doc__)
+ src, dist = pathlib.Path(argv[1]), pathlib.Path(argv[2])
+ check = "--check" in argv[3:]
+ missing = []
+ files = needed(src)
+ for path in files:
+ rel = pathlib.Path("tools") / path.name if path.parent.name == "tools" \
+ else pathlib.Path(path.name)
+ dest = dist / rel
+ if check:
+ if not dest.exists():
+ missing.append(str(rel))
+ continue
+ dest.parent.mkdir(parents=True, exist_ok=True)
+ shutil.copy2(path, dest)
+ if missing:
+ print("FAIL: coli reaches these and they are not in the archive:")
+ for name in missing:
+ print(f" {name}")
+ return 1
+ print(f"{len(files)} Python files reachable from coli "
+ f"({'all present' if check else 'copied'})")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main(sys.argv))