From 61d203235183f498caf14ef4047c98ca760959f6 Mon Sep 17 00:00:00 2001 From: spacemanspiff2007 <10754716+spacemanspiff2007@users.noreply.github.com> Date: Thu, 23 Nov 2023 07:49:15 +0100 Subject: [PATCH] 23.11.0 --- .github/workflows/run-tox.yml | 2 +- .ruff.toml | 4 ++- readme.md | 3 +- requirements.txt | 2 +- requirements_setup.txt | 6 ++-- src/HABApp/__check_dependency_packages__.py | 9 +++--- src/HABApp/__debug_info__.py | 6 ++-- src/HABApp/__version__.py | 2 +- src/HABApp/core/events/filter/event.py | 7 ++-- src/HABApp/openhab/item_to_reg.py | 1 + src/HABApp/openhab/map_events.py | 3 +- src/HABApp/openhab/process_events.py | 32 +++++++++++++------ src/HABApp/rule/interfaces/rule_subprocess.py | 22 +++++++------ tox.ini | 4 +-- 14 files changed, 64 insertions(+), 39 deletions(-) diff --git a/.github/workflows/run-tox.yml b/.github/workflows/run-tox.yml index 17106d8b..e8048b93 100644 --- a/.github/workflows/run-tox.yml +++ b/.github/workflows/run-tox.yml @@ -20,7 +20,7 @@ jobs: strategy: max-parallel: 4 matrix: - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v3 diff --git a/.ruff.toml b/.ruff.toml index 62b8a2f8..29f7cd3b 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -43,7 +43,9 @@ select = [ ignore = [ "RET501", # https://docs.astral.sh/ruff/rules/unnecessary-return-none/#unnecessary-return-none-ret501 - "TRY400" # https://docs.astral.sh/ruff/rules/error-instead-of-exception/ + "TRY400", # https://docs.astral.sh/ruff/rules/error-instead-of-exception/ + + "A003", # https://docs.astral.sh/ruff/rules/builtin-attribute-shadowing/ ] diff --git a/readme.md b/readme.md index 2be59a51..0662d034 100644 --- a/readme.md +++ b/readme.md @@ -127,9 +127,10 @@ MyOpenhabRule() ``` # Changelog -#### 23.XX.X (2023-XX-XX) +#### 23.11.1 (2023-11-23) - Fix for very small float values (#425) - Fix for writing to persistence (#424) +- Updated dependencies #### 23.09.2 (2023-09-24) - Made channel type on a ``Thing`` optional (#416) diff --git a/requirements.txt b/requirements.txt index e3a28bec..9bcc4000 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ # Packages for source formatting # ----------------------------------------------------------------------------- pre-commit >= 3.5, < 3.6 -ruff >= 0.1.5, < 0.2 +ruff >= 0.1.6, < 0.2 # ----------------------------------------------------------------------------- # Packages for other developement tasks diff --git a/requirements_setup.txt b/requirements_setup.txt index 10aeb19d..9251d495 100644 --- a/requirements_setup.txt +++ b/requirements_setup.txt @@ -1,5 +1,5 @@ -aiohttp == 3.8.6 -pydantic == 2.5.0 +aiohttp == 3.9.0 +pydantic == 2.5.2 msgspec == 0.18.4 pendulum == 2.1.2 bidict == 0.22.1 @@ -13,7 +13,7 @@ easyconfig == 0.3.1 stack_data == 0.6.3 colorama == 0.4.6 -voluptuous == 0.14.0 +voluptuous == 0.14.1 typing-extensions == 4.8.0 diff --git a/src/HABApp/__check_dependency_packages__.py b/src/HABApp/__check_dependency_packages__.py index 083c4ed7..dad27f87 100644 --- a/src/HABApp/__check_dependency_packages__.py +++ b/src/HABApp/__check_dependency_packages__.py @@ -1,11 +1,12 @@ +from __future__ import annotations + import importlib import sys -from typing import List, Dict from HABApp.__debug_info__ import print_debug_info -def get_dependencies() -> List[str]: +def get_dependencies() -> list[str]: return [ 'aiohttp-sse-client', 'aiohttp', @@ -31,7 +32,7 @@ def get_dependencies() -> List[str]: def check_dependency_packages(): """Imports all dependencies and reports failures""" - missing: Dict[str, ModuleNotFoundError] = {} + missing: dict[str, ModuleNotFoundError] = {} # Package aliases (if the import name differs from the package name) alias = { @@ -43,7 +44,7 @@ def check_dependency_packages(): for name in get_dependencies(): try: importlib.import_module(alias.get(name, name)) - except ModuleNotFoundError as e: + except ModuleNotFoundError as e: # noqa: PERF203 missing[name] = e if not missing: diff --git a/src/HABApp/__debug_info__.py b/src/HABApp/__debug_info__.py index 29234062..e39d69f1 100644 --- a/src/HABApp/__debug_info__.py +++ b/src/HABApp/__debug_info__.py @@ -1,10 +1,10 @@ import platform import sys + from HABApp.__version__ import __version__ def get_debug_info() -> str: - info = { 'HABApp': __version__, 'Platform': platform.platform(), @@ -12,7 +12,7 @@ def get_debug_info() -> str: 'Python': sys.version, } - indent = max(map(lambda x: len(x), info)) + indent = max(len(x) for x in info) ret = '\n'.join('{:{indent}s}: {:s}'.format(k, str(v).replace('\n', ''), indent=indent) for k, v in info.items()) try: @@ -26,7 +26,7 @@ def get_debug_info() -> str: ret += f'\n\nInstalled Packages\n{"-" * 80}\n{table}' except Exception as e: - ret += f'\n\nCould not get installed Packages!\nError: {str(e)}' + ret += f'\n\nCould not get installed Packages!\nError: {e!s}' return ret diff --git a/src/HABApp/__version__.py b/src/HABApp/__version__.py index f87e0f46..3bd0717c 100644 --- a/src/HABApp/__version__.py +++ b/src/HABApp/__version__.py @@ -10,4 +10,4 @@ # Development versions contain the DEV-COUNTER postfix: # - 23.09.0.DEV-1 -__version__ = '23.09.2' +__version__ = '23.11.0' diff --git a/src/HABApp/core/events/filter/event.py b/src/HABApp/core/events/filter/event.py index 1bfb57f5..756d5b3e 100644 --- a/src/HABApp/core/events/filter/event.py +++ b/src/HABApp/core/events/filter/event.py @@ -1,6 +1,6 @@ from inspect import isclass from typing import Final, Optional -from typing import get_type_hints as _get_type_hints +from typing import get_type_hints as typing_get_type_hints from HABApp.core.const import MISSING from HABApp.core.const.hints import TYPE_ANY_CLASS_TYPE @@ -22,7 +22,7 @@ def __init__(self, event_class: TYPE_ANY_CLASS_TYPE, **kwargs): self.attr_name2: Optional[str] = None self.attr_value2 = None - type_hints = _get_type_hints(event_class) + type_hints = typing_get_type_hints(event_class) for arg, value in kwargs.items(): if value is MISSING: @@ -39,7 +39,8 @@ def __init__(self, event_class: TYPE_ANY_CLASS_TYPE, **kwargs): self.attr_name2 = arg self.attr_value2 = value else: - raise ValueError('Not implemented for more than 2 values!') + msg = 'Not implemented for more than 2 values!' + raise ValueError(msg) def trigger(self, event) -> bool: if not isinstance(event, self.event_class): diff --git a/src/HABApp/openhab/item_to_reg.py b/src/HABApp/openhab/item_to_reg.py index 58c4ac7b..d1050604 100644 --- a/src/HABApp/openhab/item_to_reg.py +++ b/src/HABApp/openhab/item_to_reg.py @@ -48,6 +48,7 @@ def add_to_registry(item: 'HABApp.openhab.items.OpenhabItem', set_value=False): # Replace existing item with the updated definition Items.pop_item(name) Items.add_item(item) + return None def remove_from_registry(name: str): diff --git a/src/HABApp/openhab/map_events.py b/src/HABApp/openhab/map_events.py index c0dd6ec5..e685318b 100644 --- a/src/HABApp/openhab/map_events.py +++ b/src/HABApp/openhab/map_events.py @@ -43,4 +43,5 @@ def get_event(_in_dict: dict) -> OpenhabEvent: try: return _events[event_type].from_dict(topic, payload) except KeyError: - raise ValueError(f'Unknown Event: {event_type:s} for {_in_dict}') + msg = f'Unknown Event: {event_type:s} for {_in_dict}' + raise ValueError(msg) from None diff --git a/src/HABApp/openhab/process_events.py b/src/HABApp/openhab/process_events.py index 56ff51de..415d7179 100644 --- a/src/HABApp/openhab/process_events.py +++ b/src/HABApp/openhab/process_events.py @@ -1,23 +1,37 @@ import logging -from asyncio import create_task from typing import Union import HABApp import HABApp.core import HABApp.openhab.events +from HABApp.core.asyncio import create_task from HABApp.core.errors import ItemNotFoundException -from HABApp.core.events import ValueUpdateEvent, ValueChangeEvent -from HABApp.core.internals import uses_post_event, uses_get_item +from HABApp.core.events import ValueChangeEvent, ValueUpdateEvent +from HABApp.core.internals import uses_get_item, uses_post_event from HABApp.core.logger import log_warning from HABApp.core.wrapper import process_exception -from HABApp.openhab.definitions.topics import TOPIC_THINGS, TOPIC_ITEMS -from HABApp.openhab.events import GroupStateChangedEvent, GroupStateUpdatedEvent, \ - ItemAddedEvent, ItemRemovedEvent, ItemUpdatedEvent, \ - ThingStatusInfoEvent, ThingAddedEvent, ThingRemovedEvent, ThingUpdatedEvent, ThingConfigStatusInfoEvent -from HABApp.openhab.item_to_reg import add_to_registry, remove_from_registry, remove_thing_from_registry, \ - add_thing_to_registry +from HABApp.openhab.definitions.topics import TOPIC_ITEMS, TOPIC_THINGS +from HABApp.openhab.events import ( + GroupStateChangedEvent, + GroupStateUpdatedEvent, + ItemAddedEvent, + ItemRemovedEvent, + ItemUpdatedEvent, + ThingAddedEvent, + ThingConfigStatusInfoEvent, + ThingRemovedEvent, + ThingStatusInfoEvent, + ThingUpdatedEvent, +) +from HABApp.openhab.item_to_reg import ( + add_thing_to_registry, + add_to_registry, + remove_from_registry, + remove_thing_from_registry, +) from HABApp.openhab.map_events import get_event + log = logging.getLogger('HABApp.openhab.items') post_event = uses_post_event() diff --git a/src/HABApp/rule/interfaces/rule_subprocess.py b/src/HABApp/rule/interfaces/rule_subprocess.py index aae902ac..4d04f5a0 100644 --- a/src/HABApp/rule/interfaces/rule_subprocess.py +++ b/src/HABApp/rule/interfaces/rule_subprocess.py @@ -2,7 +2,7 @@ import logging import os from pathlib import Path -from typing import Optional, Union, Iterable, Any, Tuple, Dict, List, Callable +from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union from typing_extensions import TypeAlias @@ -10,6 +10,7 @@ from HABApp.core.logger import HABAppError, HABAppWarning from HABApp.core.wrapper import process_exception + log = logging.getLogger('HABApp.execute') HINT_EXEC_ARGS: TypeAlias = Union[str, Path] @@ -28,10 +29,12 @@ def _ensure_str_objs(objs: Iterable[HINT_EXEC_ARGS], key: str, enforce_abs=False path_val = Path(val) str_val = val else: - raise ValueError(f'{key:s}[{i:d}] is not of type str! "{val}" ({type(val).__name__:s})') + msg = f'{key:s}[{i:d}] is not of type str! "{val}" ({type(val).__name__:s})' + raise TypeError(msg) if enforce_abs and not path_val.is_absolute(): - raise ValueError(f'{key:s}[{i:d}] is not an absolute path: "{val}"') + msg = f'{key:s}[{i:d}] is not an absolute path: "{val}"' + raise ValueError(msg) new_args.append(str_val) @@ -42,20 +45,22 @@ def build_exec_params(*args: HINT_EXEC_ARGS, _capture_output=True, _additional_python_path: HINT_PYTHON_PATH = None, **kwargs: Any) -> Tuple[Iterable[str], Dict[str, Any]]: - # convenience for easy capturing if _capture_output: if 'stdout' in kwargs: - raise ValueError('Parameter "capture_output" can not be used with "stdout" in kwargs!') + msg = 'Parameter "capture_output" can not be used with "stdout" in kwargs!' + raise ValueError(msg) kwargs['stdout'] = asyncio.subprocess.PIPE if 'stderr' in kwargs: - raise ValueError('Parameter "capture_output" can not be used with "stderr" in kwargs!') + msg = 'Parameter "capture_output" can not be used with "stderr" in kwargs!' + raise ValueError(msg) kwargs['stderr'] = asyncio.subprocess.PIPE # convenience for additional libraries if _additional_python_path is not None: if 'env' in kwargs: - raise ValueError('Parameter "additional_python_path" can not be used with "env" in kwargs!') + msg = 'Parameter "additional_python_path" can not be used with "env" in kwargs!' + raise ValueError(msg) ppath = _ensure_str_objs(_additional_python_path, 'additional_python_path', enforce_abs=True) @@ -104,7 +109,6 @@ def __eq__(self, other): async def async_subprocess_exec(callback, *args, calling_func, raw_info: bool, **kwargs): - call_str = '' try: @@ -113,7 +117,7 @@ async def async_subprocess_exec(callback, *args, calling_func, raw_info: bool, * stdout = None stderr = None - call_str = ' '.join(map(lambda x: f'"{x}"', args)) + call_str = ' '.join(f'"{x}"' for x in args) try: proc = await asyncio.create_subprocess_exec(*args, **kwargs) diff --git a/tox.ini b/tox.ini index c9385b16..05482857 100644 --- a/tox.ini +++ b/tox.ini @@ -5,17 +5,17 @@ envlist = py39 py310 py311 + py312 docs - [gh-actions] python = 3.8: py38 3.9: py39 3.10: py310, flake, docs 3.11: py311 - + 3.11: py312 [testenv]