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.
Source code in calcipy/tasks/executable_utils.py
@beartype
def check_installed(ctx: Context, executable: str, message: str) -> None:
"""If the required executable isn't present, raise a clear user error."""
res = run(ctx, f'which {executable}', warn=True, hide=True)
if not res or res.exited == 1:
raise RuntimeError(message)
python_dir
cached
⚓︎
python_dir()
Runs an executable from the currently active Python directory.
Source code in calcipy/tasks/executable_utils.py
@lru_cache(maxsize=1)
def python_dir() -> str:
"""Runs an executable from the currently active Python directory."""
return str(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()
Resolve the user’s Python path based on sys
.
Source code in calcipy/tasks/executable_utils.py
@lru_cache(maxsize=1)
def resolve_python() -> Path:
"""Resolve the user's Python path based on `sys`."""
python_path = Path(sys.executable)
with suppress(ValueError):
return python_path.relative_to(Path.cwd())
return python_path