async def _create_for_hash(): await PipProcessor(target_dir, runtime_env, logger) loop = get_running_loop() return await loop.run_in_executor( None, get_directory_size_bytes, target_dir )
async def _install_pip_packages( cls, path: str, pip_packages: List[str], cwd: str, env_vars: Dict, logger: logging.Logger, ): virtualenv_path = _PathHelper.get_virtualenv_path(path) python = _PathHelper.get_virtualenv_python(path) # TODO(fyrestone): Support -i, --no-deps, --no-cache-dir, ... pip_requirements_file = _PathHelper.get_requirements_file(path) def _gen_requirements_txt(): with open(pip_requirements_file, "w") as file: for line in pip_packages: file.write(line + "\n") # Avoid blocking the event loop. loop = get_running_loop() await loop.run_in_executor(None, _gen_requirements_txt) # pip options # # --disable-pip-version-check # Don't periodically check PyPI to determine whether a new version # of pip is available for download. # # --no-cache-dir # Disable the cache, the pip runtime env is a one-time installation, # and we don't need to handle the pip cache broken. pip_install_cmd = [ python, "-m", "pip", "install", "--disable-pip-version-check", "--no-cache-dir", "-r", pip_requirements_file, ] logger.info("Installing python requirements to %s", virtualenv_path) pip_env = os.environ.copy() pip_env.update(env_vars) await check_output_cmd(pip_install_cmd, logger=logger, cwd=cwd, env=pip_env)