From 0fce9f39b3d37ebbb9b1815232051fa5f5daf8ad Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 27 Sep 2021 00:32:25 -0500 Subject: [PATCH] Avoid checking if a package is installed if it already failed (#56698) --- homeassistant/requirements.py | 6 +++--- tests/test_requirements.py | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/homeassistant/requirements.py b/homeassistant/requirements.py index 9fdeac7ac75..aad4a6b1f46 100644 --- a/homeassistant/requirements.py +++ b/homeassistant/requirements.py @@ -178,9 +178,6 @@ async def _async_process_requirements( kwargs: Any, ) -> None: """Install a requirement and save failures.""" - if pkg_util.is_installed(req): - return - if req in install_failure_history: _LOGGER.info( "Multiple attempts to install %s failed, install will be retried after next configuration check or restart", @@ -188,6 +185,9 @@ async def _async_process_requirements( ) raise RequirementsNotFound(name, [req]) + if pkg_util.is_installed(req): + return + def _install(req: str, kwargs: dict[str, Any]) -> bool: """Install requirement.""" return pkg_util.install_package(req, **kwargs) diff --git a/tests/test_requirements.py b/tests/test_requirements.py index 27ce0e1e742..7e4dba42c2f 100644 --- a/tests/test_requirements.py +++ b/tests/test_requirements.py @@ -213,10 +213,8 @@ async def test_get_integration_with_requirements_pip_install_fails_two_passes(ha assert integration assert integration.domain == "test_component" - assert len(mock_is_installed.mock_calls) == 3 + assert len(mock_is_installed.mock_calls) == 1 assert sorted(mock_call[1][0] for mock_call in mock_is_installed.mock_calls) == [ - "test-comp-after-dep==1.0.0", - "test-comp-dep==1.0.0", "test-comp==1.0.0", ]