feat(sdk): bundle shared Office authoring resources
This commit is contained in:
1 parent
1e3afc63ad
commit
37983d9298
28 files changed
+367
-58
No files matched your search
@@ -28,6 +28,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from ._resources import validate_resources
|
||||
|
||||
PACKAGE_METADATA_FILENAME = "deepseek-harness-runtime.json"
|
||||
|
||||
@@ -59,7 +60,9 @@ def bundled_runtime_path() -> Path:
|
||||
|
||||
Raises FileNotFoundError when the platform is unsupported, the executable
|
||||
has not been placed into this package, the ripgrep or Office sidecar is
|
||||
missing, or the required macOS spawn helper is missing; the message names
|
||||
missing, the authoring resources are incomplete, or the required macOS
|
||||
spawn helper is missing. Invalid authoring metadata or Python permissions
|
||||
raise ValueError. Missing executable/Office messages name
|
||||
the acquisition routes (acquisition strategy is deliberately separate from
|
||||
this lookup interface, so an on-demand download can replace it without
|
||||
touching callers).
|
||||
@@ -104,6 +107,7 @@ def bundled_runtime_path() -> Path:
|
||||
f"deepseek-harness-runtime-bin is missing the Office sidecar engine {engine} at {office}. "
|
||||
+ _EXE_ACQUISITION_HINT
|
||||
)
|
||||
validate_resources(path.with_name(f"{path.name.removesuffix('.exe')}-resources"), tag)
|
||||
return path
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
"""Validate the authoring resources in staged, installed, or archived runtime wheels."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import stat
|
||||
import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def validate_resources(root: Path | zipfile.Path, target: str) -> None:
|
||||
"""Reject a missing or wrong-target Python environment or bundled Office skill tree."""
|
||||
manifest_path = root / "primary-runtime/runtime.json"
|
||||
if not manifest_path.is_file():
|
||||
raise FileNotFoundError(f"runtime authoring resources are missing: {manifest_path}")
|
||||
manifest = json.loads(manifest_path.read_text(encoding="utf-8"))
|
||||
platform, arch = target.rsplit("-", 1)
|
||||
platform = {"macos": "darwin", "win": "win32"}.get(platform, platform)
|
||||
if not isinstance(manifest, dict) or (manifest.get("platform"), manifest.get("arch")) != (platform, arch):
|
||||
raise ValueError(f"runtime authoring resources do not match target {target}")
|
||||
version = manifest.get("python")
|
||||
if not isinstance(version, str) or not re.fullmatch(r"\d+\.\d+\.\d+", version):
|
||||
raise ValueError("runtime authoring resources have invalid Python version metadata")
|
||||
if not isinstance(manifest.get("pythonPackages"), dict) or not manifest["pythonPackages"]:
|
||||
raise ValueError("runtime authoring resources have no Python distributions")
|
||||
python_root = root / "primary-runtime/dependencies/python"
|
||||
executable = python_root / ("python.exe" if platform == "win32" else "bin/python3")
|
||||
packages = python_root / ("Lib/site-packages" if platform == "win32" else f"lib/python{version.rsplit('.', 1)[0]}/site-packages")
|
||||
required = [executable, root / "office-skills/scripts/check_office.py"]
|
||||
required.extend(root / f"office-skills/office-{kind}/SKILL.md" for kind in ("docx", "pptx", "xlsx"))
|
||||
for path in required:
|
||||
if not path.is_file():
|
||||
raise FileNotFoundError(f"runtime authoring resource is missing: {path}")
|
||||
if not packages.is_dir():
|
||||
raise FileNotFoundError(f"runtime Python site-packages is missing: {packages}")
|
||||
if platform != "win32":
|
||||
mode = (executable.root.getinfo(executable.at).external_attr >> 16
|
||||
if isinstance(executable, zipfile.Path) else executable.stat().st_mode)
|
||||
if mode & stat.S_IXUSR == 0:
|
||||
raise ValueError(f"runtime Python lost its executable bit: {executable}")
|
||||
Reference in new issue
Block a user