oarepo-runtime 1.5.58__py3-none-any.whl → 1.5.60__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -178,7 +178,7 @@ def run_datastream_processor(batch: Dict, *, processor: JSONObject, identity, ca
178
178
  {
179
179
  "batch": deserialized_batch.json,
180
180
  "identity": serialize_identity(identity),
181
- "callback": f"{processor_signature.kind}_error",
181
+ "callback": f"{processor_signature.kind.value}_error",
182
182
  "exception": err.json,
183
183
  },
184
184
  )
@@ -25,11 +25,20 @@ class DataStreamChain(abc.ABC):
25
25
  def finish(self, callback: Union[DataStreamCallback, Any]):
26
26
  pass
27
27
 
28
+ try:
29
+ from enum import StrEnum
28
30
 
29
- class SignatureKind(str, Enum):
30
- READER = "reader"
31
- TRANSFORMER = "transformer"
32
- WRITER = "writer"
31
+ class SignatureKind(StrEnum):
32
+ READER = "reader"
33
+ TRANSFORMER = "transformer"
34
+ WRITER = "writer"
35
+
36
+ except ImportError:
37
+
38
+ class SignatureKind(str, Enum):
39
+ READER = "reader"
40
+ TRANSFORMER = "transformer"
41
+ WRITER = "writer"
33
42
 
34
43
 
35
44
  @dataclasses.dataclass
@@ -81,7 +81,7 @@ def run_semi_asynchronous_datastream_processor(
81
81
  {
82
82
  "batch": batch.json,
83
83
  "identity": serialize_identity(identity),
84
- "callback": f"{signature.kind}_error",
84
+ "callback": f"{signature.kind.value}_error",
85
85
  "exception": err.json,
86
86
  },
87
87
  )
@@ -1,4 +1,4 @@
1
- from typing import Any, List
1
+ from typing import Any, Callable, List
2
2
 
3
3
 
4
4
  class Selector:
@@ -25,6 +25,71 @@ class FirstItemSelector(PathSelector):
25
25
  return []
26
26
 
27
27
 
28
+ class FilteredSelector(Selector):
29
+ """
30
+ Selector which filters output of another selector
31
+ Example:
32
+ FilteredSelector(PathSelector("metadata.creators", "metadata.contributors"),
33
+ filter=lambda x: x["nameType"] == "personal", projection="affiliations")
34
+
35
+ selects affiliations of creators with nameType personal from following data
36
+
37
+ data = {
38
+ "metadata": {
39
+ "creators": [
40
+ {"name": "hugo", "affiliations": ["uni1", "uni2"], "nameType": "personal"},
41
+ {"name": "uni3", "nameType": "organizational"},
42
+ ]
43
+ }
44
+ }
45
+ """
46
+
47
+ def __init__(
48
+ self,
49
+ selector: Selector,
50
+ filter: Callable[[Any], bool],
51
+ projection: Callable[[Any], Any] | str = None,
52
+ ):
53
+
54
+ self.selector = selector
55
+ self.filter = filter
56
+ self.projection = projection
57
+
58
+ def select(self, record):
59
+ selected = self.selector.select(record)
60
+ selected = filter(self.filter, selected)
61
+ if self.projection:
62
+ ret = []
63
+ for select_element in selected:
64
+ if isinstance(self.projection, str):
65
+ if isinstance(select_element, dict) and self.projection in select_element:
66
+ result = select_element[self.projection]
67
+ else:
68
+ result = []
69
+ else:
70
+ result = self.projection(select_element)
71
+ if isinstance(result, list):
72
+ ret += result
73
+ else:
74
+ ret.append(result)
75
+ else:
76
+ ret = list(selected)
77
+ return ret
78
+
79
+
80
+ class MultiSelector(Selector):
81
+ """Selector concatenating outputs of multiple selectors"""
82
+
83
+ def __init__(self, *selectors: Selector):
84
+ self.selectors = selectors
85
+
86
+ def select(self, record):
87
+ ret = []
88
+ for selector in self.selectors:
89
+ ret += selector.select(record)
90
+ return ret
91
+
92
+
28
93
  def getter(data, path: List):
29
94
  if len(path) == 0:
30
95
  if isinstance(data, list):
@@ -36,4 +101,4 @@ def getter(data, path: List):
36
101
  yield from getter(data[path[0]], path[1:])
37
102
  elif isinstance(data, list):
38
103
  for item in data:
39
- yield from getter(item, path)
104
+ yield from getter(item, path)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oarepo-runtime
3
- Version: 1.5.58
3
+ Version: 1.5.60
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -14,14 +14,14 @@ oarepo_runtime/cli/fixtures.py,sha256=l6zHpz1adjotrbFy_wcN2TOL8x20i-1jbQmaoEEo-U
14
14
  oarepo_runtime/cli/index.py,sha256=2dZvXtrph527YIgFTCQ8dIVsza-bZou9HBBzYRWAPTY,8243
15
15
  oarepo_runtime/cli/validate.py,sha256=HpSvHQCGHlrdgdpKix9cIlzlBoJEiT1vACZdMnOUGEY,2827
16
16
  oarepo_runtime/datastreams/__init__.py,sha256=_i52Ek9J8DMARST0ejZAZPzUKm55xrrlKlCSO7dl6y4,1008
