Avoid checking if a package is installed if it already failed (#56698)

This commit is contained in:
J. Nick Koston 2021-09-27 00:32:25 -05:00 committed by GitHub
parent 01bd3ff138
commit 0fce9f39b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View file

@ -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)

View file

@ -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",
]