Source code for gptcache.utils.dependency_control

import subprocess

from gptcache.utils.error import PipInstallError
from gptcache.utils.log import gptcache_log

[docs]def prompt_install(package: str, warn: bool = False): # pragma: no cover """ Function used to prompt user to install a package. """ cmd = f"pip install -q {package}" try: if warn and input(f"Install {package}? Y/n: ") != "Y": raise ModuleNotFoundError(f"No module named {package}") print(f"start to install package: {package}") subprocess.check_call(cmd, shell=True) print(f"successfully installed package: {package}")"%s installed successfully!", package) except subprocess.CalledProcessError as e: raise PipInstallError(package) from e