Source code for deephaven_enterprise.venv

#
# Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
#
"""This module allows users to dynamically inspect the virtual environment of the current worker and install
additional packages in it.
"""

import os

from deephaven import DHError

from deephaven_enterprise import dh_globals


[docs] def get_venv_path() -> str: """Returns the path to the virtual environment configured for the current worker. Returns: str """ return dh_globals.venv
[docs] def install(packages: list[str]) -> None: """Installs packages into the virtual environment of the current worker using pip. Args: packages (list[str]): 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(message="virtual environment is not configured!") pip: str = "%s/bin/pip" % dh_globals.venv if not os.path.exists(pip): raise DHError(message="pip does not exist at %s" % pip) if not os.access(pip, os.X_OK): raise DHError(message="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(message="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: raise DHError(message="%s exited with non-zero exit code" % command)