khh
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:
@@ -1,13 +1,60 @@
|
||||
"""Entry point wrapper for Medeia-Macina CLI."""
|
||||
"""Entry point wrapper for Medeia-Macina CLI.
|
||||
|
||||
This file is intentionally backwards-compatible. When installed from the
|
||||
packaged distribution the preferred entry is `medeia_macina.cli_entry.main`.
|
||||
When running from the repository (or in legacy installs) the module will
|
||||
attempt to import `MedeiaCLI` from the top-level `CLI` module.
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add the current directory to sys.path so we can import CLI
|
||||
root_dir = Path(__file__).parent
|
||||
if str(root_dir) not in sys.path:
|
||||
sys.path.insert(0, str(root_dir))
|
||||
|
||||
from CLI import MedeiaCLI
|
||||
def _run_packaged_entry(argv=None) -> int:
|
||||
"""Try to delegate to the packaged entry (`medeia_macina.cli_entry:main`)."""
|
||||
try:
|
||||
from medeia_macina.cli_entry import main as _main
|
||||
|
||||
return int(_main(argv) or 0)
|
||||
except Exception:
|
||||
return -1
|
||||
|
||||
|
||||
def _run_legacy_entry() -> None:
|
||||
"""Legacy behaviour: make repo root importable and run CLI.
|
||||
|
||||
This supports running directly from the source tree where `CLI.py` is
|
||||
available as a top-level module.
|
||||
"""
|
||||
root_dir = Path(__file__).resolve().parent
|
||||
if str(root_dir) not in sys.path:
|
||||
sys.path.insert(0, str(root_dir))
|
||||
|
||||
try:
|
||||
from CLI import MedeiaCLI
|
||||
except Exception as exc: # pragma: no cover - user environment issues
|
||||
raise ImportError(
|
||||
"Could not import 'MedeiaCLI' from top-level 'CLI'. "
|
||||
"If you installed the package into a virtualenv, activate it and run: \n"
|
||||
" pip install -e .\n"
|
||||
"or re-run the project bootstrap to ensure an up-to-date install."
|
||||
) from exc
|
||||
|
||||
if __name__ == "__main__":
|
||||
MedeiaCLI().run()
|
||||
|
||||
|
||||
# Backward-compatibility: try to expose `MedeiaCLI` at import-time when the
|
||||
# project is being used from a development checkout (so modules that import
|
||||
# the top-level `medeia_entry` can still access the CLI class).
|
||||
try:
|
||||
from CLI import MedeiaCLI as MedeiaCLI # type: ignore
|
||||
except Exception:
|
||||
# It's okay if the legacy top-level CLI isn't importable in installed packages.
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
MedeiaCLI().run()
|
||||
rc = _run_packaged_entry(sys.argv[1:])
|
||||
if rc >= 0:
|
||||
raise SystemExit(rc)
|
||||
# Fall back to legacy import when packaged entry couldn't be invoked.
|
||||
_run_legacy_entry()
|
||||
|
||||
Reference in New Issue
Block a user