def test_install_dependency(self): """Test dependencies installed.""" package_name = "async_generator" dependency = Dependency(package_name, "==1.10") sys.modules.pop(package_name, None) run_install_subprocess( [sys.executable, "-m", "pip", "uninstall", package_name, "-y"] ) try: import_module(package_name) raise Exception("should not be raised") except ModuleNotFoundError: pass builder = AEABuilder.from_aea_project(Path(self._get_cwd())) with patch( "aea.aea_builder._DependenciesManager.pypi_dependencies", {"package_name": dependency}, ): builder.install_pypi_dependencies() import_module(package_name) sys.modules.pop(package_name) run_install_subprocess( [sys.executable, "-m", "pip", "uninstall", package_name, "-y"] ) try: import_module(package_name) raise Exception("should not be raised") except ModuleNotFoundError: pass
def _install_from_requirement(file: str, install_timeout: float = 300) -> None: """ Install from requirements. :param file: requirement.txt file path :param install_timeout: timeout to wait pip to install :return: None """ try: returncode = run_install_subprocess( [sys.executable, "-m", "pip", "install", "-r", file], install_timeout) enforce(returncode == 0, "Return code != 0.") except Exception: raise AEAException( "An error occurred while installing requirement file {}. Stopping..." .format(file))