Skip to content

Disable profiler.memory service with python 3.11 #88136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions homeassistant/components/profiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_TYPE
from homeassistant.core import HomeAssistant, ServiceCall
from homeassistant.exceptions import HomeAssistantError
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import async_track_time_interval
from homeassistant.helpers.service import async_register_admin_service
Expand Down Expand Up @@ -269,6 +270,11 @@ async def _async_generate_memory_profile(hass: HomeAssistant, call: ServiceCall)
# Imports deferred to avoid loading modules
# in memory since usually only one part of this
# integration is used at a time
if sys.version_info >= (3, 11):
raise HomeAssistantError(
"Memory profiling is not supported on Python 3.11. Please use Python 3.10."
)

from guppy import hpy # pylint: disable=import-outside-toplevel

start_time = int(time.time() * 1000000)
Expand Down
6 changes: 5 additions & 1 deletion homeassistant/components/profiler/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/profiler",
"quality_scale": "internal",
"requirements": ["pyprof2calltree==1.4.5", "guppy3==3.1.2", "objgraph==3.5.0"]
"requirements": [
"pyprof2calltree==1.4.5",
"guppy3==3.1.2;python_version<'3.11'",
"objgraph==3.5.0"
]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ gspread==5.5.0
gstreamer-player==1.1.2

# homeassistant.components.profiler
guppy3==3.1.2
guppy3==3.1.2;python_version<'3.11'

# homeassistant.components.iaqualink
h2==4.1.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ growattServer==1.3.0
gspread==5.5.0

# homeassistant.components.profiler
guppy3==3.1.2
guppy3==3.1.2;python_version<'3.11'

# homeassistant.components.iaqualink
h2==4.1.0
Expand Down
2 changes: 1 addition & 1 deletion script/hassfest/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def validate_requirements_format(integration: Integration) -> bool:
if not version:
continue

for part in version.split(","):
for part in version.split(";", 1)[0].split(","):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can break this out into another PR if desirable but left here initially for context

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is OK I think 👍

version_part = PIP_VERSION_RANGE_SEPARATOR.match(part)
if (
version_part
Expand Down
23 changes: 23 additions & 0 deletions tests/components/profiler/test_init.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Test the Profiler config flow."""
from datetime import timedelta
import os
import sys
from unittest.mock import patch

import pytest
Expand All @@ -18,6 +19,7 @@
from homeassistant.components.profiler.const import DOMAIN
from homeassistant.const import CONF_SCAN_INTERVAL, CONF_TYPE
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError
import homeassistant.util.dt as dt_util

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


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


@pytest.mark.skipif(sys.version_info < (3, 11), reason="still works on python 3.10")
async def test_memory_usage_py311(hass: HomeAssistant, tmpdir) -> None:
"""Test raise an error on python3.11."""
entry = MockConfigEntry(domain=DOMAIN)
entry.add_to_hass(hass)

assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert hass.services.has_service(DOMAIN, SERVICE_MEMORY)
with pytest.raises(
HomeAssistantError,
match="Memory profiling is not supported on Python 3.11. Please use Python 3.10.",
):
await hass.services.async_call(
DOMAIN, SERVICE_MEMORY, {CONF_SECONDS: 0.000001}, blocking=True
)


async def test_object_growth_logging(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/hassfest/test_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_validate_requirements_format_ignore_pin_for_custom(integration: Integra
"test_package~=0.5.0",
"test_package>=1.4.2,<1.4.99,>=1.7,<1.8.99",
"test_package>=1.4.2,<1.9,!=1.5",
"test_package>=1.4.2;python_version<'3.11'",
]
integration.path = Path("")
assert validate_requirements_format(integration)
Expand Down