From c311987741ead1548bc5ab2e410c99c0045b4838 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 26 Sep 2023 23:50:10 +0200 Subject: [PATCH 1/4] Removed `typing.Final` from some of the most commonly used modules. `typing.Final` is not defined on Python < 3.8. --- platypush/builder/_base.py | 4 ++-- platypush/bus/redis.py | 4 ++-- platypush/entities/_base.py | 4 ++-- platypush/plugins/mqtt/_client.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/platypush/builder/_base.py b/platypush/builder/_base.py index 73cf69c8a7..5bc139f479 100644 --- a/platypush/builder/_base.py +++ b/platypush/builder/_base.py @@ -5,7 +5,7 @@ import logging import os import pathlib import sys -from typing import Final, Optional, Sequence +from typing import Optional, Sequence from platypush.config import Config from platypush.utils.manifest import ( @@ -29,7 +29,7 @@ class BaseBuilder(ABC): and :module:`platypush.platydock` modules/scripts. """ - REPO_URL: Final[str] = 'https://github.com/BlackLight/platypush.git' + REPO_URL: str = 'https://github.com/BlackLight/platypush.git' """ We use the Github URL here rather than the self-hosted Gitea URL to prevent too many requests to the Gitea server. diff --git a/platypush/bus/redis.py b/platypush/bus/redis.py index 83ded8aff7..40cd7350fa 100644 --- a/platypush/bus/redis.py +++ b/platypush/bus/redis.py @@ -1,6 +1,6 @@ import logging import threading -from typing import Final, Optional +from typing import Optional from platypush.bus import Bus from platypush.message import Message @@ -13,7 +13,7 @@ class RedisBus(Bus): Overrides the in-process in-memory local bus with a Redis bus """ - DEFAULT_REDIS_QUEUE: Final[str] = 'platypush/bus' + DEFAULT_REDIS_QUEUE: str = 'platypush/bus' def __init__(self, *args, on_message=None, redis_queue=None, **kwargs): from platypush.utils import get_redis diff --git a/platypush/entities/_base.py b/platypush/entities/_base.py index 2a739124a6..cc76450f3c 100644 --- a/platypush/entities/_base.py +++ b/platypush/entities/_base.py @@ -7,7 +7,7 @@ import subprocess import sys import types from datetime import datetime -from typing import Callable, Dict, Final, List, Optional, Set, Type, Tuple, Any +from typing import Callable, Dict, List, Optional, Set, Type, Tuple, Any import pkgutil @@ -41,7 +41,7 @@ EntityKey = Tuple[str, str] EntityMapping = Dict[EntityKey, 'Entity'] """ Internal mapping for entities used for deduplication/merge/upsert. """ -_import_error_ignored_modules: Final[Set[str]] = {'bluetooth'} +_import_error_ignored_modules: Set[str] = {'bluetooth'} """ ImportError exceptions will be ignored for these entity submodules when imported dynamically. An ImportError for these modules means that some optional diff --git a/platypush/plugins/mqtt/_client.py b/platypush/plugins/mqtt/_client.py index 5ef0c9d4d8..a82cd1ba89 100644 --- a/platypush/plugins/mqtt/_client.py +++ b/platypush/plugins/mqtt/_client.py @@ -2,14 +2,14 @@ from enum import IntEnum import logging import os import threading -from typing import Any, Callable, Dict, Final, Iterable, Optional, Union +from typing import Any, Callable, Dict, Iterable, Optional, Union import paho.mqtt.client as mqtt from platypush.config import Config MqttCallback = Callable[["MqttClient", Any, mqtt.MQTTMessage], Any] -DEFAULT_TIMEOUT: Final[int] = 30 +DEFAULT_TIMEOUT: int = 30 class MqttClient(mqtt.Client, threading.Thread): From ca7f042cccdf72e29881e8e92b81242b8c5bd503 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 27 Sep 2023 11:20:10 +0200 Subject: [PATCH 2/4] We shouldn't call dateutil.parser if t has already been deserialized to a datetime. --- platypush/plugins/rss/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/rss/__init__.py b/platypush/plugins/rss/__init__.py index 1ef908c7c8..1db8b34ee0 100644 --- a/platypush/plugins/rss/__init__.py +++ b/platypush/plugins/rss/__init__.py @@ -82,7 +82,9 @@ class RssPlugin(RunnablePlugin): t = var.get(varname) if t: - return dateutil.parser.isoparse(t) + if not isinstance(t, datetime.datetime): + t = dateutil.parser.isoparse(t) + return t return None From b76f141b615ea26362c47d9a472269f6a617ed5d Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 27 Sep 2023 11:23:55 +0200 Subject: [PATCH 3/4] Catch response write errors in the MQTT callback. If the client that forwarded the request is no longer available (either because an exception or a timeout was raised) then its I/O buffer and event loop may be closed. In this case, the response callback should handle and report the exception, and still set the event, so that any other threads waiting for the response can move on. --- platypush/plugins/mqtt/__init__.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/platypush/plugins/mqtt/__init__.py b/platypush/plugins/mqtt/__init__.py index a43c037732..d6dc1dd08e 100644 --- a/platypush/plugins/mqtt/__init__.py +++ b/platypush/plugins/mqtt/__init__.py @@ -479,8 +479,9 @@ class MqttPlugin(RunnablePlugin): client.stop() del client - @staticmethod - def _response_callback(reply_topic: str, event: threading.Event, buffer: IO[bytes]): + def _response_callback( + self, reply_topic: str, event: threading.Event, buffer: IO[bytes] + ): """ A response callback that writes the response to an IOBuffer and stops the client loop. @@ -490,9 +491,15 @@ class MqttPlugin(RunnablePlugin): if msg.topic != reply_topic: return - buffer.write(msg.payload) - client.loop_stop() - event.set() + try: + buffer.write(msg.payload) + client.loop_stop() + except Exception as e: + self.logger.warning( + 'Could not write the response back to the MQTT client: %s', e + ) + finally: + event.set() return on_message From 5025d892beca79ed7e4801d637888d97acc9878c Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 28 Sep 2023 01:25:01 +0200 Subject: [PATCH 4/4] Added install/ subfolders to package_data --- setup.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/setup.py b/setup.py index b9ea662eb0..8919f97061 100755 --- a/setup.py +++ b/setup.py @@ -43,6 +43,11 @@ setup( 'migrations/alembic.ini', 'migrations/alembic/*', 'migrations/alembic/**/*', + 'install/**', + 'install/scripts/*', + 'install/scripts/**/*', + 'install/requirements/*', + 'install/docker/*', ], }, entry_points={