Skip to content

Commit 6208dc4

Browse files
authored
V0.3 global config cleanup (#150)
* test precommit * add SAST comments * refactor usage of global_config * cleanup filenames * verify most basic tests pass with log file settings changes * cleanup db filenames little more * bump version * refactor DB models * use dots in event publisher name * optimize based on diff, move logger instances to structlog * redo basicConfig * add some tests
1 parent 2535f8c commit 6208dc4

32 files changed

+451
-278
lines changed

hololinked/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.3.9"
1+
__version__ = "0.3.10"
22

33
from .config import global_config # noqa
44
import hololinked.core # noqa: F401

hololinked/client/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
from ..config import global_config # noqa: F401
12
from .factory import ClientFactory as ClientFactory
23
from .proxy import ObjectProxy as ObjectProxy

hololinked/client/abstractions.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@
2525

2626
import asyncio
2727
import builtins
28-
import logging
2928
import threading
3029

3130
from dataclasses import dataclass
3231
from typing import Any, Callable
3332

33+
import structlog
34+
3435
from ..constants import Operations
3536
from ..td import ActionAffordance, EventAffordance, PropertyAffordance
3637
from ..td.forms import Form
@@ -45,7 +46,7 @@ def __init__(
4546
self,
4647
resource: ActionAffordance,
4748
owner_inst: Any,
48-
logger: logging.Logger,
49+
logger: structlog.stdlib.BoundLogger,
4950
) -> None:
5051
"""
5152
Parameters
@@ -54,7 +55,7 @@ def __init__(
5455
dataclass TD fragment representing the action (must have forms).
5556
owner_inst: Any
5657
instance of the owning consumed Thing or `ObjectProxy`
57-
logger: logging.Logger
58+
logger: structlog.stdlib.BoundLogger
5859
logger instance
5960
"""
6061
self.resource = resource
@@ -172,15 +173,15 @@ class ConsumedThingProperty:
172173
# property get set abstraction
173174
# Dont add doc otherwise __doc__ in slots will conflict with class variable
174175

175-
def __init__(self, resource: PropertyAffordance, owner_inst: Any, logger: logging.Logger) -> None:
176+
def __init__(self, resource: PropertyAffordance, owner_inst: Any, logger: structlog.stdlib.BoundLogger) -> None:
176177
"""
177178
Parameters
178179
----------
179180
resource: PropertyAffordance
180181
dataclass object TD fragment representing the property (must have forms).
181182
owner_inst: Any
182183
instance of the owning consumed Thing or `ObjectProxy`
183-
logger: logging.Logger
184+
logger: structlog.stdlib.BoundLogger
184185
logger instance
185186
"""
186187
self.resource = resource
@@ -320,15 +321,15 @@ class ConsumedThingEvent:
320321
def __init__(
321322
self,
322323
resource: EventAffordance,
323-
logger: logging.Logger,
324+
logger: structlog.stdlib.BoundLogger,
324325
owner_inst: Any,
325326
) -> None:
326327
"""
327328
Parameters
328329
----------
329330
resource: EventAffordance
330331
dataclass object representing the event
331-
logger: logging.Logger
332+
logger: structlog.stdlib.BoundLogger
332333
logger instance
333334
owner_inst: Any
334335
the parent object that owns this event

hololinked/client/factory.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
EventAffordance,
2121
PropertyAffordance,
2222
)
23-
from ..utils import set_global_event_loop_policy, uuid_hex
23+
from ..utils import uuid_hex
2424
from .abstractions import ConsumedThingAction, ConsumedThingEvent, ConsumedThingProperty
2525
from .http.consumed_interactions import HTTPAction, HTTPEvent, HTTPProperty
2626
from .mqtt.consumed_interactions import MQTTConsumer # only one type for now
@@ -35,9 +35,6 @@
3535
)
3636

3737

38-
set_global_event_loop_policy()
39-
40-
4138
class ClientFactory:
4239
"""
4340
An factory class for creating clients to interact with Things over different protocols.
@@ -68,7 +65,7 @@ def zmq(
6865
kwargs:
6966
Additional configuration options:
7067
71-
- `logger`: `logging.Logger`, optional.
68+
- `logger`: `structlog.stdlib.BoundLogger`, optional.
7269
A custom logger instance to use for logging
7370
- `ignore_TD_errors`: `bool`, default `False`.
7471
Whether to ignore errors while fetching the Thing Description (TD)
@@ -204,10 +201,8 @@ def http(self, url: str, **kwargs) -> ObjectProxy:
204201
kwargs:
205202
Additional configuration options:
206203
207-
- `logger`: `logging.Logger`, optional.
204+
- `logger`: `structlog.stdlib.BoundLogger`, optional.
208205
A custom logger instance to use for logging
209-
- `log_level`: `int`, default `logging.INFO`.
210-
The logging level to use for the client (e.g., logging.DEBUG, logging.INFO)
211206
- `ignore_TD_errors`: `bool`, default `False`.
212207
Whether to ignore errors while fetching the Thing Description (TD)
213208
- `skip_interaction_affordances`: `list[str]`, default `[]`.
@@ -220,6 +215,8 @@ def http(self, url: str, **kwargs) -> ObjectProxy:
220215
The timeout for establishing a HTTP connection (in seconds)
221216
- `request_timeout`: `float`, optional, default `60.0`.
222217
The timeout for completing a HTTP request (in seconds)
218+
- `security`: `BasicSecurity`, optional.
219+
The security scheme to use for authentication
223220
- `username`: `str`, optional.
224221
The username for HTTP Basic Authentication
225222
- `password`: `str`, optional.
@@ -378,10 +375,8 @@ def mqtt(
378375
kwargs:
379376
Additional configuration options:
380377
381-
- `logger`: `logging.Logger`, optional.
378+
- `logger`: `structlog.stdlib.BoundLogger`, optional.
382379
A custom logger instance to use for logging
383-
- `log_level`: `int`, default `logging.INFO`.
384-
The logging level to use for the client (e.g., logging.DEBUG, logging.INFO
385380
"""
386381
id = kwargs.get("id", f"mqtt-client|{hostname}:{port}|{uuid_hex()}")
387382
logger = kwargs.get("logger", structlog.get_logger()).bind(

hololinked/client/http/consumed_interactions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import asyncio
66
import contextlib
7-
import logging
87
import threading
98

109
from copy import deepcopy
1110
from typing import Any, AsyncIterator, Callable, Iterator
1211

1312
import httpcore
1413
import httpx
14+
import structlog
1515

1616
from ...constants import Operations
1717
from ...serializers import Serializers
@@ -103,7 +103,7 @@ def __init__(
103103
invokation_timeout: int = 5,
104104
execution_timeout: int = 5,
105105
owner_inst: Any = None,
106-
logger: logging.Logger = None,
106+
logger: structlog.stdlib.BoundLogger = None,
107107
) -> None:
108108
ConsumedThingAction.__init__(self=self, resource=resource, owner_inst=owner_inst, logger=logger)
109109
HTTPConsumedAffordanceMixin.__init__(
@@ -188,7 +188,7 @@ def __init__(
188188
invokation_timeout: int = 5,
189189
execution_timeout: int = 5,
190190
owner_inst: Any = None,
191-
logger: logging.Logger = None,
191+
logger: structlog.stdlib.BoundLogger = None,
192192
) -> None:
193193
ConsumedThingProperty.__init__(self=self, resource=resource, owner_inst=owner_inst, logger=logger)
194194
HTTPConsumedAffordanceMixin.__init__(
@@ -311,7 +311,7 @@ def __init__(
311311
invokation_timeout: int = 5,
312312
execution_timeout: int = 5,
313313
owner_inst: Any = None,
314-
logger: logging.Logger = None,
314+
logger: structlog.stdlib.BoundLogger = None,
315315
) -> None:
316316
ConsumedThingEvent.__init__(self, resource=resource, owner_inst=owner_inst, logger=logger)
317317
HTTPConsumedAffordanceMixin.__init__(

hololinked/client/mqtt/consumed_interactions.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import logging
2-
31
from typing import Any, Callable
42

53
import aiomqtt
4+
import structlog
65

76
from paho.mqtt.client import Client as PahoMQTTClient
87
from paho.mqtt.client import MQTTMessage
@@ -22,7 +21,7 @@ def __init__(
2221
async_client: aiomqtt.Client,
2322
resource: EventAffordance,
2423
qos: int,
25-
logger: logging.Logger,
24+
logger: structlog.stdlib.BoundLogger,
2625
owner_inst: Any,
2726
) -> None:
2827
super().__init__(resource=resource, logger=logger, owner_inst=owner_inst)

hololinked/client/proxy.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ def __init__(self, id: str, **kwargs) -> None:
4848
4949
- `allow_foreign_attributes`: `bool`, default `False`.
5050
allows local attributes for proxy apart from properties fetched from the server.
51-
- `logger`: `logging.Logger`, default `None`.
51+
- `logger`: `structlog.stdlib.BoundLogger`, default `None`.
5252
logger instance
53-
- `log_level`: `int`, default `logging.INFO`.
54-
log level corresponding to logging.Logger when internally created
53+
- `td`: `dict[str, Any]`, default `dict()`.
54+
Thing Description of the consumed thing
55+
- `security`: `BasicSecurity`, optional.
56+
security scheme to be used for authentication
5557
"""
5658
self.id = id
5759
self._allow_foreign_attributes = kwargs.get("allow_foreign_attributes", False)

hololinked/client/zmq/consumed_interactions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import asyncio
2-
import logging
32
import threading
43
import traceback
54
import uuid
65
import warnings
76

87
from typing import Any, Callable
98

9+
import structlog
10+
1011
from ...client.abstractions import (
1112
SSE,
1213
ConsumedThingAction,
@@ -135,7 +136,7 @@ def __init__(
135136
sync_client: SyncZMQClient,
136137
async_client: AsyncZMQClient,
137138
owner_inst: Any,
138-
logger: logging.Logger,
139+
logger: structlog.stdlib.BoundLogger,
139140
**kwargs,
140141
) -> None:
141142
"""
@@ -149,7 +150,7 @@ def __init__(
149150
asynchronous ZMQ client for async calls
150151
owner_inst: Any
151152
the parent object that owns this action
152-
logger: logging.Logger
153+
logger: structlog.stdlib.BoundLogger
153154
logger instance
154155
"""
155156
ConsumedThingAction.__init__(self, resource=resource, owner_inst=owner_inst, logger=logger)
@@ -263,7 +264,7 @@ def __init__(
263264
sync_client: SyncZMQClient,
264265
async_client: AsyncZMQClient,
265266
owner_inst: Any,
266-
logger: logging.Logger,
267+
logger: structlog.stdlib.BoundLogger,
267268
**kwargs,
268269
) -> None:
269270
"""
@@ -277,7 +278,7 @@ def __init__(
277278
asynchronous ZMQ client for async calls
278279
owner_inst: Any
279280
the parent object that owns this property
280-
logger: logging.Logger
281+
logger: structlog.stdlib.BoundLogger
281282
logger instance for logging
282283
"""
283284
ConsumedThingProperty.__init__(self, resource=resource, owner_inst=owner_inst, logger=logger)
@@ -420,7 +421,7 @@ class ZMQEvent(ConsumedThingEvent, ZMQConsumedAffordanceMixin):
420421
def __init__(
421422
self,
422423
resource: EventAffordance,
423-
logger: logging.Logger,
424+
logger: structlog.stdlib.BoundLogger,
424425
owner_inst: Any,
425426
**kwargs,
426427
) -> None:

0 commit comments

Comments
 (0)