kuflow-temporal-common 3.0.0__tar.gz → 3.2.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.
@@ -1,21 +1,22 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: kuflow-temporal-common
3
- Version: 3.0.0
3
+ Version: 3.2.0
4
4
  Summary: KuFlow utilities to use Temporal.io
5
- Home-page: https://kuflow.com/
6
5
  License: MIT
7
6
  Author: KuFlow S.L.
8
7
  Author-email: kuflow@kuflow.com
9
- Requires-Python: >=3.8,<4.0
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.8
13
11
  Classifier: Programming Language :: Python :: 3.9
14
12
  Classifier: Programming Language :: Python :: 3.10
15
13
  Classifier: Programming Language :: Python :: 3.11
16
- Requires-Dist: kuflow-rest (>=3.0.0,<4.0.0)
17
- Requires-Dist: temporalio (>=1.6.0,<1.7.0)
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Requires-Dist: kuflow-rest (>=3.2.0,<4.0.0)
17
+ Requires-Dist: temporalio (>=1.10.0,<1.11.0)
18
18
  Project-URL: Documentation, https://docs.kuflow.com/
19
+ Project-URL: Homepage, https://kuflow.com/
19
20
  Project-URL: Repository, https://github.com/kuflow/kuflow-sdk-python
20
21
  Description-Content-Type: text/markdown
21
22
 
@@ -0,0 +1 @@
1
+ 3.2.0
@@ -24,8 +24,8 @@
24
24
 
25
25
  from ._auto_heartbeater import auto_heartbeater
26
26
  from ._converter import (
27
- CompositeEncodingPayloadConverter,
28
- KuFlowComposableEncodingPayloadConverter,
27
+ KuFlowModelJSONEncoder,
28
+ KuFlowModelJSONTypeConverter,
29
29
  register_serializable_models,
30
30
  )
31
31
  from ._exceptions import KuFlowFailureType, create_application_error
@@ -33,11 +33,11 @@ from ._exceptions import KuFlowFailureType, create_application_error
33
33
 
34
34
  __all__ = [
35
35
  "auto_heartbeater",
36
- "CompositeEncodingPayloadConverter",
37
36
  "create_application_error",
38
- "KuFlowComposableEncodingPayloadConverter",
39
37
  "KuFlowFailureType",
38
+ "KuFlowModelJSONEncoder",
39
+ "KuFlowModelJSONTypeConverter",
40
40
  "register_serializable_models",
41
41
  ]
42
42
 
43
- __version__ = "3.0.0"
43
+ __version__ = "3.2.0"
@@ -24,9 +24,10 @@
24
24
 
25
25
  import asyncio
26
26
  import logging
27
+ from collections.abc import Awaitable
27
28
  from datetime import datetime
28
29
  from functools import wraps
29
- from typing import Any, Awaitable, Callable, TypeVar, cast
30
+ from typing import Any, Callable, TypeVar, cast
30
31
 
31
32
  from temporalio import activity
32
33
 
@@ -0,0 +1,69 @@
1
+ #
2
+ # MIT License
3
+ #
4
+ # Copyright (c) 2022 KuFlow
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the "Software"), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+ #
24
+
25
+ from typing import Any, Optional, Union
26
+
27
+ from temporalio.converter import (
28
+ AdvancedJSONEncoder,
29
+ JSONTypeConverter,
30
+ _JSONTypeConverterUnhandled,
31
+ )
32
+
33
+ from kuflow_rest import Deserializer, Model, Serializer
34
+
35
+
36
+ temporal_models: dict[str, type] = {}
37
+
38
+
39
+ def register_serializable_models(models: dict[str, type]):
40
+ global temporal_models
41
+
42
+ temporal_models_tmp = {k: v for k, v in models.items() if isinstance(v, type)}
43
+ temporal_models_tmp = {**temporal_models, **temporal_models_tmp}
44
+ temporal_models = temporal_models_tmp
45
+
46
+
47
+ class KuFlowModelJSONEncoder(AdvancedJSONEncoder):
48
+ def __init__(self, *args, **kwargs) -> None:
49
+ super().__init__(*args, **kwargs)
50
+ client_models = {k: v for k, v in temporal_models.items() if isinstance(v, type)}
51
+ self._serialize = Serializer(client_models)
52
+
53
+ def default(self, value: Any) -> Any:
54
+ if isinstance(value, Model):
55
+ return self._serialize.body(value, value.__class__.__name__)
56
+
57
+ return super().default(value)
58
+
59
+
60
+ class KuFlowModelJSONTypeConverter(JSONTypeConverter):
61
+ def __init__(self) -> None:
62
+ client_models = {k: v for k, v in temporal_models.items() if isinstance(v, type)}
63
+ self._deserialize = Deserializer(client_models)
64
+
65
+ def to_typed_value(self, hint: type, value: Any) -> Union[Optional[Any], _JSONTypeConverterUnhandled]:
66
+ if issubclass(hint, Model):
67
+ return self._deserialize(hint.__name__, value)
68
+
69
+ return JSONTypeConverter.Unhandled
@@ -40,7 +40,11 @@ def create_application_error(e: Exception) -> ApplicationError:
40
40
  if isinstance(e, ApplicationError):
