From 0f01ccfa4375b604a76f937ab22237194c99bb1a Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:06:00 +0200 Subject: [PATCH] Update RestrictedPython to 7.0a1.dev0 for 3.12 --- .../components/python_script/__init__.py | 31 +++++++------------ .../components/python_script/manifest.json | 5 ++- requirements_all.txt | 3 ++ requirements_test_all.txt | 3 ++ tests/components/python_script/conftest.py | 5 --- 5 files changed, 22 insertions(+), 25 deletions(-) delete mode 100644 tests/components/python_script/conftest.py diff --git a/homeassistant/components/python_script/__init__.py b/homeassistant/components/python_script/__init__.py index b96f32b71ef50b..10751d28c06658 100644 --- a/homeassistant/components/python_script/__init__.py +++ b/homeassistant/components/python_script/__init__.py @@ -3,9 +3,20 @@ import glob import logging import os -import sys import time +from RestrictedPython import ( + compile_restricted_exec, + limited_builtins, + safe_builtins, + utility_builtins, +) +from RestrictedPython.Eval import default_guarded_getitem +from RestrictedPython.Guards import ( + full_write_guard, + guarded_iter_unpack_sequence, + guarded_unpack_sequence, +) import voluptuous as vol from homeassistant.const import CONF_DESCRIPTION, CONF_NAME, SERVICE_RELOAD @@ -18,20 +29,6 @@ import homeassistant.util.dt as dt_util from homeassistant.util.yaml.loader import load_yaml -if sys.version_info < (3, 12): - from RestrictedPython import ( - compile_restricted_exec, - limited_builtins, - safe_builtins, - utility_builtins, - ) - from RestrictedPython.Eval import default_guarded_getitem - from RestrictedPython.Guards import ( - full_write_guard, - guarded_iter_unpack_sequence, - guarded_unpack_sequence, - ) - _LOGGER = logging.getLogger(__name__) DOMAIN = "python_script" @@ -85,10 +82,6 @@ class ScriptError(HomeAssistantError): def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Initialize the Python script component.""" - if sys.version_info >= (3, 12): - raise HomeAssistantError( - "Python Scripts is not supported on Python 3.12. Please use Python 3.11." - ) path = hass.config.path(FOLDER) if not os.path.isdir(path): diff --git a/homeassistant/components/python_script/manifest.json b/homeassistant/components/python_script/manifest.json index 00e43b5d260b76..bd034053a346d1 100644 --- a/homeassistant/components/python_script/manifest.json +++ b/homeassistant/components/python_script/manifest.json @@ -5,5 +5,8 @@ "documentation": "https://www.home-assistant.io/integrations/python_script", "loggers": ["RestrictedPython"], "quality_scale": "internal", - "requirements": ["RestrictedPython==6.2;python_version<'3.12'"] + "requirements": [ + "RestrictedPython==6.2;python_version<'3.12'", + "RestrictedPython==7.0a1.dev0;python_version>='3.12'" + ] } diff --git a/requirements_all.txt b/requirements_all.txt index 6ee1b939123eca..531d7752200314 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -124,6 +124,9 @@ RachioPy==1.0.3 # homeassistant.components.python_script RestrictedPython==6.2;python_version<'3.12' +# homeassistant.components.python_script +RestrictedPython==7.0a1.dev0;python_version>='3.12' + # homeassistant.components.remember_the_milk RtmAPI==0.7.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 834af20db776f6..099c9d7a29a065 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -111,6 +111,9 @@ RachioPy==1.0.3 # homeassistant.components.python_script RestrictedPython==6.2;python_version<'3.12' +# homeassistant.components.python_script +RestrictedPython==7.0a1.dev0;python_version>='3.12' + # homeassistant.components.remember_the_milk RtmAPI==0.7.2 diff --git a/tests/components/python_script/conftest.py b/tests/components/python_script/conftest.py deleted file mode 100644 index 05a518ad7f3bb2..00000000000000 --- a/tests/components/python_script/conftest.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Skip test collection for Python 3.12.""" -import sys - -if sys.version_info >= (3, 12): - collect_ignore_glob = ["test_*.py"]