datastreamcorelib 1.6.0__tar.gz → 1.7.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/PKG-INFO +13 -15
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/README.rst +6 -6
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/pyproject.toml +22 -37
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/__init__.py +2 -1
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/abstract.py +1 -0
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/binpackers.py +1 -0
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/datamessage.py +24 -4
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/imagemessage.py +1 -0
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/logging.py +1 -0
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/pubsub.py +2 -1
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/reqrep.py +50 -21
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/testhelpers.py +1 -0
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/utils.py +1 -0
- datastreamcorelib-1.6.0/setup.py +0 -38
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/LICENSE +0 -0
- {datastreamcorelib-1.6.0 → datastreamcorelib-1.7.0}/src/datastreamcorelib/py.typed +0 -0
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
2
|
Name: datastreamcorelib
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7.0
|
|
4
4
|
Summary: Helpers and utilities for https://gitlab.com/advian-oss/python-datastreamservicelib that are not eventloop specific.
|
|
5
|
-
Home-page: https://gitlab.com/advian-oss/python-datastreamcorelib/
|
|
6
5
|
License: MIT
|
|
7
6
|
Author: Eero af Heurlin
|
|
8
7
|
Author-email: eero.afheurlin@iki.fi
|
|
9
|
-
Requires-Python: >=3.
|
|
8
|
+
Requires-Python: >=3.9,<4.0
|
|
10
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
11
10
|
Classifier: Programming Language :: Python :: 3
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
15
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
-
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
16
|
Requires-Dist: libadvian (>=0.3,<=2.0)
|
|
18
17
|
Requires-Dist: msgpack (>=1.0,<2.0)
|
|
19
|
-
Project-URL: Repository, https://gitlab.com/advian-oss/python-datastreamcorelib/
|
|
20
18
|
Description-Content-Type: text/x-rst
|
|
21
19
|
|
|
22
20
|
=================
|
|
@@ -68,7 +66,7 @@ pre-commit considerations
|
|
|
68
66
|
|
|
69
67
|
If working in Docker instead of native env you need to run the pre-commit checks in docker too::
|
|
70
68
|
|
|
71
|
-
docker exec -i datastreamcorelib_devel /bin/bash -c "pre-commit install"
|
|
69
|
+
docker exec -i datastreamcorelib_devel /bin/bash -c "pre-commit install --install-hooks"
|
|
72
70
|
docker exec -i datastreamcorelib_devel /bin/bash -c "pre-commit run --all-files"
|
|
73
71
|
|
|
74
72
|
You need to have the container running, see above. Or alternatively use the docker run syntax but using
|
|
@@ -96,9 +94,9 @@ Local Development
|
|
|
96
94
|
|
|
97
95
|
TLDR:
|
|
98
96
|
|
|
99
|
-
- Create and activate a Python 3.
|
|
97
|
+
- Create and activate a Python 3.9 virtualenv (assuming virtualenvwrapper)::
|
|
100
98
|
|
|
101
|
-
mkvirtualenv -p `which python3.
|
|
99
|
+
mkvirtualenv -p `which python3.9` my_virtualenv
|
|
102
100
|
|
|
103
101
|
- change to a branch::
|
|
104
102
|
|
|
@@ -108,14 +106,14 @@ TLDR:
|
|
|
108
106
|
- Install project deps and pre-commit hooks::
|
|
109
107
|
|
|
110
108
|
poetry install
|
|
111
|
-
pre-commit install
|
|
109
|
+
pre-commit install --install-hooks
|
|
112
110
|
pre-commit run --all-files
|
|
113
111
|
|
|
114
112
|
- Ready to go.
|
|
115
113
|
|
|
116
|
-
Use Python 3.
|
|
114
|
+
Use Python 3.9 for development since it's the lowest supported version so you don't accidentally
|
|
117
115
|
use features only available in higher versions and then have to re-do everything when CI tests fail
|
|
118
|
-
on 3.
|
|
116
|
+
on 3.9.
|
|
119
117
|
|
|
120
118
|
Remember to activate your virtualenv whenever working on the repo, this is needed
|
|
121
119
|
because pylint and mypy pre-commit hooks use the "system" python for now (because reasons).
|
|
@@ -47,7 +47,7 @@ pre-commit considerations
|
|
|
47
47
|
|
|
48
48
|
If working in Docker instead of native env you need to run the pre-commit checks in docker too::
|
|
49
49
|
|
|
50
|
-
docker exec -i datastreamcorelib_devel /bin/bash -c "pre-commit install"
|
|
50
|
+
docker exec -i datastreamcorelib_devel /bin/bash -c "pre-commit install --install-hooks"
|
|
51
51
|
docker exec -i datastreamcorelib_devel /bin/bash -c "pre-commit run --all-files"
|
|
52
52
|
|
|
53
53
|
You need to have the container running, see above. Or alternatively use the docker run syntax but using
|
|
@@ -75,9 +75,9 @@ Local Development
|
|
|
75
75
|
|
|
76
76
|
TLDR:
|
|
77
77
|
|
|
78
|
-
- Create and activate a Python 3.
|
|
78
|
+
- Create and activate a Python 3.9 virtualenv (assuming virtualenvwrapper)::
|
|
79
79
|
|
|
80
|
-
mkvirtualenv -p `which python3.
|
|
80
|
+
mkvirtualenv -p `which python3.9` my_virtualenv
|
|
81
81
|
|
|
82
82
|
- change to a branch::
|
|
83
83
|
|
|
@@ -87,14 +87,14 @@ TLDR:
|
|
|
87
87
|
- Install project deps and pre-commit hooks::
|
|
88
88
|
|
|
89
89
|
poetry install
|
|
90
|
-
pre-commit install
|
|
90
|
+
pre-commit install --install-hooks
|
|
91
91
|
pre-commit run --all-files
|
|
92
92
|
|
|
93
93
|
- Ready to go.
|
|
94
94
|
|
|
95
|
-
Use Python 3.
|
|
95
|
+
Use Python 3.9 for development since it's the lowest supported version so you don't accidentally
|
|
96
96
|
use features only available in higher versions and then have to re-do everything when CI tests fail
|
|
97
|
-
on 3.
|
|
97
|
+
on 3.9.
|
|
98
98
|
|
|
99
99
|
Remember to activate your virtualenv whenever working on the repo, this is needed
|
|
100
100
|
because pylint and mypy pre-commit hooks use the "system" python for now (because reasons).
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
[
|
|
1
|
+
[project]
|
|
2
2
|
name = "datastreamcorelib"
|
|
3
|
-
version = "1.
|
|
3
|
+
version = "1.7.0"
|
|
4
4
|
description = "Helpers and utilities for https://gitlab.com/advian-oss/python-datastreamservicelib that are not eventloop specific."
|
|
5
|
-
authors = ["Eero af Heurlin
|
|
5
|
+
authors = [{name="Eero af Heurlin", email="eero.afheurlin@iki.fi" }]
|
|
6
6
|
homepage = "https://gitlab.com/advian-oss/python-datastreamcorelib/"
|
|
7
7
|
repository = "https://gitlab.com/advian-oss/python-datastreamcorelib/"
|
|
8
8
|
license = "MIT"
|
|
9
9
|
readme = "README.rst"
|
|
10
|
+
dynamic = ["dependencies", "requires-python"]
|
|
10
11
|
|
|
11
12
|
[tool.black]
|
|
12
13
|
line-length = 120
|
|
13
|
-
target-version = ['
|
|
14
|
+
target-version = ['py311']
|
|
14
15
|
exclude = '''
|
|
15
16
|
(
|
|
16
17
|
/(
|
|
@@ -33,6 +34,8 @@ exclude = '''
|
|
|
33
34
|
junit_family="xunit2"
|
|
34
35
|
addopts="--cov=datastreamcorelib --cov-fail-under=65 --cov-branch"
|
|
35
36
|
asyncio_mode="strict"
|
|
37
|
+
asyncio_default_fixture_loop_scope="function"
|
|
38
|
+
|
|
36
39
|
|
|
37
40
|
[tool.pylint.format]
|
|
38
41
|
max-line-length = 120
|
|
@@ -49,43 +52,25 @@ omit = ["tests/*"]
|
|
|
49
52
|
branch = true
|
|
50
53
|
|
|
51
54
|
[tool.poetry.dependencies]
|
|
52
|
-
python = "
|
|
55
|
+
python = "^3.9"
|
|
53
56
|
libadvian = ">=0.3,<=2.0" # Be less strict about libadvian versions to avoid causing issues downstream
|
|
54
57
|
msgpack = "^1.0"
|
|
55
|
-
dataclasses = { version = "^0.8", python = "~3.6" }
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
pytest-cov = "^4.0"
|
|
68
|
-
pylint = [
|
|
69
|
-
{ version = "^2.17", python=">=3.8,<=4.0" },
|
|
70
|
-
{ version = "^2.13", python=">=3.0,<=3.8" }
|
|
71
|
-
]
|
|
72
|
-
black = "^22.3"
|
|
73
|
-
bandit = [
|
|
74
|
-
{ version = "^1.7", extras = ["toml"], python="^3.7" },
|
|
75
|
-
{ version = "=1.7.1", extras = ["toml"], python="~3.6" }
|
|
76
|
-
]
|
|
77
|
-
mypy = [
|
|
78
|
-
{ version = "^1.2", python=">=3.8,<=4.0" },
|
|
79
|
-
{ version = "^0.942", python=">=3.0,<=3.8" }
|
|
80
|
-
]
|
|
81
|
-
pre-commit = "^2.17"
|
|
82
|
-
pytest-asyncio = [
|
|
83
|
-
{ version=">=0.18,<=1.0", python="^3.7" },
|
|
84
|
-
{ version="^0.14", python="~3.6" }
|
|
85
|
-
]
|
|
59
|
+
[tool.poetry.group.dev.dependencies]
|
|
60
|
+
pytest = "^8.3"
|
|
61
|
+
coverage = "^7.8"
|
|
62
|
+
pytest-cov = "^6.1"
|
|
63
|
+
pylint = "^3.3"
|
|
64
|
+
black = "^25.1"
|
|
65
|
+
bandit = "^1.8"
|
|
66
|
+
mypy = "^1.15"
|
|
67
|
+
pre-commit = "^4.2"
|
|
68
|
+
pytest-asyncio = ">=0.21,<1.0" # caret behaviour on 0.x is to lock to 0.x.*
|
|
86
69
|
bump2version = "^1.0"
|
|
87
|
-
detect-secrets = "^1.
|
|
70
|
+
detect-secrets = "^1.5"
|
|
71
|
+
types-toml = ">=0.10,<1.0" # caret behaviour on 0.x is to lock to 0.x.*
|
|
72
|
+
|
|
88
73
|
|
|
89
74
|
[build-system]
|
|
90
|
-
requires = ["poetry-core>=1.
|
|
75
|
+
requires = ["poetry-core>=1.2.0"]
|
|
91
76
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
"""Data messages."""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Union
|
|
2
4
|
import uuid
|
|
3
5
|
import datetime
|
|
4
6
|
from dataclasses import dataclass, field
|
|
5
|
-
from
|
|
7
|
+
from copy import deepcopy
|
|
8
|
+
import sys
|
|
6
9
|
|
|
7
10
|
from .abstract import BaseMessage, TooFewPartsError
|
|
8
|
-
from .binpackers import msgpack_pack, msgpack_unpack
|
|
11
|
+
from .binpackers import msgpack_pack, msgpack_unpack, ensure_utf8, uuid_to_b64
|
|
9
12
|
from .pubsub import PubSubMessage
|
|
10
13
|
|
|
11
14
|
|
|
15
|
+
def utctimestamp() -> str:
|
|
16
|
+
"""Get the UTC timestamp in the way given version wants it"""
|
|
17
|
+
if sys.version_info < (3, 11):
|
|
18
|
+
return datetime.datetime.utcnow().isoformat(timespec="milliseconds") + "Z"
|
|
19
|
+
# pylint: disable=E1101 # only a problem in pre 3.11 versions
|
|
20
|
+
return datetime.datetime.now(datetime.UTC).isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
21
|
+
|
|
22
|
+
|
|
12
23
|
@dataclass
|
|
13
24
|
class BaseDataMessage(BaseMessage): # pylint: disable=W0223
|
|
14
25
|
"""Baseclass for all ZMQ DataMessage types."""
|
|
@@ -17,9 +28,9 @@ class BaseDataMessage(BaseMessage): # pylint: disable=W0223
|
|
|
17
28
|
data: Dict[Any, Any] = field(compare=False, default_factory=dict)
|
|
18
29
|
|
|
19
30
|
def __post_init__(self) -> None:
|
|
20
|
-
"""Auto-add systemtime
|
|
31
|
+
"""Auto-add systemtime"""
|
|
21
32
|
if not self.data:
|
|
22
|
-
self.data["systemtime"] =
|
|
33
|
+
self.data["systemtime"] = utctimestamp()
|
|
23
34
|
|
|
24
35
|
|
|
25
36
|
@dataclass
|
|
@@ -69,3 +80,12 @@ class PubSubDataMessage(BaseDataMessage, PubSubMessage):
|
|
|
69
80
|
self.dataparts[0] = self.messageid.bytes
|
|
70
81
|
self.dataparts[1] = msgpack_pack(self.data)
|
|
71
82
|
return super().zmq_encode()
|
|
83
|
+
|
|
84
|
+
def copy_as(self, topic: Union[bytes, str]) -> "PubSubDataMessage":
|
|
85
|
+
"""Create a deep copy with new messageid and topic, auto-sets 'from_msgid' for tracking"""
|
|
86
|
+
newmsg = deepcopy(self)
|
|
87
|
+
newmsg.messageid = uuid.uuid4()
|
|
88
|
+
newmsg.data["from_msgid"] = uuid_to_b64(self.messageid)
|
|
89
|
+
newmsg.topic = ensure_utf8(topic)
|
|
90
|
+
newmsg.data["systemtime"] = utctimestamp()
|
|
91
|
+
return newmsg
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""PUB/SUB related helpers."""
|
|
2
|
+
|
|
2
3
|
from typing import Any, Coroutine, Callable, Dict, List, Sequence, Tuple, Type, Union, Optional, cast
|
|
3
4
|
from abc import ABC, abstractmethod # pylint: disable=E0611 # false positive
|
|
4
5
|
from dataclasses import dataclass, field
|
|
@@ -224,7 +225,7 @@ class BasePubSubManager(ABC):
|
|
|
224
225
|
|
|
225
226
|
if not match_found:
|
|
226
227
|
# TODO: Log error
|
|
227
|
-
|
|
228
|
+
pass
|
|
228
229
|
|
|
229
230
|
async def raw_zmq_callback_async(self, sock: ZMQSocket, msgparts: List[bytes]) -> None:
|
|
230
231
|
"""Find the corresponding subscriptions and dispatch."""
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""REQuest/REPly helpers"""
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
from typing import Callable, Any, Tuple, Optional, Sequence, List, Union, Dict
|
|
3
4
|
import inspect
|
|
4
5
|
import logging
|
|
5
6
|
|
|
@@ -9,16 +10,18 @@ from .abstract import ZMQSocket, ZMQSocketUrisInputTypes, ZMQSocketDescription
|
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
LOGGER = logging.getLogger(__name__)
|
|
13
|
+
REQREP_DEFAULT_TIMEOUT = 5.0
|
|
12
14
|
|
|
13
15
|
|
|
14
16
|
class REQMixinBase:
|
|
15
17
|
"""Common REQuest helpers"""
|
|
16
18
|
|
|
17
19
|
@classmethod
|
|
18
|
-
def construct_command(cls, cmd: str, *args: Any) -> PubSubDataMessage:
|
|
20
|
+
def construct_command(cls, cmd: str, *args: Any, **kwargs: Any) -> PubSubDataMessage:
|
|
19
21
|
"""Helper to construct the command message"""
|
|
20
22
|
msg = PubSubDataMessage(b"command")
|
|
21
23
|
msg.data["command"] = [cmd] + list(args)
|
|
24
|
+
msg.data["command_kwargs"] = kwargs
|
|
22
25
|
return msg
|
|
23
26
|
|
|
24
27
|
def _get_request_socket(self, sockdef: Union[ZMQSocket, ZMQSocketUrisInputTypes]) -> ZMQSocket:
|
|
@@ -26,13 +29,21 @@ class REQMixinBase:
|
|
|
26
29
|
raise NotImplementedError("Must be implemented in the class to be mixed in")
|
|
27
30
|
|
|
28
31
|
def _do_reqrep_blocking(
|
|
29
|
-
self,
|
|
32
|
+
self,
|
|
33
|
+
sockdef: Union[ZMQSocket, ZMQSocketUrisInputTypes],
|
|
34
|
+
msg: PubSubDataMessage,
|
|
35
|
+
*,
|
|
36
|
+
timeout: Optional[float] = None,
|
|
30
37
|
) -> PubSubDataMessage:
|
|
31
38
|
"""Do the actual REQuest and get the REPly (blocking context)"""
|
|
32
39
|
raise NotImplementedError("Must be implemented in the class to be mixed in")
|
|
33
40
|
|
|
34
41
|
async def _do_reqrep_async(
|
|
35
|
-
self,
|
|
42
|
+
self,
|
|
43
|
+
sockdef: Union[ZMQSocket, ZMQSocketUrisInputTypes],
|
|
44
|
+
msg: PubSubDataMessage,
|
|
45
|
+
*,
|
|
46
|
+
timeout: Optional[float] = None,
|
|
36
47
|
) -> PubSubDataMessage:
|
|
37
48
|
"""Do the actual REQuest and get the REPly (async context)"""
|
|
38
49
|
raise NotImplementedError("Must be implemented in the class to be mixed in")
|
|
@@ -61,22 +72,38 @@ class REQMixinBase:
|
|
|
61
72
|
return True
|
|
62
73
|
|
|
63
74
|
def send_command_blocking(
|
|
64
|
-
self,
|
|
75
|
+
self,
|
|
76
|
+
sockdef: Union[ZMQSocket, ZMQSocketUrisInputTypes],
|
|
77
|
+
cmd: str,
|
|
78
|
+
*args: Any,
|
|
79
|
+
**kwargs: Any,
|
|
65
80
|
) -> PubSubDataMessage:
|
|
66
|
-
"""Constructs and sends the command in blocking context to given socket, sanity-checks the reply
|
|
67
|
-
|
|
68
|
-
|
|
81
|
+
"""Constructs and sends the command in blocking context to given socket, sanity-checks the reply.
|
|
82
|
+
set_raise_on_insane=True to automatically raise an error if the reply is no good. set timeout=seconds
|
|
83
|
+
for non-default timeout"""
|
|
84
|
+
raise_on_insane = bool(kwargs.pop("raise_on_insane", False))
|
|
85
|
+
timeout = float(kwargs.pop("timeout", REQREP_DEFAULT_TIMEOUT))
|
|
86
|
+
cmd_msg = REQMixinBase.construct_command(cmd, *args, **kwargs)
|
|
87
|
+
reply = self._do_reqrep_blocking(sockdef, cmd_msg, timeout=timeout)
|
|
69
88
|
is_sane = self._sanity_check_reply(reply, uuid_to_b64(cmd_msg.messageid))
|
|
70
89
|
if not is_sane and raise_on_insane:
|
|
71
90
|
raise RuntimeError("Reply does not meet sanity-checks, see logs for details")
|
|
72
91
|
return reply
|
|
73
92
|
|
|
74
93
|
async def send_command_async(
|
|
75
|
-
self,
|
|
94
|
+
self,
|
|
95
|
+
sockdef: Union[ZMQSocket, ZMQSocketUrisInputTypes],
|
|
96
|
+
cmd: str,
|
|
97
|
+
*args: Any,
|
|
98
|
+
**kwargs: Any,
|
|
76
99
|
) -> PubSubDataMessage:
|
|
77
|
-
"""Constructs and sends the command in
|
|
78
|
-
|
|
79
|
-
|
|
100
|
+
"""Constructs and sends the command in blocking context to given socket, sanity-checks the reply.
|
|
101
|
+
set_raise_on_insane=True to automatically raise an error if the reply is no good. set timeout=seconds
|
|
102
|
+
for non-default timeout"""
|
|
103
|
+
raise_on_insane = kwargs.pop("raise_on_insane", False)
|
|
104
|
+
timeout = kwargs.pop("timeout", REQREP_DEFAULT_TIMEOUT)
|
|
105
|
+
cmd_msg = REQMixinBase.construct_command(cmd, *args, **kwargs)
|
|
106
|
+
reply = await self._do_reqrep_async(sockdef, cmd_msg, timeout=timeout)
|
|
80
107
|
is_sane = self._sanity_check_reply(reply, uuid_to_b64(cmd_msg.messageid))
|
|
81
108
|
if not is_sane and raise_on_insane:
|
|
82
109
|
raise RuntimeError("Reply does not meet sanity-checks, see logs for details")
|
|
@@ -91,7 +118,7 @@ class REPMixinBase:
|
|
|
91
118
|
msg: PubSubDataMessage,
|
|
92
119
|
look_in: Optional[Sequence[Any]] = None,
|
|
93
120
|
sdesc: Optional[ZMQSocketDescription] = None,
|
|
94
|
-
) -> Tuple[Callable[..., Any], Any]:
|
|
121
|
+
) -> Tuple[Callable[..., Any], Any, Dict[str, Any]]:
|
|
95
122
|
"""Resolve the method to use for message command, if optional look_in argument is given will look for the
|
|
96
123
|
command method in the given classes in that order (defaults to [self])
|
|
97
124
|
|
|
@@ -99,6 +126,7 @@ class REPMixinBase:
|
|
|
99
126
|
"""
|
|
100
127
|
|
|
101
128
|
_ = sdesc
|
|
129
|
+
LOGGER.debug("msg={}".format(msg))
|
|
102
130
|
|
|
103
131
|
if "command" not in msg.data:
|
|
104
132
|
raise RuntimeError("No command given")
|
|
@@ -109,6 +137,7 @@ class REPMixinBase:
|
|
|
109
137
|
else:
|
|
110
138
|
cmd = msg.data["command"][0]
|
|
111
139
|
cmd_args = msg.data["command"][1:]
|
|
140
|
+
cmd_kwargs = msg.data.get("command_kwargs", {})
|
|
112
141
|
|
|
113
142
|
if not look_in:
|
|
114
143
|
look_in = [self]
|
|
@@ -121,7 +150,7 @@ class REPMixinBase:
|
|
|
121
150
|
if not cmd_method:
|
|
122
151
|
raise RuntimeError("no such method {}".format(cmd))
|
|
123
152
|
|
|
124
|
-
return cmd_method, cmd_args
|
|
153
|
+
return cmd_method, cmd_args, cmd_kwargs
|
|
125
154
|
|
|
126
155
|
async def handle_rep_async(
|
|
127
156
|
self, msgparts: List[bytes], sdesc: Optional[ZMQSocketDescription] = None
|
|
@@ -136,13 +165,13 @@ class REPMixinBase:
|
|
|
136
165
|
msg = PubSubDataMessage.zmq_decode(msgparts)
|
|
137
166
|
reply.data["cmd_msgid"] = uuid_to_b64(msg.messageid)
|
|
138
167
|
|
|
139
|
-
cmd_method, cmd_args = self.resolve_command_method_and_args(msg, None, sdesc)
|
|
168
|
+
cmd_method, cmd_args, cmd_kwargs = self.resolve_command_method_and_args(msg, None, sdesc)
|
|
140
169
|
# Handle both coroutines and sync methods
|
|
141
170
|
if inspect.iscoroutinefunction(cmd_method):
|
|
142
|
-
response = await cmd_method(*cmd_args)
|
|
171
|
+
response = await cmd_method(*cmd_args, **cmd_kwargs)
|
|
143
172
|
else:
|
|
144
|
-
response = cmd_method(*cmd_args)
|
|
145
|
-
LOGGER.debug("{}({}) returned {}".format(cmd_method, cmd_args, response))
|
|
173
|
+
response = cmd_method(*cmd_args, **cmd_kwargs)
|
|
174
|
+
LOGGER.debug("{}({}, *, {}) returned {}".format(cmd_method, cmd_args, cmd_kwargs, response))
|
|
146
175
|
reply.data.update(
|
|
147
176
|
{
|
|
148
177
|
"failed": False,
|
|
@@ -166,12 +195,12 @@ class REPMixinBase:
|
|
|
166
195
|
msg = PubSubDataMessage.zmq_decode(msgparts)
|
|
167
196
|
reply.data["cmd_msgid"] = uuid_to_b64(msg.messageid)
|
|
168
197
|
|
|
169
|
-
cmd_method, cmd_args = self.resolve_command_method_and_args(msg, None, sdesc)
|
|
198
|
+
cmd_method, cmd_args, cmd_kwargs = self.resolve_command_method_and_args(msg, None, sdesc)
|
|
170
199
|
if inspect.iscoroutinefunction(cmd_method):
|
|
171
200
|
raise RuntimeError("{} is a coroutine and we are not capable of handling that".format(cmd_method))
|
|
172
201
|
|
|
173
|
-
response = cmd_method(*cmd_args)
|
|
174
|
-
LOGGER.debug("{}({}) returned {}".format(cmd_method, cmd_args, response))
|
|
202
|
+
response = cmd_method(*cmd_args, **cmd_kwargs)
|
|
203
|
+
LOGGER.debug("{}({}, *, {}) returned {}".format(cmd_method, cmd_args, cmd_kwargs, response))
|
|
175
204
|
reply.data.update(
|
|
176
205
|
{
|
|
177
206
|
"failed": False,
|
datastreamcorelib-1.6.0/setup.py
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
from setuptools import setup
|
|
3
|
-
|
|
4
|
-
package_dir = \
|
|
5
|
-
{'': 'src'}
|
|
6
|
-
|
|
7
|
-
packages = \
|
|
8
|
-
['datastreamcorelib']
|
|
9
|
-
|
|
10
|
-
package_data = \
|
|
11
|
-
{'': ['*']}
|
|
12
|
-
|
|
13
|
-
install_requires = \
|
|
14
|
-
['libadvian>=0.3,<=2.0', 'msgpack>=1.0,<2.0']
|
|
15
|
-
|
|
16
|
-
extras_require = \
|
|
17
|
-
{':python_version >= "3.6" and python_version < "3.7"': ['dataclasses>=0.8,<0.9']}
|
|
18
|
-
|
|
19
|
-
setup_kwargs = {
|
|
20
|
-
'name': 'datastreamcorelib',
|
|
21
|
-
'version': '1.6.0',
|
|
22
|
-
'description': 'Helpers and utilities for https://gitlab.com/advian-oss/python-datastreamservicelib that are not eventloop specific.',
|
|
23
|
-
'long_description': '=================\ndatastreamcorelib\n=================\n\nCore helpers and Abstract Base Classes for making use of ZMQ nice, easy and DRY.\n\nYou should probably look at https://gitlab.com/advian-oss/python-datastreamservicelib and\nhttps://gitlab.com/advian-oss/python-datastreamserviceapp_template unless you\'re working\non an adapter for yet unsupported eventloop.\n\nDocker\n------\n\nFor more controlled deployments and to get rid of "works on my computer" -syndrome, we always\nmake sure our software works under docker.\n\nIt\'s also a quick way to get started with a standard development environment.\n\nSSH agent forwarding\n^^^^^^^^^^^^^^^^^^^^\n\nWe need buildkit_::\n\n export DOCKER_BUILDKIT=1\n\n.. _buildkit: https://docs.docker.com/develop/develop-images/build_enhancements/\n\nAnd also the exact way for forwarding agent to running instance is different on OSX::\n\n export DOCKER_SSHAGENT="-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock -e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock"\n\nand Linux::\n\n export DOCKER_SSHAGENT="-v $SSH_AUTH_SOCK:$SSH_AUTH_SOCK -e SSH_AUTH_SOCK"\n\nCreating a development container\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nBuild image, create container and start it::\n\n docker build --ssh default --target devel_shell -t datastreamcorelib:devel_shell .\n docker create --name datastreamcorelib_devel -v `pwd`":/app" -it -v /tmp:/tmp `echo $DOCKER_SSHAGENT` datastreamcorelib:devel_shell\n docker start -i datastreamcorelib_devel\n\npre-commit considerations\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\nIf working in Docker instead of native env you need to run the pre-commit checks in docker too::\n\n docker exec -i datastreamcorelib_devel /bin/bash -c "pre-commit install"\n docker exec -i datastreamcorelib_devel /bin/bash -c "pre-commit run --all-files"\n\nYou need to have the container running, see above. Or alternatively use the docker run syntax but using\nthe running container is faster::\n\n docker run -it --rm -v `pwd`":/app" datastreamcorelib:devel_shell -c "pre-commit run --all-files"\n\nTest suite\n^^^^^^^^^^\n\nYou can use the devel shell to run py.test when doing development, for CI use\nthe "tox" target in the Dockerfile::\n\n docker build --ssh default --target tox -t datastreamcorelib:tox .\n docker run -it --rm -v `pwd`":/app" `echo $DOCKER_SSHAGENT` datastreamcorelib:tox\n\nProduction docker\n^^^^^^^^^^^^^^^^^\n\nThere\'s a "production" target since it\'s our standard pattern, however this library does not yet\nexpose any CLI tools so the production target is kinda useless.\n\nLocal Development\n-----------------\n\nTLDR:\n\n- Create and activate a Python 3.6 virtualenv (assuming virtualenvwrapper)::\n\n mkvirtualenv -p `which python3.6` my_virtualenv\n\n- change to a branch::\n\n git checkout -b my_branch\n\n- install Poetry: https://python-poetry.org/docs/#installation\n- Install project deps and pre-commit hooks::\n\n poetry install\n pre-commit install\n pre-commit run --all-files\n\n- Ready to go.\n\nUse Python 3.6 for development since it\'s the lowest supported version so you don\'t accidentally\nuse features only available in higher versions and then have to re-do everything when CI tests fail\non 3.6.\n\nRemember to activate your virtualenv whenever working on the repo, this is needed\nbecause pylint and mypy pre-commit hooks use the "system" python for now (because reasons).\n\nRunning "pre-commit run --all-files" and "py.test -v" regularly during development and\nespecially before committing will save you some headache.\n',
|
|
24
|
-
'author': 'Eero af Heurlin',
|
|
25
|
-
'author_email': 'eero.afheurlin@iki.fi',
|
|
26
|
-
'maintainer': None,
|
|
27
|
-
'maintainer_email': None,
|
|
28
|
-
'url': 'https://gitlab.com/advian-oss/python-datastreamcorelib/',
|
|
29
|
-
'package_dir': package_dir,
|
|
30
|
-
'packages': packages,
|
|
31
|
-
'package_data': package_data,
|
|
32
|
-
'install_requires': install_requires,
|
|
33
|
-
'extras_require': extras_require,
|
|
34
|
-
'python_requires': '>=3.6.2,<4.0',
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
setup(**setup_kwargs)
|
|
File without changes
|
|
File without changes
|