@simplexai/localmodels-darwin-arm64 0.1.0-dev.32.build.git9f03dd7a81cec1338df8eaf613ec9e3013365c9c → 0.1.0-dev.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bootstrap.identity +1 -1
- package/bootstrap.sha256 +141 -99
- package/modules/localmodels/__init__.py +1 -1
- package/modules/localmodels/__main__.py +4 -0
- package/modules/localmodels/app.py +7 -2
- package/modules/localmodels/approval.py +4 -4
- package/modules/localmodels/bifrost_checks.py +121 -3
- package/modules/localmodels/bifrost_provider.py +53 -0
- package/modules/localmodels/bifrost_unit.py +32 -1
- package/modules/localmodels/budget.py +7 -1
- package/modules/localmodels/catalog.json +286 -12
- package/modules/localmodels/catalog.py +30 -29
- package/modules/localmodels/catalog_add.py +1 -0
- package/modules/localmodels/cli_parser.py +10 -2
- package/modules/localmodels/component.py +7 -1
- package/modules/localmodels/decode_calibration.json +6 -0
- package/modules/localmodels/decode_calibration.py +104 -0
- package/modules/localmodels/deploy.py +44 -7
- package/modules/localmodels/deploy_steps.py +10 -1
- package/modules/localmodels/engines-strata-0.1.49.2.json +31 -0
- package/modules/localmodels/engines-strata-0.1.59.1.json +31 -0
- package/modules/localmodels/engines.json +57 -1
- package/modules/localmodels/engines.py +6 -2
- package/modules/localmodels/estimator.py +21 -7
- package/modules/localmodels/frontend.py +4 -4
- package/modules/localmodels/gateway.py +14 -4
- package/modules/localmodels/gateway_app_bifrost.py +4 -3
- package/modules/localmodels/gateway_bifrost.py +70 -57
- package/modules/localmodels/gateway_probe.py +3 -4
- package/modules/localmodels/gguf.py +7 -0
- package/modules/localmodels/harness.py +24 -25
- package/modules/localmodels/harness_gateway.py +19 -10
- package/modules/localmodels/harness_probe.py +33 -6
- package/modules/localmodels/hosts.py +73 -9
- package/modules/localmodels/install.py +36 -6
- package/modules/localmodels/library_cli.py +179 -0
- package/modules/localmodels/library_convert.py +132 -0
- package/modules/localmodels/library_gateway.py +471 -0
- package/modules/localmodels/library_jobs.py +314 -0
- package/modules/localmodels/library_model.py +246 -0
- package/modules/localmodels/library_pricing.py +347 -0
- package/modules/localmodels/library_serve.py +348 -0
- package/modules/localmodels/library_state.py +373 -0
- package/modules/localmodels/library_status.py +349 -0
- package/modules/localmodels/llm_rank.py +77 -8
- package/modules/localmodels/memcalc.py +7 -30
- package/modules/localmodels/metal.py +26 -0
- package/modules/localmodels/metal_probe.py +11 -7
- package/modules/localmodels/plan_envelope.py +4 -1
- package/modules/localmodels/preparation.py +49 -0
- package/modules/localmodels/probe.py +8 -8
- package/modules/localmodels/process_identity.py +536 -9
- package/modules/localmodels/quant_formats.py +123 -0
- package/modules/localmodels/recommend.py +32 -3
- package/modules/localmodels/recommend_cli.py +8 -4
- package/modules/localmodels/records.py +1 -0
- package/modules/localmodels/remote_ops.py +104 -6
- package/modules/localmodels/remote_ops_download.py +17 -2
- package/modules/localmodels/remote_ops_prepare.py +425 -0
- package/modules/localmodels/remote_ops_remove.py +40 -7
- package/modules/localmodels/remote_ops_service.py +110 -8
- package/modules/localmodels/remote_ops_verify.py +15 -2
- package/modules/localmodels/runtime_auth.py +31 -1
- package/modules/localmodels/runtime_cli.py +3 -4
- package/modules/localmodels/runtime_io.py +50 -6
- package/modules/localmodels/service_autostart.py +45 -1
- package/modules/localmodels/service_control.py +13 -0
- package/modules/localmodels/service_deployment.py +12 -3
- package/modules/localmodels/service_jobs.py +33 -4
- package/modules/localmodels/service_probe.py +67 -13
- package/modules/localmodels/service_stop.py +152 -0
- package/modules/localmodels/service_worker.py +9 -1
- package/modules/localmodels/services_cli.py +50 -6
- package/modules/localmodels/setup_inspection.py +34 -25
- package/modules/localmodels/setup_text.py +118 -0
- package/modules/localmodels/sizecalc.py +625 -0
- package/modules/localmodels/sizecalc_cli.py +249 -0
- package/modules/localmodels/stack.py +69 -17
- package/modules/localmodels/stack_args.py +91 -19
- package/modules/localmodels/stack_auto.py +78 -0
- package/modules/localmodels/stack_binding.py +23 -35
- package/modules/localmodels/stack_card.py +195 -0
- package/modules/localmodels/stack_cleanup.py +379 -0
- package/modules/localmodels/stack_clients.py +4 -1
- package/modules/localmodels/stack_compose.py +173 -206
- package/modules/localmodels/stack_console.py +2 -0
- package/modules/localmodels/stack_decision.py +3 -2
- package/modules/localmodels/stack_down.py +189 -0
- package/modules/localmodels/stack_events.py +54 -0
- package/modules/localmodels/stack_hardware.py +30 -34
- package/modules/localmodels/stack_journal.py +29 -8
- package/modules/localmodels/stack_ledger.py +411 -0
- package/modules/localmodels/stack_lifecycle.py +162 -167
- package/modules/localmodels/stack_llm_ram.py +57 -5
- package/modules/localmodels/stack_memory.py +721 -0
- package/modules/localmodels/stack_picks.py +147 -0
- package/modules/localmodels/stack_plan.py +143 -25
- package/modules/localmodels/stack_ports.py +22 -0
- package/modules/localmodels/stack_preflight.py +699 -0
- package/modules/localmodels/stack_review.py +123 -5
- package/modules/localmodels/stack_rollback.py +2 -0
- package/modules/localmodels/stack_route.py +256 -0
- package/modules/localmodels/stack_run.py +11 -0
- package/modules/localmodels/stack_suite.py +107 -20
- package/modules/localmodels/stack_summary.py +65 -4
- package/modules/localmodels/stack_try.py +354 -0
- package/modules/localmodels/stack_try_client.py +194 -0
- package/modules/localmodels/stack_try_docs.py +139 -0
- package/modules/localmodels/stack_up.py +8 -1
- package/modules/localmodels/stack_update.py +29 -4
- package/modules/localmodels/stack_verify.py +3 -1
- package/modules/localmodels/stack_view.py +10 -11
- package/modules/localmodels/stack_view_apply.py +4 -2
- package/modules/localmodels/stack_view_events.py +2 -1
- package/modules/localmodels/stack_view_serve.py +3 -0
- package/modules/localmodels/stack_view_text.py +1 -1
- package/modules/localmodels/stack_view_words.py +4 -1
- package/modules/localmodels/stack_warm.py +574 -0
- package/modules/localmodels/stack_whatif.py +558 -0
- package/modules/localmodels/suite.py +48 -39
- package/modules/localmodels/tool_archive.py +40 -0
- package/modules/localmodels/tools.json +8 -0
- package/modules/localmodels/transport.py +1 -0
- package/modules/localmodels/vision.py +8 -1
- package/modules/localmodels/web/sizecalc/app.js +431 -0
- package/modules/localmodels/web/sizecalc/calc.js +269 -0
- package/modules/localmodels/web/sizecalc/page.html +362 -0
- package/modules/localmodels/web/view/ASSET-SOURCES.md +11 -0
- package/modules/localmodels/web/view/i18n.js +1 -1
- package/modules/localmodels/web/view/logo-claude.svg +3 -0
- package/modules/localmodels/web/view/logo-codex.png +0 -0
- package/modules/localmodels/web/view/logo-pi.svg +6 -0
- package/modules/localmodels/web/view/view.css +4 -0
- package/modules/localmodels/web/view/view.js +15 -6
- package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/METADATA +1 -1
- package/modules/simplex_localmodels-0.1.0.dev36.dist-info/RECORD +242 -0
- package/package.json +1 -1
- package/tool.json +1 -1
- package/modules/simplex_localmodels-0.1.0.dev32.dist-info/RECORD +0 -200
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/WHEEL +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/entry_points.txt +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/licenses/NOTICE +0 -0
- /package/modules/{simplex_localmodels-0.1.0.dev32.dist-info → simplex_localmodels-0.1.0.dev36.dist-info}/licenses/localmodels/HERMES-LICENSE +0 -0
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
"""What ``stack remove`` clears once the services and tools are gone, and ``stack prune``.
|
|
2
|
+
|
|
3
|
+
An uninstall leaves nothing behind but what was downloaded and verified (the model files and
|
|
4
|
+
the tool and engine archives, so the next install needs no download), the owned manifest that
|
|
5
|
+
lists them (so ``--purge`` can delete them later) and the manifest's empty lock file. stack_lifecycle.remove stops and removes the
|
|
6
|
+
services, the gateway and the tools; ``sweep`` then deletes what only the stack used: the
|
|
7
|
+
engines its deployments ran that no remaining record names (with their download archives), the
|
|
8
|
+
saved stack plans with their run records, the cached host facts, and the tool's own directories
|
|
9
|
+
left empty. A deployment made outside ``stack`` keeps its record and the engine it runs, and an
|
|
10
|
+
engine no record ever named is left for ``prune``, which lists every unreferenced engine
|
|
11
|
+
directory and deletes them under ``--yes``.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import os
|
|
18
|
+
import shutil
|
|
19
|
+
import sys
|
|
20
|
+
from collections.abc import Callable, Iterable, Iterator
|
|
21
|
+
from pathlib import Path
|
|
22
|
+
|
|
23
|
+
from localmodels import deploy, hosts
|
|
24
|
+
from localmodels.budget import gib
|
|
25
|
+
from localmodels.stack_plan import StackError, platform_error
|
|
26
|
+
|
|
27
|
+
Out = Callable[[str], None]
|
|
28
|
+
# State this tool writes for a stack and nothing else reads: saved plans, run records, the
|
|
29
|
+
# apply lock and journal (stacks/), the cached probe (facts/) and the view window's profile.
|
|
30
|
+
STACK_STATE = ("stacks", "facts", "view-app")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Engines = dict[Path, set[str]] # engine directory -> the archive names it was unpacked from
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _engines(doc: object) -> Iterator[tuple[Path, set[str]]]:
|
|
37
|
+
"""Every engine section anywhere in a saved plan, run or deployment record: its directory
|
|
38
|
+
(plans write ``~/...``, so the path is expanded) and the names of its download archives."""
|
|
39
|
+
if isinstance(doc, dict):
|
|
40
|
+
binary = doc.get("binary")
|
|
41
|
+
if isinstance(binary, str):
|
|
42
|
+
folder = Path(os.path.expanduser(binary)).parent
|
|
43
|
+
if folder.parent.name == "engines":
|
|
44
|
+
assets = doc.get("assets")
|
|
45
|
+
names = {
|
|
46
|
+
str(a["name"])
|
|
47
|
+
for a in (assets if isinstance(assets, list) else [])
|
|
48
|
+
if isinstance(a, dict) and "name" in a
|
|
49
|
+
}
|
|
50
|
+
yield folder, names
|
|
51
|
+
for value in doc.values():
|
|
52
|
+
yield from _engines(value)
|
|
53
|
+
elif isinstance(doc, list):
|
|
54
|
+
for item in doc:
|
|
55
|
+
yield from _engines(item)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def engines_in_use(skip: Iterable[str] = (), *, stacks: bool = True) -> Engines:
|
|
59
|
+
"""The engines something here still names: each deployment record but those of ``skip``,
|
|
60
|
+
and with ``stacks`` every saved stack plan and its run record. An uninstall reads it once
|
|
61
|
+
before it removes anything and again for what remains (``skip`` the deployments it takes,
|
|
62
|
+
``stacks`` False when the saved plans go too)."""
|
|
63
|
+
gone = set(skip)
|
|
64
|
+
docs: list[object] = [r for r in hosts.records(hosts.LOCAL_ID) if r["plan"]["name"] not in gone]
|
|
65
|
+
if stacks:
|
|
66
|
+
for plan_path in hosts.stack_plans():
|
|
67
|
+
try:
|
|
68
|
+
docs.append(json.loads(plan_path.read_text(encoding="utf-8")))
|
|
69
|
+
except (OSError, json.JSONDecodeError):
|
|
70
|
+
continue
|
|
71
|
+
for run, plan in hosts.stack_runs():
|
|
72
|
+
docs += [run, plan]
|
|
73
|
+
found: Engines = {}
|
|
74
|
+
for doc in docs:
|
|
75
|
+
for folder, names in _engines(doc):
|
|
76
|
+
found.setdefault(folder, set()).update(names)
|
|
77
|
+
return found
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _same(paths: Iterable[Path]) -> set[Path]:
|
|
81
|
+
return {path.resolve() for path in paths}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _stray_engines() -> list[Path]:
|
|
85
|
+
"""Engine directories no plan, run or record names, under every engines root one of them
|
|
86
|
+
uses and under the default base directory's."""
|
|
87
|
+
used = engines_in_use()
|
|
88
|
+
roots = {Path(deploy.DEFAULT_BASE_DIR).expanduser() / "engines"} | {d.parent for d in used}
|
|
89
|
+
named = _same(used)
|
|
90
|
+
return sorted(
|
|
91
|
+
child
|
|
92
|
+
for root in roots
|
|
93
|
+
if root.is_dir()
|
|
94
|
+
for child in root.iterdir()
|
|
95
|
+
if child.is_dir() and child.name != ".archives" and child.resolve() not in named
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def prune(yes: bool, out: Out = print) -> int:
|
|
100
|
+
"""Engine directories nothing references: list them, delete them only under ``--yes``."""
|
|
101
|
+
if sys.platform != "darwin" and (error := platform_error(sys.platform)):
|
|
102
|
+
raise StackError(error)
|
|
103
|
+
stray = _stray_engines()
|
|
104
|
+
if not stray:
|
|
105
|
+
out("No unreferenced engine directories")
|
|
106
|
+
return 0
|
|
107
|
+
out("These engine directories are not referenced by any stack plan, run or deployment record:")
|
|
108
|
+
for d in stray:
|
|
109
|
+
out(f" {d}")
|
|
110
|
+
if not yes:
|
|
111
|
+
out("To delete them, run stack prune --yes")
|
|
112
|
+
return 0
|
|
113
|
+
for d in stray:
|
|
114
|
+
shutil.rmtree(d)
|
|
115
|
+
out(f"Deleted {d}")
|
|
116
|
+
return 0
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _size(path: Path) -> int:
|
|
120
|
+
if path.is_dir() and not path.is_symlink():
|
|
121
|
+
return sum(p.lstat().st_size for p in path.rglob("*") if p.is_symlink() or p.is_file())
|
|
122
|
+
return path.lstat().st_size if os.path.lexists(path) else 0
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def state_paths() -> list[Path]:
|
|
126
|
+
"""The stack's own entries in the state directory that exist now."""
|
|
127
|
+
return [p for name in STACK_STATE if (p := hosts.state_dir() / name).exists()]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# The directories this tool makes under a base directory; an uninstall removes the empty ones.
|
|
131
|
+
OWN_DIRS = ("deployments", "frontends", "engines", "tools", "models", "bifrost")
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def _drop_empty_dirs(root: Path) -> None:
|
|
135
|
+
"""Remove ``root``'s empty directories, deepest first, and ``root`` itself when nothing is
|
|
136
|
+
left in it. Files are never touched."""
|
|
137
|
+
if not root.is_dir() or root.is_symlink():
|
|
138
|
+
return
|
|
139
|
+
for folder, _, _ in os.walk(root, topdown=False):
|
|
140
|
+
if not os.listdir(folder):
|
|
141
|
+
os.rmdir(folder)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def orphaned(
|
|
145
|
+
before: Engines, taken: Iterable[str], state: bool, *, downloads: bool = False
|
|
146
|
+
) -> list[Path]:
|
|
147
|
+
"""What an uninstall of the deployments ``taken`` leaves without a user: each engine
|
|
148
|
+
directory ``before`` names that nothing remaining names and, with ``downloads`` (a purge),
|
|
149
|
+
the archives only those engines were unpacked from. Without it the archives stay beside the
|
|
150
|
+
model files, so the next install unpacks them instead of downloading. An engine no record
|
|
151
|
+
ever named (unpacked by hand, or left by an older build) is not this uninstall's:
|
|
152
|
+
``stack prune`` lists those."""
|
|
153
|
+
still = engines_in_use(taken, stacks=not state)
|
|
154
|
+
named, wanted = _same(still), {name for names in still.values() for name in names}
|
|
155
|
+
dirs = sorted(d for d in before if d.is_dir() and d.resolve() not in named)
|
|
156
|
+
if not downloads:
|
|
157
|
+
return dirs
|
|
158
|
+
archives = sorted(
|
|
159
|
+
{
|
|
160
|
+
d.parent / ".archives" / (name + suffix)
|
|
161
|
+
for d in dirs
|
|
162
|
+
for name in before[d] - wanted
|
|
163
|
+
for suffix in ("", ".sha256")
|
|
164
|
+
}
|
|
165
|
+
)
|
|
166
|
+
return dirs + [path for path in archives if os.path.lexists(path)]
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def sweep(
|
|
170
|
+
before: Engines,
|
|
171
|
+
taken: Iterable[str],
|
|
172
|
+
*,
|
|
173
|
+
state: bool,
|
|
174
|
+
downloads: bool = False,
|
|
175
|
+
dry_run: bool = False,
|
|
176
|
+
) -> tuple[list[str], int]:
|
|
177
|
+
"""Delete the engines the uninstall orphaned (``orphaned``; their archives too with
|
|
178
|
+
``downloads``) and the stack's state when ``state`` (no deployment is left to read it).
|
|
179
|
+
Returns what went, one line each, and the bytes freed; ``dry_run`` only reports."""
|
|
180
|
+
doomed = orphaned(before, taken, state, downloads=downloads)
|
|
181
|
+
doomed += state_paths() if state else []
|
|
182
|
+
lines = [f"{path} ({gib(_size(path))})" for path in doomed]
|
|
183
|
+
freed = sum(_size(path) for path in doomed)
|
|
184
|
+
if dry_run:
|
|
185
|
+
return lines, freed
|
|
186
|
+
for path in doomed:
|
|
187
|
+
if path.is_dir() and not path.is_symlink():
|
|
188
|
+
shutil.rmtree(path)
|
|
189
|
+
else:
|
|
190
|
+
path.unlink(missing_ok=True)
|
|
191
|
+
if state:
|
|
192
|
+
_drop_empty_dirs(hosts.state_dir())
|
|
193
|
+
return lines, freed
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def tidy(base_dirs: Iterable[Path], tools_dir: str | Path = hosts.TOOLS_DIR) -> None:
|
|
197
|
+
"""The last step of an uninstall. Once nothing is owned, the private client configuration
|
|
198
|
+
this tool keeps in the tools directory goes too (another user's files stay where they are),
|
|
199
|
+
then the tool's own directories (OWN_DIRS) left empty and each base directory left empty.
|
|
200
|
+
A directory someone else made there stays, empty or not. The manifest's empty
|
|
201
|
+
``owned.lock`` stays: unlinking a lock file lets two writers each hold a "lock" (WHI-317,
|
|
202
|
+
.agents/skills/owned-manifest-lock), so it is the one file an uninstall leaves."""
|
|
203
|
+
root = Path(tools_dir).expanduser()
|
|
204
|
+
private = root / "gateway-home"
|
|
205
|
+
if not hosts.owned_path(tools_dir).exists() and private.is_dir():
|
|
206
|
+
# Windows has no uid: the directory sits in this user's profile under a private ACL.
|
|
207
|
+
uid = os.getuid() if hasattr(os, "getuid") else None
|
|
208
|
+
if uid is None or all(p.lstat().st_uid == uid for p in private.rglob("*")):
|
|
209
|
+
shutil.rmtree(private)
|
|
210
|
+
_drop_empty_dirs(root)
|
|
211
|
+
for base in base_dirs:
|
|
212
|
+
for name in OWN_DIRS:
|
|
213
|
+
_drop_empty_dirs(base / name)
|
|
214
|
+
if base.is_dir() and not base.is_symlink() and not any(base.iterdir()):
|
|
215
|
+
base.rmdir()
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def finish(
|
|
219
|
+
before: Engines,
|
|
220
|
+
taken: set[str],
|
|
221
|
+
bases: set[Path],
|
|
222
|
+
last: bool,
|
|
223
|
+
dry_run: bool,
|
|
224
|
+
out: Out,
|
|
225
|
+
quiet: bool = False,
|
|
226
|
+
downloads: bool = False,
|
|
227
|
+
) -> int:
|
|
228
|
+
"""Clear what no service or tool is left to use: orphaned engines, the stack's saved state
|
|
229
|
+
when ``last`` (no other deployment reads it), emptied directories and, when nothing is
|
|
230
|
+
owned, the manifest's own directory. Says so when there was nothing, unless ``quiet``."""
|
|
231
|
+
swept = sweep(before, taken, state=last, downloads=downloads, dry_run=dry_run)
|
|
232
|
+
for line in swept[0]:
|
|
233
|
+
out(f"{'would delete' if dry_run else '✓ deleted'} {line}")
|
|
234
|
+
if not dry_run:
|
|
235
|
+
tidy(bases)
|
|
236
|
+
if not swept[0] and not quiet:
|
|
237
|
+
out("This tool owns no resources on this computer; nothing to remove.")
|
|
238
|
+
return 0
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def _same_place(a: str, b: str) -> bool:
|
|
242
|
+
def norm(p: str) -> str:
|
|
243
|
+
return os.path.normcase(os.path.normpath(os.path.expanduser(p)))
|
|
244
|
+
|
|
245
|
+
return norm(a) == norm(b)
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def adopted(members: set[str], dry_run: bool, out: Out) -> hosts.Owned:
|
|
249
|
+
"""The manifest as an uninstall reads it. Each of the stack's deployments is taken from its
|
|
250
|
+
own record in this state directory: one the manifest does not list yet is added, and one
|
|
251
|
+
the manifest lists at ANOTHER directory is corrected. Deployment names repeat across
|
|
252
|
+
installations that share a tools directory (another stack, the Simplex installer's, a test
|
|
253
|
+
run), and the manifest keeps one entry per name: on home-win a stale entry named a
|
|
254
|
+
temporary directory, so the uninstall "removed" that and dropped the record of the search
|
|
255
|
+
server that was running (2026-11-12). The other directory is left alone. ``dry_run`` keeps
|
|
256
|
+
the correction in memory."""
|
|
257
|
+
doc = hosts.load_owned()
|
|
258
|
+
for record in hosts.records(hosts.LOCAL_ID):
|
|
259
|
+
plan = record["plan"]
|
|
260
|
+
name, entry = plan["name"], doc["deployments"].get(plan["name"])
|
|
261
|
+
if name not in members:
|
|
262
|
+
continue
|
|
263
|
+
if entry is not None and _same_place(entry["deploy_dir"], plan["service"]["deploy_dir"]):
|
|
264
|
+
continue
|
|
265
|
+
if entry is not None:
|
|
266
|
+
out(
|
|
267
|
+
f"- {name}: the manifest named another directory ({entry['deploy_dir']}); this "
|
|
268
|
+
"installation's record decides where it lives, and that directory is left alone"
|
|
269
|
+
)
|
|
270
|
+
if dry_run:
|
|
271
|
+
doc["deployments"][name] = hosts.owned_entry(plan)
|
|
272
|
+
else:
|
|
273
|
+
hosts.own_deployment(plan)
|
|
274
|
+
doc = hosts.load_owned()
|
|
275
|
+
return doc
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def without_others_archives(doc: hosts.Owned, taken: set[str], out: Out) -> hosts.Owned:
|
|
279
|
+
"""``doc`` without the owned archives that sit under the base directory of a deployment
|
|
280
|
+
this uninstall leaves alone: one manifest can serve two stacks (the Simplex installer keeps
|
|
281
|
+
its own state and base directory beside a plain ``stack`` install), and a front end's venv
|
|
282
|
+
under the other stack's tree is that stack's. They stay on disk and in the manifest."""
|
|
283
|
+
theirs = {
|
|
284
|
+
Path(os.path.expanduser(d["deploy_dir"])).parent.parent
|
|
285
|
+
for name, d in doc["deployments"].items()
|
|
286
|
+
if name not in taken and not d["removed"]
|
|
287
|
+
}
|
|
288
|
+
kept = [a for a in doc["archives"] if any(base in Path(a).parents for base in theirs)]
|
|
289
|
+
if not kept:
|
|
290
|
+
return doc
|
|
291
|
+
out(
|
|
292
|
+
f"- {len(kept)} owned path(s) under a deployment left alone are kept: "
|
|
293
|
+
+ ", ".join(sorted(kept)[:3])
|
|
294
|
+
+ ("" if len(kept) <= 3 else ", …")
|
|
295
|
+
)
|
|
296
|
+
return {**doc, "archives": [a for a in doc["archives"] if a not in kept]}
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def is_download(path: str) -> bool:
|
|
300
|
+
"""A file this tool downloaded and verified (a tool or engine archive, or its checksum
|
|
301
|
+
marker), kept in a ``.archives`` directory. Front-end venvs and the gateway's data are
|
|
302
|
+
owned archives too, but installed or written here: an uninstall always deletes those."""
|
|
303
|
+
return Path(path).parent.name == ".archives"
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def kept_downloads(
|
|
307
|
+
doc: hosts.Owned, before: Engines, taken: Iterable[str], state: bool
|
|
308
|
+
) -> list[str]:
|
|
309
|
+
"""The download archives a plain uninstall leaves for the next install: the owned tool
|
|
310
|
+
archives, and the archives of the engines it is about to orphan. The caller records them
|
|
311
|
+
in the manifest, so a later ``--purge`` still finds the engine archives once the plans that
|
|
312
|
+
named them are gone."""
|
|
313
|
+
owned = [a for a in doc["archives"] if is_download(a)]
|
|
314
|
+
engines = [
|
|
315
|
+
str(folder.parent / ".archives" / (name + suffix))
|
|
316
|
+
for folder in orphaned(before, taken, state)
|
|
317
|
+
for name in before[folder]
|
|
318
|
+
for suffix in ("", ".sha256")
|
|
319
|
+
]
|
|
320
|
+
return sorted({p for p in [*owned, *engines] if os.path.lexists(p)})
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
def record_downloads(paths: list[str]) -> None:
|
|
324
|
+
"""Keep ``paths`` in the manifest's archives (see ``kept_downloads``)."""
|
|
325
|
+
if paths:
|
|
326
|
+
hosts.update_owned(
|
|
327
|
+
lambda d: d.__setitem__("archives", sorted(set(d["archives"]) | set(paths)))
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
Listing = list[tuple[str, int, int]] # path, bytes, hard links
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
def local_listing(paths: list[str]) -> Listing:
|
|
335
|
+
"""Each file, and each file inside a directory (a front's venv), that ``paths`` name."""
|
|
336
|
+
found = []
|
|
337
|
+
for path in paths:
|
|
338
|
+
if os.path.isdir(path) and not os.path.islink(path):
|
|
339
|
+
inner = sorted(str(p) for p in Path(path).rglob("*") if p.is_file() or p.is_symlink())
|
|
340
|
+
found += local_listing(inner)
|
|
341
|
+
elif os.path.lexists(path):
|
|
342
|
+
st = os.lstat(path)
|
|
343
|
+
found.append((path, st.st_size, st.st_nlink))
|
|
344
|
+
return found
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
def kept_weights(entries: dict[str, hosts.OwnedDeployment], listing: Listing) -> Listing:
|
|
348
|
+
"""The model files of ``entries`` that stay on disk: those not in the delete ``listing``."""
|
|
349
|
+
doomed = {path for path, _, _ in listing}
|
|
350
|
+
files = sorted({os.path.expanduser(f) for d in entries.values() for f in d["files"]})
|
|
351
|
+
return local_listing([f for f in files if f not in doomed])
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def preview(
|
|
355
|
+
listing: Listing,
|
|
356
|
+
kept: Listing,
|
|
357
|
+
swept: tuple[list[str], int],
|
|
358
|
+
doc: hosts.Owned,
|
|
359
|
+
out: Out,
|
|
360
|
+
downloads: Listing | None = None,
|
|
361
|
+
) -> None:
|
|
362
|
+
"""``stack remove --dry-run``: what would go and what would stay; nothing is changed."""
|
|
363
|
+
total = sum(size for _, size, _ in listing) + swept[1]
|
|
364
|
+
out(f"Would delete {len(listing)} files and what follows, {gib(total)} in all:")
|
|
365
|
+
for path in [t["path"] for t in doc["tools"]] + swept[0]:
|
|
366
|
+
out(f" {path}")
|
|
367
|
+
for path, size, _ in listing:
|
|
368
|
+
out(f" {path} ({size} bytes)")
|
|
369
|
+
weight = sum(size for _, size, _ in kept)
|
|
370
|
+
out(f"Would keep {len(kept)} model files, {gib(weight)}" + (":" if kept else ""))
|
|
371
|
+
for path, size, _ in kept:
|
|
372
|
+
out(f" {path} ({size} bytes)")
|
|
373
|
+
downloads = downloads or []
|
|
374
|
+
size = sum(size for _, size, _ in downloads)
|
|
375
|
+
if downloads:
|
|
376
|
+
out(f"Would keep {len(downloads)} downloaded archives, {gib(size)} (--purge deletes):")
|
|
377
|
+
for path, size, _ in downloads:
|
|
378
|
+
out(f" {path} ({size} bytes)")
|
|
379
|
+
out("Nothing changed: this was a dry run")
|
|
@@ -37,7 +37,10 @@ def config_files(client: str, env: dict[str, str] | None = None) -> dict[str, st
|
|
|
37
37
|
for name in names:
|
|
38
38
|
path = directory / name
|
|
39
39
|
if path.is_symlink() or (
|
|
40
|
-
path.exists()
|
|
40
|
+
path.exists()
|
|
41
|
+
and (
|
|
42
|
+
not path.is_file() or (hasattr(os, "getuid") and path.stat().st_uid != os.getuid())
|
|
43
|
+
)
|
|
41
44
|
):
|
|
42
45
|
raise harness.HarnessError(f"{client} config is not a regular file of the current user")
|
|
43
46
|
found[str(path)] = harness.digest(str(path))
|