Skip to content

Commit 6153968

Browse files
authored
Disable profiler.memory service with python 3.11 (#88136)
1 parent 6254200 commit 6153968

File tree

7 files changed

+38
-4
lines changed

7 files changed

+38
-4
lines changed

homeassistant/components/profiler/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from homeassistant.config_entries import ConfigEntry
1616
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_TYPE
1717
from homeassistant.core import HomeAssistant, ServiceCall
18+
from homeassistant.exceptions import HomeAssistantError
1819
import homeassistant.helpers.config_validation as cv
1920
from homeassistant.helpers.event import async_track_time_interval
2021
from homeassistant.helpers.service import async_register_admin_service
@@ -269,6 +270,11 @@ async def _async_generate_memory_profile(hass: HomeAssistant, call: ServiceCall)
269270
# Imports deferred to avoid loading modules
270271
# in memory since usually only one part of this
271272
# integration is used at a time
273+
if sys.version_info >= (3, 11):
274+
raise HomeAssistantError(
275+
"Memory profiling is not supported on Python 3.11. Please use Python 3.10."
276+
)
277+
272278
from guppy import hpy # pylint: disable=import-outside-toplevel
273279

274280
start_time = int(time.time() * 1000000)

homeassistant/components/profiler/manifest.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"config_flow": true,
66
"documentation": "https://www.home-assistant.io/integrations/profiler",
77
"quality_scale": "internal",
8-
"requirements": ["pyprof2calltree==1.4.5", "guppy3==3.1.2", "objgraph==3.5.0"]
8+
"requirements": [
9+
"pyprof2calltree==1.4.5",
10+
"guppy3==3.1.2;python_version<'3.11'",
11+
"objgraph==3.5.0"
12+
]
913
}

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ gspread==5.5.0
849849
gstreamer-player==1.1.2
850850

851851
# homeassistant.components.profiler
852-
guppy3==3.1.2
852+
guppy3==3.1.2;python_version<'3.11'
853853

854854
# homeassistant.components.iaqualink
855855
h2==4.1.0

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ growattServer==1.3.0
644644
gspread==5.5.0
645645

646646
# homeassistant.components.profiler
647-
guppy3==3.1.2
647+
guppy3==3.1.2;python_version<'3.11'
648648

649649
# homeassistant.components.iaqualink
650650
h2==4.1.0

script/hassfest/requirements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def validate_requirements_format(integration: Integration) -> bool:
9090
if not version:
9191
continue
9292

93-
for part in version.split(","):
93+
for part in version.split(";", 1)[0].split(","):
9494
version_part = PIP_VERSION_RANGE_SEPARATOR.match(part)
9595
if (
9696
version_part

tests/components/profiler/test_init.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Test the Profiler config flow."""
22
from datetime import timedelta
33
import os
4+
import sys
45
from unittest.mock import patch
56

67
import pytest
@@ -18,6 +19,7 @@
1819
from homeassistant.components.profiler.const import DOMAIN
1920
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_TYPE
2021
from homeassistant.core import HomeAssistant
22+
from homeassistant.exceptions import HomeAssistantError
2123
import homeassistant.util.dt as dt_util
2224

2325
from tests.common import MockConfigEntry, async_fire_time_changed
@@ -53,6 +55,9 @@ def _mock_path(filename):
5355
await hass.async_block_till_done()
5456

5557

58+
@pytest.mark.skipif(
59+
sys.version_info >= (3, 11), reason="not yet available on python 3.11"
60+
)
5661
async def test_memory_usage(hass: HomeAssistant, tmpdir) -> None:
5762
"""Test we can setup and the service is registered."""
5863
test_dir = tmpdir.mkdir("profiles")
@@ -83,6 +88,24 @@ def _mock_path(filename):
8388
await hass.async_block_till_done()
8489

8590

91+
@pytest.mark.skipif(sys.version_info < (3, 11), reason="still works on python 3.10")
92+
async def test_memory_usage_py311(hass: HomeAssistant, tmpdir) -> None:
93+
"""Test raise an error on python3.11."""
94+
entry = MockConfigEntry(domain=DOMAIN)
95+
entry.add_to_hass(hass)
96+
97+
assert await hass.config_entries.async_setup(entry.entry_id)
98+
await hass.async_block_till_done()
99+
assert hass.services.has_service(DOMAIN, SERVICE_MEMORY)
100+
with pytest.raises(
101+
HomeAssistantError,
102+
match="Memory profiling is not supported on Python 3.11. Please use Python 3.10.",
103+
):
104+
await hass.services.async_call(
105+
DOMAIN, SERVICE_MEMORY, {CONF_SECONDS: 0.000001}, blocking=True
106+
)
107+
108+
86109
async def test_object_growth_logging(
87110
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
88111
) -> None:

tests/hassfest/test_requirements.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def test_validate_requirements_format_ignore_pin_for_custom(integration: Integra
5252
"test_package~=0.5.0",
5353
"test_package>=1.4.2,<1.4.99,>=1.7,<1.8.99",
5454
"test_package>=1.4.2,<1.9,!=1.5",
55+
"test_package>=1.4.2;python_version<'3.11'",
5556
]
5657
integration.path = Path("")
5758
assert validate_requirements_format(integration)

0 commit comments

Comments
 (0)