Skip to content

Commit 628f87d

Browse files
authored
lazy load Pub/Sub modules (#1160)
1 parent bcd2a5e commit 628f87d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pycsw/broker/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
#
2828
# =================================================================
2929

30+
import importlib
31+
3032
from pycsw.broker.base import BasePubSubClient
31-
from pycsw.broker.mqtt import MQTTPubSubClient
3233

3334

3435
def load_client(def_: dict) -> BasePubSubClient:
@@ -40,11 +41,12 @@ def load_client(def_: dict) -> BasePubSubClient:
4041
:returns: PubSubClient object
4142
"""
4243

43-
class_ = CLIENTS[def_['type']]
44+
module, class_ = CLIENTS[def_['type']].rsplit('.', 1)
45+
module = importlib.import_module(module)
4446

45-
return class_(def_)
47+
return getattr(module, class_)(def_)
4648

4749

4850
CLIENTS = {
49-
'mqtt': MQTTPubSubClient
51+
'mqtt': 'pycsw.broker.mqtt.MQTTPubSubClient'
5052
}

0 commit comments

Comments
 (0)