Files
NexusOS/hatch_build.py
Athena KaminskyandClaude Opus 5 9104c724c4 feat(packaging): move the CLI into nexusos_cli and make the wheel self-sufficient
The CLI shipped from `management/`, which also holds desktop-only pieces (the
Tk control panel, the XFCE panel wiring, the shell wrappers). Packaging that
directory meant the wheel either dragged in tkinter or shipped a broken import.
Split it: `nexusos_cli/` is what the wheel ships and what `nexus`/`ncp`/
`nexusos` dispatch to, `management/` keeps the desktop half.

Alongside the move:

* hatch_build.py decides the interface/web/dist include at build time. dist/
  is gitignored, so a static force-include aborts `pip install -e .` on a
  fresh clone - before the reader reaches the `npm run build` step. Editable
  installs now skip a missing dist; wheels and sdists hard-error naming the
  command to run.
* synapse/proc_util.py gives frontend_manager and ncp process inspection and
  termination without psutil, which became an optional extra when the wheel
  landed. It routes around Windows having no signals, where os.kill(pid, 15)
  is an unblockable TerminateProcess rather than a polite request.
* nexusos_cli/monitor.py adds `ncp monitor`, an ASCII dashboard with no curses
  or rich dependency so it works in Termux, plain SSH and Windows Terminal.
  Collector and renderer are separate so tests feed fixtures, no stack needed.
* tests/test_packaging_deps.py fails the gate when synapse or nexusos_cli
  import a distribution pyproject does not declare, and when an optional
  dependency is imported at module scope instead of lazily.
* bin/check.sh now builds the wheel, twine-checks it, and asserts the compiled
  UI and seed playbooks are actually inside it. A wheel that builds but ships
  no dist/ serves a blank page, which only shows up after release.

tests/test_nexus_api.py moves to tests/ with the module it covers.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 08:11:39 -05:00

56 lines
2.0 KiB
Python

"""Build hook that ships the compiled web UI without breaking `pip install -e .`.
interface/web/dist is gitignored - it is a Vite build artifact, not source - so
a fresh clone does not have it. A static force-include of a missing path aborts
the build, which would make the README's first step ("pip install -e .") fail
before the reader ever gets to `npm run build`.
So the include is decided here instead:
* editable install -> skip a missing dist, the UI just isn't served yet
* wheel / sdist -> hard error naming the exact command to run
Set NEXUS_ALLOW_UILESS_BUILD=1 to build a deliberately headless distribution
(API and CLI only).
"""
from __future__ import annotations
import os
from pathlib import Path
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
_UI_SOURCE = Path("interface") / "web" / "dist"
_UI_TARGETS = {
"wheel": "synapse/_resources/web",
"sdist": "interface/web/dist",
}
class NexusBuildHook(BuildHookInterface):
PLUGIN_NAME = "custom"
def initialize(self, version: str, build_data: dict) -> None:
target = _UI_TARGETS.get(self.target_name)
if target is None:
return
source = Path(self.root) / _UI_SOURCE
if (source / "index.html").is_file():
build_data.setdefault("force_include", {})[str(source)] = target
return
if version == "editable" or os.getenv("NEXUS_ALLOW_UILESS_BUILD") == "1":
self.app.display_warning(
f"No compiled web UI at {_UI_SOURCE} - the backend will serve the "
"API only. Build it with: cd interface/web && npm ci && npm run build"
)
return
raise RuntimeError(
f"Cannot build a {self.target_name}: the compiled web UI is missing from "
f"{_UI_SOURCE}.\n"
"Build it first:\n"
" cd interface/web && npm ci && npm run build\n"
"Or set NEXUS_ALLOW_UILESS_BUILD=1 to ship an API/CLI-only distribution."
)