41
41
  return e
42
42
 
43
+ error: ApplicationError
43
44
  if isinstance(e, HttpResponseError):
44
- return ApplicationError("Rest Invocation error", e, type=KuFlowFailureType.ACTIVITIES_REST_FAILURE)
45
+ error = ApplicationError("Rest Invocation error", e, type=KuFlowFailureType.ACTIVITIES_REST_FAILURE)
46
+ else:
47
+ error = ApplicationError("Invocation error", e, type=KuFlowFailureType.ACTIVITIES_FAILURE)
48
+ error.__cause__ = e
45
49
 
46
- return ApplicationError("Invocation error", e, type=KuFlowFailureType.ACTIVITIES_FAILURE)
50
+ return error
@@ -1,24 +1,30 @@
1
- [tool.poetry]
1
+ [project]
2
2
  name = "kuflow-temporal-common"
3
- version = "3.0.0"
4
3
  description = "KuFlow utilities to use Temporal.io"
5
4
  license = "MIT"
6
- authors = ["KuFlow S.L. <kuflow@kuflow.com>"]
5
+ readme = "README.md"
6
+ authors = [{name = "KuFlow S.L.", email = "kuflow@kuflow.com"}]
7
+ dynamic = ["version", "dependencies"]
8
+ requires-python = '>=3.9,<4.0'
9
+
10
+ [project.urls]
7
11
  homepage = "https://kuflow.com/"
8
- documentation = "https://docs.kuflow.com/"
9
12
  repository = "https://github.com/kuflow/kuflow-sdk-python"
10
- readme = "README.md"
11
- include = ["VERSION", "README.md", "CHANGELOG.md"]
12
- packages = [{ include = "kuflow_temporal_common" }]
13
+ documentation = "https://docs.kuflow.com/"
13
14
 
14
15
  [build-system]
15
16
  requires = ["poetry_core>=1.0.0"]
16
17
  build-backend = "poetry.core.masonry.api"
17
18
 
19
+ [tool.poetry]
20
+ version = "3.2.0"
21
+ include = ["VERSION", "README.md", "CHANGELOG.md"]
22
+ packages = [{ include = "kuflow_temporal_common" }]
23
+ requires-poetry = '>=2.0,<3.0'
24
+
18
25
  [tool.poetry.dependencies]
19
- python = "^3.8"
20
- kuflow-rest = "^3.0.0"
21
- temporalio = "~1.6.0"
26
+ kuflow-rest = "^3.2.0"
27
+ temporalio = "~1.10.0"
22
28
 
23
29
  [tool.poetry.group.dev.dependencies]
24
30
  mypy = "^1.11.1"
