Skip to content

muxtools.utils.download

get_executable

get_executable(type: str, can_error: Literal[True] = ..., *, package: str | None = None) -> str
get_executable(type: str, can_error: Literal[False] = ..., *, package: str | None = None) -> str | None
get_executable(type: str, can_error: bool = True, *, package: str | None = None) -> str | None

Find an executable, optionally selecting its installed package provider.

package is a canonical name, without a version constraint. Configured constraints still apply, and vof_exe_* overrides remain highest priority. With can_error=False, a missing executable returns None.

Source code in muxtools/utils/download.py
def get_executable(type: str, can_error: bool = True, *, package: str | None = None) -> str | None:
    """Find an executable, optionally selecting its installed package provider.

    ``package`` is a canonical name, without a version constraint. Configured
    constraints still apply, and ``vof_exe_*`` overrides remain highest priority.
    With ``can_error=False``, a missing executable returns ``None``.
    """
    from .binaries.runner import get_managed_executable

    env = os.environ.get(f"vof_exe_{type.lower()}", None)
    if env:
        path = Path(env)
        if path.exists():
            return str(path.resolve())
        if not can_error:
            return None
        raise error(f"Custom executable for {type} not found!", get_executable)
    try:
        path = get_managed_executable(type, package=package)
    except FileNotFoundError:
        if not can_error:
            return None
        raise
    if path is None and can_error:
        raise crit(f"{type.lower()} executable not found in path!", get_executable)
    return path