bootstrap: add automatic .pth write for editable installs so top-level CLI is importable
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
This commit is contained in:
@@ -228,6 +228,56 @@ def main() -> int:
|
||||
print("Installing project into local venv (editable mode)")
|
||||
run([str(venv_python), "-m", "pip", "install", "-e", "."])
|
||||
|
||||
# Verify top-level 'CLI' import and, if missing, attempt to make it available
|
||||
print("Verifying top-level 'CLI' import in venv...")
|
||||
try:
|
||||
import subprocess as _sub
|
||||
rc = _sub.run([str(venv_python), "-c", "import importlib; importlib.import_module('CLI')"], check=False)
|
||||
if rc.returncode == 0:
|
||||
print("OK: top-level 'CLI' is importable in the venv.")
|
||||
else:
|
||||
print("Top-level 'CLI' not importable; attempting to add repo path to venv site-packages via a .pth file...")
|
||||
cmd = [str(venv_python), "-c", (
|
||||
"import site, sysconfig\n"
|
||||
"out=[]\n"
|
||||
"try:\n out.extend(site.getsitepackages())\nexcept Exception:\n pass\n"
|
||||
"try:\n p = sysconfig.get_paths().get('purelib')\n if p:\n out.append(p)\nexcept Exception:\n pass\n"
|
||||
"seen=[]; res=[]\n"
|
||||
"for x in out:\n if x and x not in seen:\n seen.append(x); res.append(x)\n"
|
||||
"for s in res:\n print(s)\n"
|
||||
)]
|
||||
out = _sub.check_output(cmd, text=True).strip().splitlines()
|
||||
site_dir = None
|
||||
for sp in out:
|
||||
if sp and _Path(sp).exists():
|
||||
site_dir = _Path(sp)
|
||||
break
|
||||
if site_dir is None:
|
||||
print("Could not determine venv site-packages directory; skipping .pth fallback")
|
||||
else:
|
||||
pth_file = site_dir / "medeia_repo.pth"
|
||||
if pth_file.exists():
|
||||
txt = pth_file.read_text(encoding="utf-8")
|
||||
if str(repo_root) in txt:
|
||||
print(f".pth already contains repo root: {pth_file}")
|
||||
else:
|
||||
with pth_file.open("a", encoding="utf-8") as fh:
|
||||
fh.write(str(repo_root) + "\n")
|
||||
print(f"Appended repo root to existing .pth: {pth_file}")
|
||||
else:
|
||||
with pth_file.open("w", encoding="utf-8") as fh:
|
||||
fh.write(str(repo_root) + "\n")
|
||||
print(f"Wrote .pth adding repo root to venv site-packages: {pth_file}")
|
||||
|
||||
# Re-check whether CLI can be imported now
|
||||
rc2 = _sub.run([str(venv_python), "-c", "import importlib; importlib.import_module('CLI')"], check=False)
|
||||
if rc2.returncode == 0:
|
||||
print("Top-level 'CLI' import works after adding .pth")
|
||||
else:
|
||||
print("Adding .pth did not make top-level 'CLI' importable; consider creating an egg-link or checking the venv.")
|
||||
except Exception as exc:
|
||||
print(f"Warning: failed to verify or modify site-packages for top-level CLI: {exc}")
|
||||
|
||||
# Optional: install Deno runtime (default: install unless --no-deno is passed)
|
||||
install_deno_requested = True
|
||||
if getattr(args, "no_deno", False):
|
||||
|
||||
Reference in New Issue
Block a user