Executable utils
Utilities for working in calcipy’s python environment.
Functions⚓︎
check_installed ⚓︎
check_installed(ctx, executable, message)
If the required executable isn’t present, raise a clear user error.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
if not missing |
Source code in calcipy/tasks/executable_utils.py
def check_installed(ctx: Context, executable: str, message: str) -> None:
"""If the required executable isn't present, raise a clear user error.
Raises:
RuntimeError: if not missing
"""
if executable in _EXECUTABLE_CACHE:
res = _EXECUTABLE_CACHE[executable]
else:
res = run(ctx, f'which {executable}', warn=True, hide=True)
_EXECUTABLE_CACHE[executable] = res
if not res or res.exited == 1:
raise RuntimeError(message)
python_dir
cached
⚓︎
python_dir()
Return an executable path from the currently active Python directory.
Source code in calcipy/tasks/executable_utils.py
@lru_cache(maxsize=1)
def python_dir() -> Path:
"""Return an executable path from the currently active Python directory."""
return resolve_python().parent
python_m
cached
⚓︎
python_m()
Return the active python path and -m flag.
Source code in calcipy/tasks/executable_utils.py
@lru_cache(maxsize=1)
def python_m() -> str:
"""Return the active python path and `-m` flag."""
return f'{resolve_python()} -m'
resolve_python
cached
⚓︎
resolve_python()
Return the user’s Python path based on sys.
Source code in calcipy/tasks/executable_utils.py
@lru_cache(maxsize=1)
def resolve_python() -> Path:
"""Return the user's Python path based on `sys`."""
python_path = Path(sys.executable).absolute()
with suppress(ValueError):
return python_path.relative_to(Path.cwd())
return python_path