#!python
"""Launch the package-local MMG executable without moving its shared libraries."""

import os
import sys
from importlib.util import find_spec
from pathlib import Path


def main():
    spec = find_spec("Muscat")
    if spec is None or not spec.submodule_search_locations:
        sys.exit("Cannot locate the installed Muscat package")
    executable = Path(next(iter(spec.submodule_search_locations))) / "bin" / "mmg2d_O3"
    if not executable.is_file():
        sys.exit(f"Packaged MMG executable is missing: {executable}")
    os.execv(str(executable), [str(executable), *sys.argv[1:]])


if __name__ == "__main__":
    main()
