From a6a47c0b4426b034c79bcafe34f3a9ce89fd7933 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 15 Apr 2024 14:06:59 -0500 Subject: [PATCH] Make aiohttp_cors a top level import (#115563) * Make aiohttp_cors a top level import This was moved to a late import in #27935 but there is no longer any need to import it late in the event loop as aiohttp_cors is listed in pyproject.toml so it will always be available * drop requirements as they are all top level now * drop requirements as they are all top level now * adjust --- homeassistant/components/emulated_hue/manifest.json | 3 +-- homeassistant/components/http/cors.py | 6 +----- homeassistant/components/http/manifest.json | 7 +------ requirements_all.txt | 10 ---------- requirements_test_all.txt | 10 ---------- tests/test_requirements.py | 9 ++++----- 6 files changed, 7 insertions(+), 38 deletions(-) diff --git a/homeassistant/components/emulated_hue/manifest.json b/homeassistant/components/emulated_hue/manifest.json index ff3591e0066..14baa5b5d04 100644 --- a/homeassistant/components/emulated_hue/manifest.json +++ b/homeassistant/components/emulated_hue/manifest.json @@ -6,6 +6,5 @@ "dependencies": ["network"], "documentation": "https://www.home-assistant.io/integrations/emulated_hue", "iot_class": "local_push", - "quality_scale": "internal", - "requirements": ["aiohttp_cors==0.7.0"] + "quality_scale": "internal" } diff --git a/homeassistant/components/http/cors.py b/homeassistant/components/http/cors.py index ebae2480589..d97ac9922a2 100644 --- a/homeassistant/components/http/cors.py +++ b/homeassistant/components/http/cors.py @@ -13,6 +13,7 @@ from aiohttp.web_urldispatcher import ( ResourceRoute, StaticResource, ) +import aiohttp_cors from homeassistant.const import HTTP_HEADER_X_REQUESTED_WITH from homeassistant.core import callback @@ -35,11 +36,6 @@ VALID_CORS_TYPES: Final = (Resource, ResourceRoute, StaticResource) @callback def setup_cors(app: Application, origins: list[str]) -> None: """Set up CORS.""" - # This import should remain here. That way the HTTP integration can always - # be imported by other integrations without it's requirements being installed. - # pylint: disable-next=import-outside-toplevel - import aiohttp_cors - cors = aiohttp_cors.setup( app, defaults={ diff --git a/homeassistant/components/http/manifest.json b/homeassistant/components/http/manifest.json index 647b7e42a3a..fb804251edc 100644 --- a/homeassistant/components/http/manifest.json +++ b/homeassistant/components/http/manifest.json @@ -5,10 +5,5 @@ "documentation": "https://www.home-assistant.io/integrations/http", "integration_type": "system", "iot_class": "local_push", - "quality_scale": "internal", - "requirements": [ - "aiohttp_cors==0.7.0", - "aiohttp-fast-url-dispatcher==0.3.0", - "aiohttp-zlib-ng==0.3.1" - ] + "quality_scale": "internal" } diff --git a/requirements_all.txt b/requirements_all.txt index 67d731ab587..be4e0d16451 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -262,16 +262,6 @@ aioharmony==0.2.10 # homeassistant.components.homekit_controller aiohomekit==3.1.5 -# homeassistant.components.http -aiohttp-fast-url-dispatcher==0.3.0 - -# homeassistant.components.http -aiohttp-zlib-ng==0.3.1 - -# homeassistant.components.emulated_hue -# homeassistant.components.http -aiohttp_cors==0.7.0 - # homeassistant.components.hue aiohue==4.7.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5de1f7f5164..5f471c4d7a0 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -238,16 +238,6 @@ aioharmony==0.2.10 # homeassistant.components.homekit_controller aiohomekit==3.1.5 -# homeassistant.components.http -aiohttp-fast-url-dispatcher==0.3.0 - -# homeassistant.components.http -aiohttp-zlib-ng==0.3.1 - -# homeassistant.components.emulated_hue -# homeassistant.components.http -aiohttp_cors==0.7.0 - # homeassistant.components.hue aiohue==4.7.1 diff --git a/tests/test_requirements.py b/tests/test_requirements.py index ed04ef8649b..73f3f54c3c4 100644 --- a/tests/test_requirements.py +++ b/tests/test_requirements.py @@ -591,7 +591,7 @@ async def test_discovery_requirements_mqtt(hass: HomeAssistant) -> None: ) as mock_process: await async_get_integration_with_requirements(hass, "mqtt_comp") - assert len(mock_process.mock_calls) == 2 # mqtt also depends on http + assert len(mock_process.mock_calls) == 1 assert mock_process.mock_calls[0][1][1] == mqtt.requirements @@ -608,13 +608,12 @@ async def test_discovery_requirements_ssdp(hass: HomeAssistant) -> None: ) as mock_process: await async_get_integration_with_requirements(hass, "ssdp_comp") - assert len(mock_process.mock_calls) == 4 + assert len(mock_process.mock_calls) == 3 assert mock_process.mock_calls[0][1][1] == ssdp.requirements assert { mock_process.mock_calls[1][1][0], mock_process.mock_calls[2][1][0], - mock_process.mock_calls[3][1][0], - } == {"http", "network", "recorder"} + } == {"network", "recorder"} @pytest.mark.parametrize( @@ -638,7 +637,7 @@ async def test_discovery_requirements_zeroconf( ) as mock_process: await async_get_integration_with_requirements(hass, "comp") - assert len(mock_process.mock_calls) == 4 # zeroconf also depends on http + assert len(mock_process.mock_calls) == 3 assert mock_process.mock_calls[0][1][1] == zeroconf.requirements