fdf
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled

This commit is contained in:
nose
2025-12-24 23:01:12 -08:00
parent 21d51d7f46
commit a2ec5ba22b
2 changed files with 35 additions and 0 deletions

View File

@@ -12,6 +12,34 @@ from pathlib import Path
import shlex
def _ensure_repo_root_on_sys_path(pkg_file: Optional[Path] = None) -> None:
"""Ensure the repository root (where top-level modules live) is importable.
The project currently keeps key modules like `CLI.py` at the repo root.
When `mm` is invoked from a different working directory, that repo root is
not necessarily on `sys.path`, which breaks `import CLI`.
We infer the repo root by walking up from this package location and looking
for a sibling `CLI.py`.
`pkg_file` exists for unit tests; production uses this module's `__file__`.
"""
try:
pkg_dir = (pkg_file or Path(__file__)).resolve().parent
except Exception:
return
for parent in pkg_dir.parents:
try:
if (parent / "CLI.py").exists():
parent_str = str(parent)
if parent_str not in sys.path:
sys.path.insert(0, parent_str)
return
except Exception:
continue
def _parse_mode_and_strip_args(args: List[str]) -> Tuple[Optional[str], List[str]]:
"""Parse --gui/--cli/--mode flags and return (mode, cleaned_args).
@@ -103,6 +131,7 @@ def _import_medeia_entry_module():
the repository (searching for .egg-link, walking parents, or checking CWD).
"""
try:
_ensure_repo_root_on_sys_path()
return importlib.import_module("medeia_entry")
except ImportError:
# Try to find the project root next to this installed package
@@ -165,6 +194,7 @@ def _run_cli(clean_args: List[str]) -> int:
else:
# Try importing the top-level `CLI` module directly (editable/repo mode).
try:
_ensure_repo_root_on_sys_path()
from CLI import MedeiaCLI as _M # type: ignore
MedeiaCLI = _M
except Exception: