Source code for deephaven_enterprise.venv
# Copyright (c) 2023-2023 Deephaven Data Labs and Patent Pending
from deephaven_enterprise import dh_globals
from deephaven import DHError
from typing import List
import os
[docs]def get_venv_path() -> str:
"""
Get the path to the virtual environment configured for this worker.
:return: the path to the virtual environment configured for this worker
"""
return dh_globals.venv
[docs]def install(packages : List[str]) -> None:
"""
Installs packages into the virtual environment using pip.
:param packages: the list of packages to install
:raises DHError: if pip is not found, or fails to install the requested packages
"""
if dh_globals.venv is None:
raise DHError("virtual environment is not configured!")
pip : str = "%s/bin/pip" % dh_globals.venv
if not os.path.exists(pip):
raise DHError("pip does not exist at %s" % pip)
if not os.access(pip, os.X_OK):
raise DHError("pip is not executable at %s" % pip)
lib_path : str = "%s/lib" % dh_globals.venv
if not os.access(lib_path, os.W_OK):
raise DHError("venv is not writable %s" % lib_path)
command : str = "%s install %s" % (pip, " ".join(packages))
ret_val : int = os.system(command)
if ret_val == 0:
return True
else:
raise DHError("%s exited with non-zero exit code" % command)