@@ -1 +0,0 @@
1
- 3.0.0
@@ -1,112 +0,0 @@
1
- #
2
- # MIT License
3
- #
4
- # Copyright (c) 2022 KuFlow
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the "Software"), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
23
- #
24
-
25
- import json
26
- from typing import Any, Dict, List, Optional, Type
27
-
28
- from temporalio.api.common.v1 import Payload
29
- from temporalio.converter import (
30
- EncodingPayloadConverter,
31
- JSONPlainPayloadConverter,
32
- )
33
-
34
- from kuflow_rest import Deserializer, Model, Serializer
35
-
36
-
37
- temporal_models: Dict[str, type] = {}
38
-
39
-
40
- def register_serializable_models(models: Dict[str, type]):
41
- global temporal_models
42
-
43
- temporal_models_tmp = {k: v for k, v in models.items() if isinstance(v, type)}
44
- temporal_models_tmp = {**temporal_models, **temporal_models_tmp}
45
- temporal_models = temporal_models_tmp
46
-
47
-
48
- class CompositeEncodingPayloadConverter(EncodingPayloadConverter):
49
- """Composite encoding payload converter that delegates to a list of encoding payload converters.
50
-
51
- Encoding/decoding are attempted on each payload converter successively until
52
- it succeeds.
53
-
54
- """
55
-
56
- def __init__(self, encoding: str, converters: List[EncodingPayloadConverter]):
57
- """Initializes the encoding data converter.
58
-
59
- Arguments:
60
- encoding: Encoding of this EncodingPayloadConverter
61
- converters: Encoding payload converters to delegate to, in order.
62
- """
63
- self.register_encoding = encoding
64
- self.converters = converters
65
-
66
- @property
67
- def encoding(self) -> str:
68
- return self.register_encoding
69
-
70
- def to_payload(self, value: Any) -> Optional[Payload]:
71
- payload: Optional[Payload] = None
72
- for converter in self.converters:
73
- payload = converter.to_payload(value)
74
- if payload is not None:
75
- break
76
-
77
- return payload
78
-
79
- def from_payload(self, payload: Payload, type_hint: Optional[Type] = None) -> Any:
80
- value: Optional[Payload] = None
81
- for converter in self.converters:
82
- value = converter.from_payload(payload, type_hint)
83
- if value is not None:
84
- break
85
-
86
- return value
87
-
88
-
89
- class KuFlowComposableEncodingPayloadConverter(EncodingPayloadConverter):
90
- def __init__(self, default_json_converter=JSONPlainPayloadConverter()) -> None:
91
- self._default_json_converter = default_json_converter
92
- client_models = {k: v for k, v in temporal_models.items() if isinstance(v, type)}
93
- self._serialize = Serializer(client_models)
94
- self._deserialize = Deserializer(client_models)
95
-
96
- @property
97
- def encoding(self) -> str:
98
- return "json/plain"
99
-
100
- def to_payload(self, value: Any) -> Optional[Payload]:
101
- if isinstance(value, Model) is False:
102
- return None
103
-
104
- serialized = self._serialize.body(value, value.__class__.__name__)
105
- return self._default_json_converter.to_payload(serialized)
106
-
107
- def from_payload(self, payload: Payload, type_hint: Optional[Type] = None) -> Any:
108
- if issubclass(type_hint, Model) is False:
109
- return None
110
-
111
- as_python_object = json.loads(payload.data)
112
- return self._deserialize(type_hint.__name__, as_python_object)
@@ -1,30 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- from setuptools import setup
3
-
4
- packages = \
5
- ['kuflow_temporal_common']
6
-
7
- package_data = \
8
- {'': ['*']}
9
-
10
- install_requires = \
11
- ['kuflow-rest>=3.0.0,<4.0.0', 'temporalio>=1.6.0,<1.7.0']
12
-
13
- setup_kwargs = {
14
- 'name': 'kuflow-temporal-common',
15
- 'version': '3.0.0',
16
- 'description': 'KuFlow utilities to use Temporal.io',
17
- 'long_description': '[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://github.com/kuflow/kuflow-sdk-python/blob/master/LICENSE)\n[![Python](https://img.shields.io/pypi/pyversions/kuflow-temporal-common.svg)](https://pypi.org/project/kuflow-temporal-common)\n[![PyPI](https://img.shields.io/pypi/v/kuflow-temporal-common.svg)](https://pypi.org/project/kuflow-temporal-common)\n\n# KuFlow Temporal Common\n\nKuFlow utilities to use with Temporal.\n\n## Documentation\n\nMore detailed docs are available in the [documentation pages](https://docs.kuflow.com/developers/).\n\n## Contributing\n\nWe are happy to receive your help and comments, together we will dance a wonderful KuFlow. Please review our [contribution guide](CONTRIBUTING.md).\n\n## License\n\n[MIT License](https://github.com/kuflow/kuflow-sdk-python/blob/master/LICENSE)\n',
18
- 'author': 'KuFlow S.L.',
19
- 'author_email': 'kuflow@kuflow.com',
20
- 'maintainer': 'None',
21
- 'maintainer_email': 'None',
22
- 'url': 'https://kuflow.com/',
23
- 'packages': packages,
24
- 'package_data': package_data,
25
- 'install_requires': install_requires,
26
- 'python_requires': '>=3.8,<4.0',
27
- }
28
-
29
-
30
- setup(**setup_kwargs)