17
- oarepo_runtime/datastreams/asynchronous.py,sha256=1I1mEaTxyrcHD7LK6O9z2QX37AgeejflxynGmLreLQ0,7396
17
+ oarepo_runtime/datastreams/asynchronous.py,sha256=JwT-Hx6P7KwV0vSJlxX6kLSIX5vtsekVsA2p_hZpJ_U,7402
18
18
  oarepo_runtime/datastreams/catalogue.py,sha256=D6leq-FPT3RP3SniEAXPm66v3q8ZdQnaUYJ5XM0dIFY,5021
19
- oarepo_runtime/datastreams/datastreams.py,sha256=wnMk1UFv-cWXRO0jHwRNoJBO0cbZaHqrLnH7vgfnf78,4485
19
+ oarepo_runtime/datastreams/datastreams.py,sha256=N9XXwIaBTADkPhE-XG6uotMwd-8Kn0vEZOoeV2BnMGI,4679
20
20
  oarepo_runtime/datastreams/errors.py,sha256=WyZLU53EdFJTLv6K2ooM_M6ISjLS-U1dDw6B7guOLSc,1540
21
21
  oarepo_runtime/datastreams/ext.py,sha256=ivugdVMCqwugK-5SeX14a-dMq6VaTt7DM2wFU357tR4,1406
22
22
  oarepo_runtime/datastreams/fixtures.py,sha256=LTzRLoS3hkdP7a7wX3fCNWplaxh0DQQjxGto3p1_Luk,8691
23
23
  oarepo_runtime/datastreams/json.py,sha256=OAiaH93eqpH5qNQSPKKc8K-hXKAn5lB0PUKwwZFqJSw,153
24
- oarepo_runtime/datastreams/semi_asynchronous.py,sha256=TJWby2MDKXm5feRocoWB-8OhsShq5R9HoZ74O1rGBOk,2934
24
+ oarepo_runtime/datastreams/semi_asynchronous.py,sha256=kNc6BBnV6oFoY9kHgf5l8fd1wibRfI0dwyzLtu4fmUA,2940
25
25
  oarepo_runtime/datastreams/synchronous.py,sha256=t5lfnMkLqy3jK5zMl-nIuA0HlMPiHGjwCqZ8XQP-3GM,2595
26
26
  oarepo_runtime/datastreams/transformers.py,sha256=q5KzHPl2kJg7HP1BtKJ7F_UMqg_7L1ZGDX0O7s8D6UI,521
27
27
  oarepo_runtime/datastreams/types.py,sha256=KZjblc3T_UFFW7LrMDmiR8lqVf86V484LAHj6yg05EI,9908
@@ -62,7 +62,7 @@ oarepo_runtime/records/systemfields/icu.py,sha256=sSGAgi5WhsAY4cCBL7-7nMpvHAuctp
62
62
  oarepo_runtime/records/systemfields/mapping.py,sha256=tXOK_jkdY1pOUO7_VfChfDNB8UTi21GUXaidpugTnO8,1017
63
63
  oarepo_runtime/records/systemfields/owner.py,sha256=dYRVBinniW7ECHuSnTAjeN6x1KhhJtNR9vxmD1KswMs,3805
64
64
  oarepo_runtime/records/systemfields/record_status.py,sha256=U3kem4-JkNsT17e0iAl3HIAZ2MvO5lY_0U757aZvTKE,935
65
- oarepo_runtime/records/systemfields/selectors.py,sha256=rXNioeyCHLiNGsA_zu8bfoFdu29ACSNN7zHRUm1rJ6Q,928
65
+ oarepo_runtime/records/systemfields/selectors.py,sha256=xQEMhmqiE1M466cMilVO85V2DkELbbM3Xa8oYSCli8o,2959
66
66
  oarepo_runtime/records/systemfields/synthetic.py,sha256=UustvhzcDGuaNZLDeHbWwshoxQR-qRIuHDCct5RXmrI,4287
67
67
  oarepo_runtime/resources/__init__.py,sha256=v8BGrOTu_FjKzd0eozV7Q4GoGxyfybsL2cI-tbP5Pys,185
68
68
  oarepo_runtime/resources/file_resource.py,sha256=Ta3bFce7l0xwqkkOMOEu9mxbB8BbKj5HUHRHmidhnl8,414
@@ -119,9 +119,9 @@ oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
119
119
  oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
120
120
  oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
121
121
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
122
- oarepo_runtime-1.5.58.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
123
- oarepo_runtime-1.5.58.dist-info/METADATA,sha256=9UdbdfnIle2-N6TfXHW5wlAOLYL-QDMcZ7CdU6ZbwCg,4720
124
- oarepo_runtime-1.5.58.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
125
- oarepo_runtime-1.5.58.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
126
- oarepo_runtime-1.5.58.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
127
- oarepo_runtime-1.5.58.dist-info/RECORD,,
122
+ oarepo_runtime-1.5.60.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
123
+ oarepo_runtime-1.5.60.dist-info/METADATA,sha256=8HAOuGW8hqgI2E1df2A-ux-WdXPlA5fMM7TFvok8hTY,4720
124
+ oarepo_runtime-1.5.60.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
125
+ oarepo_runtime-1.5.60.dist-info/entry_points.txt,sha256=QrlXAKuPDVBinaSh_v3yO9_Nb9ZNmJCJ0VFcCW-z0Jg,327
126
+ oarepo_runtime-1.5.60.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
127
+ oarepo_runtime-1.5.60.dist-info/RECORD,,