Build TUI, web, desktop UI and runnable agent products from explicit prepared inputs. Keep dependency preparation separate from distribution packaging, with PM and native builds sharing uv environment construction. Docker copies compiled frontend products instead of build dependencies. Nix retains uv2nix environments and consumes shared assembly through store references. Native desktop and Termux use the same launcher and frontend contracts. Preserve the independent PM runtime and source imports from arbitrary working directories. Keep failed frontend builds from replacing the previous product, reject source/output overlap, and bound dependency-process output draining. Include hermes_wisdom in the Nix wheel: real CLI smoke tests exposed its missing package declaration on the base revision too. Verified focused Python and JavaScript suites, Docker build/runtime checks, Nix desktop and CLI/ACP checks, standalone TUI and packaged Electron PTY, and real full-Chromium interaction. Native signed installers, Android device installation and the full repository suite remain CI verification.
77 lines
3.1 KiB
Python
77 lines
3.1 KiB
Python
"""Native/Docker dependency preparation over PM's explicit uv mechanics.
|
|
|
|
Unlike live PM, a build never discovers plugins or publishes a selection.
|
|
The source is the prepared application tree; editable installs keep pointing
|
|
at that tree. Nix and Termux retain their own dependency providers.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
from collections.abc import Mapping, Sequence
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
|
|
from pm.environment import PythonEnvironment
|
|
from pm.package import InstallError
|
|
|
|
|
|
def build_python_environment(
|
|
*, source: Path, python: Path, uv: Path, out: Path,
|
|
env: Mapping[str, str], cache: Path | None = None,
|
|
extras: Sequence[str] = (), all_extras: bool = False,
|
|
no_install_project: bool = False, offline: bool = False,
|
|
) -> Path:
|
|
"""Build a fresh environment and return its Python executable after validation.
|
|
|
|
``out`` must not exist. Failure removes only this invocation's destination;
|
|
a pre-existing environment is never deleted or used as a successful result.
|
|
The cache (default: ``out.parent / ".uv-cache"``) remains available to the
|
|
native offline-cache packager. ``no_install_project`` prepares only the
|
|
locked dependencies, before an application source layer is available.
|
|
"""
|
|
source, out = source.absolute(), out.absolute()
|
|
cache = out.parent / ".uv-cache" if cache is None else cache.absolute()
|
|
environment = PythonEnvironment(
|
|
uv=uv.absolute(), python=python.absolute(), destination=out,
|
|
cache=cache.absolute(), env=env, offline=offline, output=sys.stderr,
|
|
)
|
|
out.mkdir(parents=True)
|
|
try:
|
|
environment.create()
|
|
environment.sync(source, extras=extras, all_extras=all_extras,
|
|
no_install_project=no_install_project)
|
|
environment.check()
|
|
except BaseException:
|
|
shutil.rmtree(out, ignore_errors=True)
|
|
raise
|
|
return environment.executable
|
|
|
|
|
|
def main(argv: Sequence[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--source", required=True, type=Path)
|
|
parser.add_argument("--python", required=True, type=Path)
|
|
parser.add_argument("--uv", required=True, type=Path)
|
|
parser.add_argument("--out", required=True, type=Path)
|
|
parser.add_argument("--cache", type=Path, help="uv cache; defaults to OUT's sibling .uv-cache")
|
|
selection = parser.add_mutually_exclusive_group()
|
|
selection.add_argument("--extra", dest="extras", action="append", default=[])
|
|
selection.add_argument("--all-extras", action="store_true")
|
|
parser.add_argument("--no-install-project", action="store_true")
|
|
parser.add_argument("--offline", action="store_true")
|
|
args = parser.parse_args(argv)
|
|
try:
|
|
executable = build_python_environment(**vars(args), env=dict(os.environ))
|
|
except (InstallError, OSError, ValueError, subprocess.TimeoutExpired) as exc:
|
|
print(f"python environment: {exc}", file=sys.stderr)
|
|
return 1
|
|
print(executable)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|