sim-cli-core 0.3.0__py3-none-any.whl → 0.3.2__py3-none-any.whl
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.
- sim/_plugin_install.py +71 -170
- sim/cli.py +125 -15
- sim/compat.py +23 -1
- sim/config.py +8 -11
- sim/describe.py +11 -3
- sim/history.py +6 -0
- sim/inspect.py +48 -12
- sim/plugin_catalog.py +232 -0
- sim/server.py +37 -3
- sim/session.py +4 -1
- {sim_cli_core-0.3.0.dist-info → sim_cli_core-0.3.2.dist-info}/METADATA +71 -24
- sim_cli_core-0.3.2.dist-info/RECORD +29 -0
- sim_cli_core-0.3.2.dist-info/licenses/NOTICE +35 -0
- sim_cli_core-0.3.0.dist-info/RECORD +0 -28
- sim_cli_core-0.3.0.dist-info/licenses/NOTICE +0 -72
- {sim_cli_core-0.3.0.dist-info → sim_cli_core-0.3.2.dist-info}/WHEEL +0 -0
- {sim_cli_core-0.3.0.dist-info → sim_cli_core-0.3.2.dist-info}/entry_points.txt +0 -0
- {sim_cli_core-0.3.0.dist-info → sim_cli_core-0.3.2.dist-info}/licenses/LICENSE +0 -0
sim/_plugin_install.py
CHANGED
|
@@ -6,109 +6,34 @@ install pipeline.
|
|
|
6
6
|
|
|
7
7
|
A `<source>` argument can be any of:
|
|
8
8
|
|
|
9
|
-
*
|
|
10
|
-
|
|
9
|
+
* ``sim-plugin-<name>`` / ``sim-plugin-<name>==<version>`` — exact pip
|
|
10
|
+
package spec.
|
|
11
11
|
* ``https://...whl`` / ``https://...tar.gz`` — direct wheel/sdist URL.
|
|
12
12
|
* ``./path/to/dir`` — local plugin source directory.
|
|
13
13
|
* ``./path/to/wheel.whl`` / ``./path/to/sdist.tar.gz`` — local artifact.
|
|
14
14
|
* ``git+https://...`` / ``git+ssh://...`` — git URL.
|
|
15
15
|
|
|
16
|
-
The resolver classifies the source with no network calls
|
|
17
|
-
|
|
18
|
-
invocation does the work.
|
|
16
|
+
The resolver classifies the source with no network calls and no plugin
|
|
17
|
+
registry lookup. Then a single ``pip install`` invocation does the work.
|
|
19
18
|
"""
|
|
20
19
|
from __future__ import annotations
|
|
21
20
|
|
|
22
|
-
import json
|
|
23
|
-
import os
|
|
24
21
|
import re
|
|
25
22
|
import shutil
|
|
26
23
|
import subprocess
|
|
27
24
|
import sys
|
|
28
|
-
import urllib.request
|
|
29
25
|
from dataclasses import dataclass, field
|
|
30
26
|
from pathlib import Path
|
|
31
27
|
from typing import Any
|
|
32
28
|
|
|
33
29
|
|
|
34
|
-
# ── Index ───────────────────────────────────────────────────────────────────
|
|
35
|
-
|
|
36
|
-
DEFAULT_INDEX_URL = (
|
|
37
|
-
"https://raw.githubusercontent.com/svd-ai-lab/sim-plugin-index/main/index.json"
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
# How long an index is treated as fresh, before we re-fetch.
|
|
41
|
-
INDEX_CACHE_TTL_SECONDS = 3600
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def _index_cache_dir() -> Path:
|
|
45
|
-
return Path.home() / ".sim" / "index-cache"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def _index_cache_path() -> Path:
|
|
49
|
-
return _index_cache_dir() / "index.json"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def fetch_index(url: str = DEFAULT_INDEX_URL, *, force: bool = False, offline: bool = False) -> dict[str, Any]:
|
|
53
|
-
"""Fetch the public plugin index. Caches under ~/.sim/index-cache/.
|
|
54
|
-
|
|
55
|
-
In ``--offline`` mode, only the local cache is consulted; an empty index
|
|
56
|
-
is returned if no cache exists.
|
|
57
|
-
"""
|
|
58
|
-
cache = _index_cache_path()
|
|
59
|
-
if offline:
|
|
60
|
-
if cache.is_file():
|
|
61
|
-
try:
|
|
62
|
-
return json.loads(cache.read_text(encoding="utf-8"))
|
|
63
|
-
except (OSError, json.JSONDecodeError):
|
|
64
|
-
return {"schema_version": 1, "plugins": []}
|
|
65
|
-
return {"schema_version": 1, "plugins": []}
|
|
66
|
-
|
|
67
|
-
if not force and cache.is_file():
|
|
68
|
-
try:
|
|
69
|
-
age = cache.stat().st_mtime
|
|
70
|
-
except OSError:
|
|
71
|
-
age = 0
|
|
72
|
-
import time
|
|
73
|
-
if time.time() - age < INDEX_CACHE_TTL_SECONDS:
|
|
74
|
-
try:
|
|
75
|
-
return json.loads(cache.read_text(encoding="utf-8"))
|
|
76
|
-
except (OSError, json.JSONDecodeError):
|
|
77
|
-
pass
|
|
78
|
-
|
|
79
|
-
try:
|
|
80
|
-
with urllib.request.urlopen(url, timeout=10) as resp:
|
|
81
|
-
data = resp.read().decode("utf-8")
|
|
82
|
-
except Exception: # noqa: BLE001 — degrade if no network
|
|
83
|
-
if cache.is_file():
|
|
84
|
-
try:
|
|
85
|
-
return json.loads(cache.read_text(encoding="utf-8"))
|
|
86
|
-
except (OSError, json.JSONDecodeError):
|
|
87
|
-
pass
|
|
88
|
-
return {"schema_version": 1, "plugins": []}
|
|
89
|
-
|
|
90
|
-
parsed = json.loads(data)
|
|
91
|
-
cache.parent.mkdir(parents=True, exist_ok=True)
|
|
92
|
-
cache.write_text(data, encoding="utf-8")
|
|
93
|
-
return parsed
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def index_entry(name: str, *, offline: bool = False, url: str = DEFAULT_INDEX_URL) -> dict[str, Any] | None:
|
|
97
|
-
"""Look up one plugin by name in the index."""
|
|
98
|
-
idx = fetch_index(url=url, offline=offline)
|
|
99
|
-
for entry in idx.get("plugins", []):
|
|
100
|
-
if entry.get("name") == name:
|
|
101
|
-
return entry
|
|
102
|
-
return None
|
|
103
|
-
|
|
104
|
-
|
|
105
30
|
# ── Source resolution ──────────────────────────────────────────────────────
|
|
106
31
|
|
|
107
32
|
|
|
108
33
|
@dataclass(frozen=True)
|
|
109
34
|
class ResolvedSource:
|
|
110
35
|
"""One install source classified into a canonical kind."""
|
|
111
|
-
kind: str
|
|
36
|
+
kind: str
|
|
112
37
|
raw: str # the original argument
|
|
113
38
|
name: str | None = None
|
|
114
39
|
version: str | None = None
|
|
@@ -116,18 +41,34 @@ class ResolvedSource:
|
|
|
116
41
|
extras: dict[str, Any] = field(default_factory=dict)
|
|
117
42
|
|
|
118
43
|
|
|
119
|
-
|
|
120
|
-
|
|
44
|
+
_SHORT_NAME_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_]*$")
|
|
45
|
+
_SIM_PLUGIN_PACKAGE_RE = re.compile(
|
|
46
|
+
r"^(sim-plugin-[A-Za-z0-9][A-Za-z0-9_.-]*)(?:\[[A-Za-z0-9_,.-]+\])?"
|
|
47
|
+
r"(?:\s*(?:==|!=|~=|>=|<=|>|<)\s*[A-Za-z0-9.*+!_.-]+)?$"
|
|
48
|
+
)
|
|
49
|
+
_VERSION_PIN_RE = re.compile(r"(?:==|!=|~=|>=|<=|>|<)\s*(.+)$")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _short_name_error(name: str) -> str:
|
|
53
|
+
return (
|
|
54
|
+
f"{name!r} is not an explicit plugin install source. "
|
|
55
|
+
"See 'sim plugin catalog' for the official plugin list, or pass an "
|
|
56
|
+
"explicit pip-installable source: a local wheel/sdist path, a direct "
|
|
57
|
+
"wheel/sdist URL, a git URL, or a package spec such as "
|
|
58
|
+
f"'sim-plugin-{name}'."
|
|
59
|
+
)
|
|
121
60
|
|
|
122
61
|
|
|
123
|
-
def resolve_source(source: str, *, offline: bool = False,
|
|
62
|
+
def resolve_source(source: str, *, offline: bool = False,
|
|
63
|
+
index_url: str | None = None) -> ResolvedSource:
|
|
124
64
|
"""Classify a source argument and choose what to hand to pip.
|
|
125
65
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
66
|
+
``offline`` and ``index_url`` are accepted for API compatibility but no
|
|
67
|
+
longer affect resolution; this resolver never reads a plugin index or maps
|
|
68
|
+
short names to ``sim-plugin-*`` package names.
|
|
129
69
|
"""
|
|
130
70
|
s = source.strip()
|
|
71
|
+
_ = (offline, index_url)
|
|
131
72
|
|
|
132
73
|
# Local files / dirs first (cheapest to check).
|
|
133
74
|
p = Path(s)
|
|
@@ -138,7 +79,7 @@ def resolve_source(source: str, *, offline: bool = False, index_url: str = DEFAU
|
|
|
138
79
|
return ResolvedSource(kind="local-wheel", raw=s, pip_target=str(target))
|
|
139
80
|
if target.name.endswith(".tar.gz") or target.suffix == ".tar":
|
|
140
81
|
return ResolvedSource(kind="local-sdist", raw=s, pip_target=str(target))
|
|
141
|
-
|
|
82
|
+
return ResolvedSource(kind="local-file", raw=s, pip_target=str(target))
|
|
142
83
|
if target.is_dir():
|
|
143
84
|
return ResolvedSource(kind="local-dir", raw=s, pip_target=str(target))
|
|
144
85
|
# Path doesn't exist on disk and doesn't look obviously remote — error.
|
|
@@ -156,41 +97,20 @@ def resolve_source(source: str, *, offline: bool = False, index_url: str = DEFAU
|
|
|
156
97
|
# Generic URL: treat as wheel-url and let pip complain.
|
|
157
98
|
return ResolvedSource(kind="wheel-url", raw=s, pip_target=s)
|
|
158
99
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
pip_target=str(entry["latest_wheel_url"]))
|
|
174
|
-
git = entry.get("git")
|
|
175
|
-
if git:
|
|
176
|
-
return ResolvedSource(kind="name-version", raw=s, name=name, version=version,
|
|
177
|
-
pip_target=f"git+{git}@v{version}")
|
|
178
|
-
return ResolvedSource(kind="name-version", raw=s, name=name, version=version,
|
|
179
|
-
pip_target=f"sim-plugin-{name}=={version}")
|
|
180
|
-
|
|
181
|
-
# bare name
|
|
182
|
-
if _NAME_RE.match(s):
|
|
183
|
-
entry = index_entry(s, offline=offline, url=index_url)
|
|
184
|
-
if entry is None and offline:
|
|
185
|
-
raise ValueError(f"plugin {s!r} not in offline index")
|
|
186
|
-
if entry is None:
|
|
187
|
-
# Optimistic: assume sim-plugin-<name> is published; pip will tell us.
|
|
188
|
-
return ResolvedSource(kind="name", raw=s, name=s, pip_target=f"sim-plugin-{s}")
|
|
189
|
-
if entry.get("latest_wheel_url"):
|
|
190
|
-
return ResolvedSource(kind="name", raw=s, name=s, pip_target=str(entry["latest_wheel_url"]))
|
|
191
|
-
if entry.get("git"):
|
|
192
|
-
return ResolvedSource(kind="name", raw=s, name=s, pip_target=f"git+{entry['git']}")
|
|
193
|
-
return ResolvedSource(kind="name", raw=s, name=s, pip_target=f"sim-plugin-{s}")
|
|
100
|
+
package_match = _SIM_PLUGIN_PACKAGE_RE.match(s)
|
|
101
|
+
if package_match:
|
|
102
|
+
version_match = _VERSION_PIN_RE.search(s)
|
|
103
|
+
version = version_match.group(1).strip() if version_match else None
|
|
104
|
+
return ResolvedSource(
|
|
105
|
+
kind="package-spec",
|
|
106
|
+
raw=s,
|
|
107
|
+
name=package_match.group(1),
|
|
108
|
+
version=version,
|
|
109
|
+
pip_target=s,
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
if _SHORT_NAME_RE.match(s):
|
|
113
|
+
raise ValueError(_short_name_error(s))
|
|
194
114
|
|
|
195
115
|
raise ValueError(f"could not classify install source: {source!r}")
|
|
196
116
|
|
|
@@ -272,6 +192,7 @@ def install_plugin(
|
|
|
272
192
|
sync_target: Path | None = None,
|
|
273
193
|
skip_sync: bool = False,
|
|
274
194
|
python: str | None = None,
|
|
195
|
+
extra_index_urls: list[str] | None = None,
|
|
275
196
|
) -> InstallReport:
|
|
276
197
|
"""High-level installer used by ``sim plugin install``.
|
|
277
198
|
|
|
@@ -292,9 +213,16 @@ def install_plugin(
|
|
|
292
213
|
message=str(e),
|
|
293
214
|
)
|
|
294
215
|
|
|
216
|
+
extra_args: list[str] = []
|
|
217
|
+
for extra_index_url in extra_index_urls or []:
|
|
218
|
+
extra_args.extend(["--extra-index-url", extra_index_url])
|
|
219
|
+
|
|
295
220
|
proc = _pip_install(
|
|
296
221
|
resolved.pip_target,
|
|
297
|
-
editable=editable,
|
|
222
|
+
editable=editable,
|
|
223
|
+
upgrade=upgrade,
|
|
224
|
+
python=python,
|
|
225
|
+
extra_args=extra_args or None,
|
|
298
226
|
)
|
|
299
227
|
ok = proc.returncode == 0
|
|
300
228
|
|
|
@@ -387,63 +315,36 @@ def uninstall_plugin(name: str, *, sync: bool = True,
|
|
|
387
315
|
|
|
388
316
|
|
|
389
317
|
def bundle_plugins(names: list[str], output_dir: Path, *,
|
|
390
|
-
index_url: str =
|
|
391
|
-
"""
|
|
318
|
+
index_url: str | None = None) -> dict[str, Any]:
|
|
319
|
+
"""The install-resolver-backed bundle flow was removed.
|
|
392
320
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
321
|
+
Use the discovery catalogue to find plugins, then download explicit wheel
|
|
322
|
+
URLs or install exact package specs. The catalogue itself is not an
|
|
323
|
+
install-time resolver.
|
|
396
324
|
"""
|
|
397
|
-
|
|
398
|
-
output_dir.mkdir(parents=True, exist_ok=True)
|
|
399
|
-
|
|
400
|
-
idx = fetch_index(url=index_url)
|
|
401
|
-
by_name = {e["name"]: e for e in idx.get("plugins", [])}
|
|
402
|
-
|
|
403
|
-
fetched: list[dict[str, Any]] = []
|
|
404
|
-
errors: list[dict[str, Any]] = []
|
|
405
|
-
|
|
406
|
-
for name in names:
|
|
407
|
-
entry = by_name.get(name)
|
|
408
|
-
if entry is None:
|
|
409
|
-
errors.append({"name": name, "error": "not in index"})
|
|
410
|
-
continue
|
|
411
|
-
wheel_url = entry.get("latest_wheel_url")
|
|
412
|
-
if not wheel_url:
|
|
413
|
-
errors.append({"name": name, "error": "index entry has no latest_wheel_url"})
|
|
414
|
-
continue
|
|
415
|
-
wheel_basename = Path(wheel_url.split("?")[0]).name
|
|
416
|
-
dest = output_dir / wheel_basename
|
|
417
|
-
try:
|
|
418
|
-
with urllib.request.urlopen(wheel_url, timeout=30) as resp, dest.open("wb") as f:
|
|
419
|
-
shutil.copyfileobj(resp, f)
|
|
420
|
-
except Exception as e: # noqa: BLE001 — surface fetch errors
|
|
421
|
-
errors.append({"name": name, "error": f"download failed: {e}"})
|
|
422
|
-
continue
|
|
423
|
-
|
|
424
|
-
rewritten = dict(entry)
|
|
425
|
-
rewritten["latest_wheel_url"] = f"file://{dest}"
|
|
426
|
-
fetched.append(rewritten)
|
|
427
|
-
|
|
428
|
-
bundle_idx = {"schema_version": 1, "plugins": fetched}
|
|
429
|
-
(output_dir / "index.json").write_text(
|
|
430
|
-
json.dumps(bundle_idx, indent=2) + "\n", encoding="utf-8",
|
|
431
|
-
)
|
|
432
|
-
|
|
325
|
+
_ = (names, output_dir, index_url)
|
|
433
326
|
return {
|
|
434
|
-
"ok":
|
|
327
|
+
"ok": False,
|
|
435
328
|
"output": str(output_dir),
|
|
436
|
-
"fetched": [
|
|
437
|
-
"errors":
|
|
329
|
+
"fetched": [],
|
|
330
|
+
"errors": [
|
|
331
|
+
{
|
|
332
|
+
"name": name,
|
|
333
|
+
"error": (
|
|
334
|
+
"bundle no longer resolves catalogue names; use "
|
|
335
|
+
"sim plugin catalog/search to discover plugins, then pass "
|
|
336
|
+
"explicit wheel URLs, local artifacts, git URLs, or exact "
|
|
337
|
+
"package specs"
|
|
338
|
+
),
|
|
339
|
+
}
|
|
340
|
+
for name in names
|
|
341
|
+
],
|
|
438
342
|
}
|
|
439
343
|
|
|
440
344
|
|
|
441
345
|
__all__ = [
|
|
442
|
-
"DEFAULT_INDEX_URL",
|
|
443
346
|
"ResolvedSource",
|
|
444
347
|
"InstallReport",
|
|
445
|
-
"fetch_index",
|
|
446
|
-
"index_entry",
|
|
447
348
|
"resolve_source",
|
|
448
349
|
"install_plugin",
|
|
449
350
|
"uninstall_plugin",
|
sim/cli.py
CHANGED
|
@@ -13,6 +13,19 @@ from sim.drivers import get_driver
|
|
|
13
13
|
from sim.runner import execute_script
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
# Reconfigure stdout/stderr to UTF-8 so non-ASCII glyphs (arrows, check marks,
|
|
17
|
+
# warning triangles, etc.) survive on Windows consoles that default to cp1252
|
|
18
|
+
# or older codepages. errors="replace" prevents crashes on terminals that
|
|
19
|
+
# can't render a given codepoint — affected glyphs become "?" instead of
|
|
20
|
+
# raising UnicodeEncodeError.
|
|
21
|
+
if sys.stdout.encoding and sys.stdout.encoding.lower() != "utf-8":
|
|
22
|
+
try:
|
|
23
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
24
|
+
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
|
25
|
+
except (AttributeError, OSError):
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
|
|
16
29
|
# ── Top-level group ──────────────────────────────────────────────────────────
|
|
17
30
|
|
|
18
31
|
@click.group()
|
|
@@ -328,7 +341,7 @@ def lint(ctx, script):
|
|
|
328
341
|
level="error",
|
|
329
342
|
message=(
|
|
330
343
|
f"No registered driver claims {script_path.name!r}. "
|
|
331
|
-
"Install the matching plugin (e.g. `sim plugin install
|
|
344
|
+
"Install the matching plugin (e.g. `sim plugin install sim-plugin-<solver>`) "
|
|
332
345
|
"or pass `sim run` if you want to attempt execution anyway."
|
|
333
346
|
),
|
|
334
347
|
)],
|
|
@@ -483,6 +496,47 @@ def _print_followup_hints(run_id, stdout_path, stderr_path, delta):
|
|
|
483
496
|
click.echo(f" cat {delta[0]['path']} # likely solver log (largest write)")
|
|
484
497
|
|
|
485
498
|
|
|
499
|
+
def _parse_driver_option_value(value: str):
|
|
500
|
+
lowered = value.lower()
|
|
501
|
+
if lowered == "true":
|
|
502
|
+
return True
|
|
503
|
+
if lowered == "false":
|
|
504
|
+
return False
|
|
505
|
+
try:
|
|
506
|
+
return int(value)
|
|
507
|
+
except ValueError:
|
|
508
|
+
pass
|
|
509
|
+
try:
|
|
510
|
+
return float(value)
|
|
511
|
+
except ValueError:
|
|
512
|
+
return value
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def _parse_driver_options(items: tuple[str, ...]) -> dict:
|
|
516
|
+
"""Parse generic driver launch passthrough options from KEY=VALUE pairs."""
|
|
517
|
+
parsed: dict = {}
|
|
518
|
+
for item in items:
|
|
519
|
+
if "=" not in item:
|
|
520
|
+
raise click.BadParameter(
|
|
521
|
+
f"{item!r} is not KEY=VALUE",
|
|
522
|
+
param_hint="--driver-option",
|
|
523
|
+
)
|
|
524
|
+
key, value = item.split("=", 1)
|
|
525
|
+
key = key.strip()
|
|
526
|
+
if not key:
|
|
527
|
+
raise click.BadParameter(
|
|
528
|
+
f"{item!r} has an empty key",
|
|
529
|
+
param_hint="--driver-option",
|
|
530
|
+
)
|
|
531
|
+
if key in parsed:
|
|
532
|
+
raise click.BadParameter(
|
|
533
|
+
f"{key!r} was provided more than once",
|
|
534
|
+
param_hint="--driver-option",
|
|
535
|
+
)
|
|
536
|
+
parsed[key] = _parse_driver_option_value(value)
|
|
537
|
+
return parsed
|
|
538
|
+
|
|
539
|
+
|
|
486
540
|
# ── connect (persistent session) ────────────────────────────────────────────
|
|
487
541
|
|
|
488
542
|
@main.command()
|
|
@@ -492,11 +546,19 @@ def _print_followup_hints(run_id, stdout_path, stderr_path, delta):
|
|
|
492
546
|
@click.option("--processors", default=1, type=int)
|
|
493
547
|
@click.option("--workspace", default=None,
|
|
494
548
|
help="Solver-specific working dir (e.g. flotherm FLOUSERDIR).")
|
|
549
|
+
@click.option("--driver-option", "driver_options", multiple=True,
|
|
550
|
+
metavar="KEY=VALUE",
|
|
551
|
+
help="Generic driver launch option passthrough. Repeat as needed.")
|
|
495
552
|
@click.pass_context
|
|
496
|
-
def connect(ctx, solver, mode, ui_mode, processors, workspace):
|
|
553
|
+
def connect(ctx, solver, mode, ui_mode, processors, workspace, driver_options):
|
|
497
554
|
"""Launch a solver and hold a persistent session."""
|
|
498
555
|
from sim.session import SessionClient
|
|
499
556
|
|
|
557
|
+
try:
|
|
558
|
+
parsed_driver_options = _parse_driver_options(driver_options)
|
|
559
|
+
except click.BadParameter as exc:
|
|
560
|
+
raise click.ClickException(str(exc)) from exc
|
|
561
|
+
|
|
500
562
|
client = SessionClient(host=ctx.obj["host"], port=ctx.obj["port"],
|
|
501
563
|
session_id=ctx.obj.get("session"))
|
|
502
564
|
result = client.connect(
|
|
@@ -505,6 +567,7 @@ def connect(ctx, solver, mode, ui_mode, processors, workspace):
|
|
|
505
567
|
ui_mode=ui_mode,
|
|
506
568
|
processors=processors,
|
|
507
569
|
workspace=workspace,
|
|
570
|
+
driver_options=parsed_driver_options,
|
|
508
571
|
)
|
|
509
572
|
|
|
510
573
|
if ctx.obj["json"]:
|
|
@@ -858,7 +921,7 @@ def init(ctx, force):
|
|
|
858
921
|
@click.option("--config", "config_path", type=click.Path(exists=True, dir_okay=False, path_type=Path),
|
|
859
922
|
default=None, help="Override the sim.toml location.")
|
|
860
923
|
@click.option("--offline", is_flag=True,
|
|
861
|
-
help="
|
|
924
|
+
help="Accepted for compatibility; plugin install no longer uses an index.")
|
|
862
925
|
@click.option("--dry-run", is_flag=True,
|
|
863
926
|
help="Print what would happen without installing anything.")
|
|
864
927
|
@click.pass_context
|
|
@@ -936,8 +999,49 @@ def plugin():
|
|
|
936
999
|
|
|
937
1000
|
Plugins extend sim with additional solvers. Each plugin ships its
|
|
938
1001
|
driver + skill in one wheel; see docs/plugin-install.md for the install
|
|
939
|
-
flows (
|
|
1002
|
+
flows (package spec, direct URL, local wheel, git URL, etc.).
|
|
1003
|
+
"""
|
|
1004
|
+
|
|
1005
|
+
|
|
1006
|
+
@plugin.command("catalog")
|
|
1007
|
+
@click.option("--offline", is_flag=True,
|
|
1008
|
+
help="Use the cached discovery catalogue only.")
|
|
1009
|
+
@click.option("--refresh", is_flag=True,
|
|
1010
|
+
help="Refresh the cached discovery catalogue.")
|
|
1011
|
+
@click.option("--catalog-url", default=None,
|
|
1012
|
+
help="Override the discovery catalogue URL.")
|
|
1013
|
+
@click.pass_context
|
|
1014
|
+
def plugin_catalog_cmd(ctx, offline, refresh, catalog_url):
|
|
1015
|
+
"""List available plugins from the discovery catalogue.
|
|
1016
|
+
|
|
1017
|
+
This is discovery only. Install commands remain explicit and pip-native;
|
|
1018
|
+
the catalogue is not used to silently resolve short names during install.
|
|
940
1019
|
"""
|
|
1020
|
+
from sim.plugin_catalog import DEFAULT_CATALOG_URL, list_catalog
|
|
1021
|
+
|
|
1022
|
+
rows = list_catalog(
|
|
1023
|
+
url=catalog_url or DEFAULT_CATALOG_URL,
|
|
1024
|
+
offline=offline,
|
|
1025
|
+
force=refresh,
|
|
1026
|
+
)
|
|
1027
|
+
if ctx.obj["json"]:
|
|
1028
|
+
click.echo(json_mod.dumps([r.to_dict() for r in rows], indent=2))
|
|
1029
|
+
return
|
|
1030
|
+
|
|
1031
|
+
if not rows:
|
|
1032
|
+
click.echo("[sim] plugin catalog: no available plugins found")
|
|
1033
|
+
return
|
|
1034
|
+
|
|
1035
|
+
click.echo(f"[sim] {len(rows)} available plugin(s) in catalog:")
|
|
1036
|
+
for r in rows:
|
|
1037
|
+
ver = f" {r.version}" if r.version else ""
|
|
1038
|
+
license_class = f" ({r.license_class})" if r.license_class else ""
|
|
1039
|
+
dist = f" [{r.distribution}]" if r.distribution else ""
|
|
1040
|
+
click.echo(f" {r.id:20s} {r.name}{ver}{dist}{license_class}")
|
|
1041
|
+
if r.summary:
|
|
1042
|
+
click.echo(f" {r.summary}")
|
|
1043
|
+
if r.install:
|
|
1044
|
+
click.echo(f" install: sim plugin install {r.install}")
|
|
941
1045
|
|
|
942
1046
|
|
|
943
1047
|
@plugin.command("list")
|
|
@@ -1022,10 +1126,13 @@ def plugin_info_cmd(ctx, name):
|
|
|
1022
1126
|
@click.argument("source")
|
|
1023
1127
|
@click.option("-e", "--editable", is_flag=True,
|
|
1024
1128
|
help="Editable install (pip install -e). For plugin authors.")
|
|
1025
|
-
@click.option("--upgrade",
|
|
1026
|
-
help="Pass --upgrade to pip
|
|
1129
|
+
@click.option("--upgrade/--no-upgrade", default=True,
|
|
1130
|
+
help="Pass --upgrade to pip so the install replaces any "
|
|
1131
|
+
"existing version with whatever the source resolves to. "
|
|
1132
|
+
"Default: enabled. Use --no-upgrade to keep an existing "
|
|
1133
|
+
"install if one is already present.")
|
|
1027
1134
|
@click.option("--offline", is_flag=True,
|
|
1028
|
-
help="
|
|
1135
|
+
help="Accepted for compatibility; plugin install no longer uses an index.")
|
|
1029
1136
|
@click.option("--no-sync", "no_sync", is_flag=True,
|
|
1030
1137
|
help="Skip sync-skills after install.")
|
|
1031
1138
|
@click.option("--target", "sync_target", type=click.Path(file_okay=False, path_type=Path),
|
|
@@ -1035,20 +1142,23 @@ def plugin_info_cmd(ctx, name):
|
|
|
1035
1142
|
help="Pin the target Python interpreter for the install. "
|
|
1036
1143
|
"Defaults to the interpreter running sim — use this "
|
|
1037
1144
|
"when sim is on PATH but the desired venv isn't activated.")
|
|
1145
|
+
@click.option("--extra-index-url", "extra_index_urls", multiple=True,
|
|
1146
|
+
help="Additional Python package index for private plugins. "
|
|
1147
|
+
"Passed through to pip/uv pip install.")
|
|
1038
1148
|
@click.pass_context
|
|
1039
1149
|
def plugin_install(ctx, source, editable, upgrade, offline, no_sync, sync_target,
|
|
1040
|
-
python_exe):
|
|
1150
|
+
python_exe, extra_index_urls):
|
|
1041
1151
|
"""Install a plugin from any supported source.
|
|
1042
1152
|
|
|
1043
1153
|
\b
|
|
1044
1154
|
Examples:
|
|
1045
|
-
sim plugin install coolprop
|
|
1046
|
-
sim plugin install coolprop
|
|
1155
|
+
sim plugin install sim-plugin-coolprop # exact package spec
|
|
1156
|
+
sim plugin install sim-plugin-coolprop==0.1.0 # pinned package spec
|
|
1047
1157
|
sim plugin install ./sim_plugin_coolprop-0.1.0-py3-none-any.whl
|
|
1048
1158
|
sim plugin install ./sim-plugin-coolprop -e # editable, for authors
|
|
1049
1159
|
sim plugin install git+https://github.com/svd-ai-lab/sim-plugin-coolprop
|
|
1050
|
-
sim plugin install
|
|
1051
|
-
sim plugin install
|
|
1160
|
+
sim plugin install sim-plugin-coolprop --python /path/to/venv/bin/python
|
|
1161
|
+
sim plugin install sim-plugin-mechanical --extra-index-url https://example.com/simple/
|
|
1052
1162
|
"""
|
|
1053
1163
|
from sim._plugin_install import install_plugin
|
|
1054
1164
|
|
|
@@ -1057,6 +1167,7 @@ def plugin_install(ctx, source, editable, upgrade, offline, no_sync, sync_target
|
|
|
1057
1167
|
editable=editable, upgrade=upgrade, offline=offline,
|
|
1058
1168
|
sync_target=sync_target, skip_sync=no_sync,
|
|
1059
1169
|
python=python_exe,
|
|
1170
|
+
extra_index_urls=list(extra_index_urls),
|
|
1060
1171
|
)
|
|
1061
1172
|
|
|
1062
1173
|
if ctx.obj["json"]:
|
|
@@ -1105,12 +1216,11 @@ def plugin_uninstall(ctx, name, python_exe):
|
|
|
1105
1216
|
help="Output directory for wheels + filtered index.json.")
|
|
1106
1217
|
@click.pass_context
|
|
1107
1218
|
def plugin_bundle(ctx, names, output):
|
|
1108
|
-
"""
|
|
1219
|
+
"""Deprecated: index-backed plugin bundles are no longer supported.
|
|
1109
1220
|
|
|
1110
1221
|
\b
|
|
1111
1222
|
Examples:
|
|
1112
|
-
sim plugin
|
|
1113
|
-
sim plugin install --offline --from-dir ./plugins-bundle/ coolprop
|
|
1223
|
+
sim plugin install ./vendor/sim_plugin_coolprop-0.1.0-py3-none-any.whl
|
|
1114
1224
|
"""
|
|
1115
1225
|
from sim._plugin_install import bundle_plugins
|
|
1116
1226
|
|
sim/compat.py
CHANGED
|
@@ -185,7 +185,7 @@ def load_compatibility_by_name(driver_name: str) -> "Compatibility | None":
|
|
|
185
185
|
if not traversable.is_file():
|
|
186
186
|
return None
|
|
187
187
|
text = traversable.read_text(encoding="utf-8")
|
|
188
|
-
except (FileNotFoundError, ModuleNotFoundError, OSError):
|
|
188
|
+
except (FileNotFoundError, ModuleNotFoundError, OSError, TypeError):
|
|
189
189
|
return None
|
|
190
190
|
return _parse_compatibility_text(driver_name, text)
|
|
191
191
|
|
|
@@ -395,6 +395,28 @@ def skills_block_for_profile(driver: str, profile: "Profile | None") -> dict:
|
|
|
395
395
|
driver_dir = (root / driver) if root is not None else None
|
|
396
396
|
|
|
397
397
|
if driver_dir is None or not driver_dir.is_dir():
|
|
398
|
+
# Out-of-tree plugins can bundle skills through the ``sim.skills``
|
|
399
|
+
# entry-point. Prefer the external sim-skills tree when present so
|
|
400
|
+
# local development overlays win, then fall back to the installed
|
|
401
|
+
# plugin bundle.
|
|
402
|
+
try:
|
|
403
|
+
from sim.plugins import skills_dir_for
|
|
404
|
+
plugin_dir = skills_dir_for(driver)
|
|
405
|
+
except Exception: # noqa: BLE001 - skills are advisory context
|
|
406
|
+
plugin_dir = None
|
|
407
|
+
if plugin_dir is not None:
|
|
408
|
+
try:
|
|
409
|
+
index = plugin_dir.joinpath("SKILL.md")
|
|
410
|
+
if index.is_file():
|
|
411
|
+
return {
|
|
412
|
+
"root": str(plugin_dir),
|
|
413
|
+
"index": str(index),
|
|
414
|
+
"active_sdk_layer": active_sdk,
|
|
415
|
+
"active_solver_layer": active_solver,
|
|
416
|
+
}
|
|
417
|
+
except Exception: # noqa: BLE001 - fall through to hint
|
|
418
|
+
pass
|
|
419
|
+
|
|
398
420
|
return {
|
|
399
421
|
"root": None,
|
|
400
422
|
"index": None,
|
sim/config.py
CHANGED
|
@@ -271,11 +271,12 @@ SIM_TOML_STUB = """\
|
|
|
271
271
|
# workspace = "./workspace"
|
|
272
272
|
|
|
273
273
|
# Each entry under [[sim.plugins]] declares one plugin to install.
|
|
274
|
-
# Sources accepted:
|
|
274
|
+
# Sources accepted: package = "sim-plugin-...", git+https://...,
|
|
275
275
|
# wheel = "./path/to/file.whl", or version = "==X.Y.Z" / ">=X".
|
|
276
276
|
#
|
|
277
277
|
# [[sim.plugins]]
|
|
278
278
|
# name = "coolprop"
|
|
279
|
+
# package = "sim-plugin-coolprop"
|
|
279
280
|
# version = ">=0.1.0"
|
|
280
281
|
"""
|
|
281
282
|
|
|
@@ -311,6 +312,7 @@ def validate_sim_toml(path: Path) -> list[str]:
|
|
|
311
312
|
|
|
312
313
|
[[sim.plugins]]
|
|
313
314
|
name = <string> # required
|
|
315
|
+
package = <string>? # exact pip package name/spec
|
|
314
316
|
version = <string>?
|
|
315
317
|
git = <string>?
|
|
316
318
|
wheel = <string>? # local path
|
|
@@ -351,7 +353,7 @@ def validate_sim_toml(path: Path) -> list[str]:
|
|
|
351
353
|
if "name" not in p or not isinstance(p["name"], str):
|
|
352
354
|
errors.append(f"[[sim.plugins]] entry #{i} missing required 'name'")
|
|
353
355
|
continue
|
|
354
|
-
for k in ("version", "git", "wheel"):
|
|
356
|
+
for k in ("package", "version", "git", "wheel"):
|
|
355
357
|
if k in p and not isinstance(p[k], str):
|
|
356
358
|
errors.append(f"[[sim.plugins]] {p['name']!r} field {k!r} must be a string")
|
|
357
359
|
|
|
@@ -362,19 +364,14 @@ def derive_install_source(plugin_entry: dict[str, Any]) -> str:
|
|
|
362
364
|
"""Translate one [[sim.plugins]] entry to an install-source string.
|
|
363
365
|
|
|
364
366
|
Resolution priority: explicit ``wheel`` path > explicit ``git`` URL
|
|
365
|
-
> ``
|
|
367
|
+
> explicit ``package`` plus optional version > ``name``.
|
|
366
368
|
"""
|
|
367
369
|
if "wheel" in plugin_entry:
|
|
368
370
|
return plugin_entry["wheel"]
|
|
369
371
|
if "git" in plugin_entry:
|
|
370
372
|
return f"git+{plugin_entry['git']}"
|
|
371
|
-
|
|
373
|
+
package = plugin_entry.get("package") or plugin_entry["name"]
|
|
372
374
|
version = plugin_entry.get("version")
|
|
373
375
|
if version:
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
if version.startswith("=="):
|
|
377
|
-
return f"{name}@{v}"
|
|
378
|
-
# Range constraints: fall back to bare name and let pip resolve.
|
|
379
|
-
return name
|
|
380
|
-
return name
|
|
376
|
+
return f"{package}{version}"
|
|
377
|
+
return package
|