# Copyright (c) 2023-2023 Deephaven Data Labs and Patent Pendingfromdeephaven_enterpriseimportdh_globalsfromdeephavenimportDHErrorfromtypingimportListimportos
[docs]defget_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 """returndh_globals.venv
[docs]definstall(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 """ifdh_globals.venvisNone:raiseDHError("virtual environment is not configured!")pip:str="%s/bin/pip"%dh_globals.venvifnotos.path.exists(pip):raiseDHError("pip does not exist at %s"%pip)ifnotos.access(pip,os.X_OK):raiseDHError("pip is not executable at %s"%pip)lib_path:str="%s/lib"%dh_globals.venvifnotos.access(lib_path,os.W_OK):raiseDHError("venv is not writable %s"%lib_path)command:str="%s install %s"%(pip," ".join(packages))ret_val:int=os.system(command)ifret_val==0:returnTrueelse:raiseDHError("%s exited with non-zero exit code"%command)