From b4df977f6f83f83b5628b21c52cc8cdfd8ab7be2 Mon Sep 17 00:00:00 2001 From: Andrew Mirsky Date: Mon, 11 Aug 2025 21:56:30 -0400 Subject: [PATCH] pre 0.11.3 release cleanup (#294) * add warning message for client config to match client config description --- README.md | 20 ++++++++++---------- amqtt/client.py | 2 +- amqtt/contexts.py | 4 +++- amqtt/plugins/manager.py | 2 +- amqtt/scripts/default_client.yaml | 2 +- docs_web/index.md | 20 ++++++++++---------- tests/conftest.py | 13 +++++++------ tests/test_client.py | 14 ++++++++------ 8 files changed, 41 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 6e5673e..86fc92c 100644 --- a/README.md +++ b/README.md @@ -19,16 +19,16 @@ - Client auto-reconnection on network lost - Plugin framework for functionality expansion; included plugins: - - `$SYS` topic publishing - - AWS IOT-style shadow states - - x509 certificate authentication (including cli cert creation) - - Secure file-based password authentication - - Configuration-based topic authorization - - MySQL, Postgres & SQLite user and/or topic auth (including cli manager) - - External server (HTTP) user and/or topic auth - - LDAP user and/or topic auth - - JWT user and/or topic auth - - Fail over session persistence + - `$SYS` topic publishing + - AWS IOT-style shadow states + - x509 certificate authentication (including cli cert creation) + - Secure file-based password authentication + - Configuration-based topic authorization + - MySQL, Postgres & SQLite user and/or topic auth (including cli manager) + - External server (HTTP) user and/or topic auth + - LDAP user and/or topic auth + - JWT user and/or topic auth + - Fail over session persistence ## Installation diff --git a/amqtt/client.py b/amqtt/client.py index 681008e..c9dd62d 100644 --- a/amqtt/client.py +++ b/amqtt/client.py @@ -577,7 +577,7 @@ class MQTTClient: cadata: str | None = None, ) -> Session: """Initialize the MQTT session.""" - broker_conf = self.config.get("broker", {}).copy() + broker_conf = self.config.get("connection", {}).copy() if uri is not None: broker_conf.uri = uri diff --git a/amqtt/contexts.py b/amqtt/contexts.py index 4ba917f..4da2fa1 100644 --- a/amqtt/contexts.py +++ b/amqtt/contexts.py @@ -1,5 +1,6 @@ from dataclasses import dataclass, field, fields, replace import logging +import warnings try: from enum import Enum, StrEnum @@ -335,7 +336,7 @@ class ClientConfig(Dictable): """Upon reconnect, should subscriptions be cleared. Can be overridden by `MQTTClient.connect`""" topics: dict[str, TopicConfig] | None = field(default_factory=dict) """Specify the topics and what flags should be set for messages published to them.""" - broker: ConnectionConfig | None = field(default_factory=ConnectionConfig) + broker: ConnectionConfig | None = None """*Deprecated* Configuration for connecting to the broker. Use `connection` field instead.""" connection: ConnectionConfig = field(default_factory=ConnectionConfig) """Configuration for connecting to the broker. See @@ -357,6 +358,7 @@ class ClientConfig(Dictable): raise ValueError(msg) if self.broker is not None: + warnings.warn("The 'broker' option is deprecated, please use 'connection' instead.", stacklevel=2) self.connection = self.broker if bool(not self.connection.keyfile) ^ bool(not self.connection.certfile): diff --git a/amqtt/plugins/manager.py b/amqtt/plugins/manager.py index eae40ab..157d15a 100644 --- a/amqtt/plugins/manager.py +++ b/amqtt/plugins/manager.py @@ -132,7 +132,7 @@ class PluginManager(Generic[C]): "Loading plugins from EntryPoints is deprecated and will be removed in a future version." " Use `plugins` section of config instead.", DeprecationWarning, - stacklevel=2 + stacklevel=4 ) self._load_ep_plugins(namespace) diff --git a/amqtt/scripts/default_client.yaml b/amqtt/scripts/default_client.yaml index b686f84..60d86de 100644 --- a/amqtt/scripts/default_client.yaml +++ b/amqtt/scripts/default_client.yaml @@ -7,7 +7,7 @@ auto_reconnect: true cleansession: true reconnect_max_interval: 10 reconnect_retries: 2 -broker: +connection: uri: "mqtt://127.0.0.1" plugins: amqtt.plugins.logging_amqtt.PacketLoggerPlugin: diff --git a/docs_web/index.md b/docs_web/index.md index 89adb6c..e7fa1f4 100644 --- a/docs_web/index.md +++ b/docs_web/index.md @@ -11,16 +11,16 @@ - Support QoS 0, QoS 1 and QoS 2 messages flow - Client auto-reconnection on network lost - Plugin framework for functionality expansion; included plugins: - - `$SYS` topic publishing - - AWS IOT-style shadow states - - x509 certificate authentication (including cli cert creation) - - Secure file-based password authentication - - Configuration-based topic authorization - - MySQL, Postgres & SQLite user and/or topic auth (including cli manager) - - External server (HTTP) user and/or topic auth - - LDAP user and/or topic auth - - JWT user and/or topic auth - - Fail over session persistence + - `$SYS` topic publishing + - AWS IOT-style shadow states + - x509 certificate authentication (including cli cert creation) + - Secure file-based password authentication + - Configuration-based topic authorization + - MySQL, Postgres & SQLite user and/or topic auth (including cli manager) + - External server (HTTP) user and/or topic auth + - LDAP user and/or topic auth + - JWT user and/or topic auth + - Fail over session persistence ## Installation diff --git a/tests/conftest.py b/tests/conftest.py index 14fea72..96fe04b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -93,13 +93,14 @@ def mock_plugin_manager(): @pytest.fixture async def broker_fixture(test_config): - broker = Broker(test_config, plugin_namespace="amqtt.test.plugins") - await broker.start() - assert broker.transitions.is_started() - assert broker._sessions == {} - assert "default" in broker._servers + with pytest.warns(DeprecationWarning): + broker = Broker(test_config, plugin_namespace="amqtt.test.plugins") + await broker.start() + assert broker.transitions.is_started() + assert broker._sessions == {} + assert "default" in broker._servers - yield broker + yield broker if not broker.transitions.is_stopped(): await broker.shutdown() diff --git a/tests/test_client.py b/tests/test_client.py index 2c7fea1..6eed5c9 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -256,7 +256,7 @@ def client_config(): } }, "keep_alive": 10, - "broker": { + "connection": { "uri": "mqtt://localhost:1884" }, "reconnect_max_interval": 5, @@ -489,13 +489,15 @@ async def test_client_no_auth(): client = MQTTClient(client_id="client1", config={'auto_reconnect': False}) - broker = Broker(plugin_namespace='tests.mock_plugins', config=config) - await broker.start() + with pytest.warns(DeprecationWarning): - with pytest.raises(ConnectError): - await client.connect("mqtt://127.0.0.1:1883/") + broker = Broker(plugin_namespace='tests.mock_plugins', config=config) + await broker.start() - await broker.shutdown() + with pytest.raises(ConnectError): + await client.connect("mqtt://127.0.0.1:1883/") + + await broker.shutdown() @pytest.mark.asyncio