haiway 0.15.2__py3-none-any.whl → 0.17.0__py3-none-any.whl

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.
haiway/__init__.py CHANGED
@@ -3,7 +3,6 @@ from haiway.context import (
3
3
  Disposables,
4
4
  MetricsContext,
5
5
  MetricsHandler,
6
- MetricsReading,
7
6
  MetricsRecording,
8
7
  MetricsScopeEntering,
9
8
  MetricsScopeExiting,
@@ -76,7 +75,6 @@ __all__ = [
76
75
  "MetricsHandler",
77
76
  "MetricsHolder",
78
77
  "MetricsLogger",
79
- "MetricsReading",
80
78
  "MetricsRecording",
81
79
  "MetricsScopeEntering",
82
80
  "MetricsScopeExiting",
@@ -4,7 +4,6 @@ from haiway.context.identifier import ScopeIdentifier
4
4
  from haiway.context.metrics import (
5
5
  MetricsContext,
6
6
  MetricsHandler,
7
- MetricsReading,
8
7
  MetricsRecording,
9
8
  MetricsScopeEntering,
10
9
  MetricsScopeExiting,
@@ -17,7 +16,6 @@ __all__ = [
17
16
  "Disposables",
18
17
  "MetricsContext",
19
18
  "MetricsHandler",
20
- "MetricsReading",
21
19
  "MetricsRecording",
22
20
  "MetricsScopeEntering",
23
21
  "MetricsScopeExiting",
haiway/context/access.py CHANGED
@@ -20,7 +20,7 @@ from haiway.context.disposables import Disposable, Disposables
20
20
  from haiway.context.identifier import ScopeIdentifier
21
21
  from haiway.context.logging import LoggerContext
22
22
  from haiway.context.metrics import MetricsContext, MetricsHandler
23
- from haiway.context.state import StateContext
23
+ from haiway.context.state import ScopeState, StateContext
24
24
  from haiway.context.tasks import TaskGroupContext
25
25
  from haiway.state import State
26
26
  from haiway.utils import mimic_function
@@ -70,9 +70,7 @@ class ScopeContext:
70
70
  object.__setattr__(
71
71
  self,
72
72
  "_task_group_context",
73
- TaskGroupContext(
74
- task_group=task_group,
75
- )
73
+ TaskGroupContext(task_group=task_group)
76
74
  if task_group is not None or self._identifier.is_root
77
75
  else None,
78
76
  )
@@ -175,8 +173,11 @@ class ScopeContext:
175
173
  self,
176
174
  "_state_context",
177
175
  StateContext(
178
- state=self._state_context._state.updated(
179
- await disposables.__aenter__(),
176
+ state=ScopeState(
177
+ (
178
+ *await disposables.__aenter__(),
179
+ *self._state_context._state._state.values(),
180
+ )
180
181
  ),
181
182
  ),
182
183
  )
@@ -512,62 +513,6 @@ class ctx:
512
513
 
513
514
  MetricsContext.record(metric)
514
515
 
515
- @overload
516
- @staticmethod
517
- async def read[Metric: State](
518
- metric: type[Metric],
519
- /,
520
- *,
521
- merged: bool = False,
522
- ) -> Metric | None: ...
523
-
524
- @overload
525
- @staticmethod
526
- async def read[Metric: State](
527
- metric: type[Metric],
528
- /,
529
- *,
530
- merged: bool = False,
531
- default: Metric,
532
- ) -> Metric: ...
533
-
534
- @staticmethod
535
- async def read[Metric: State](
536
- metric: type[Metric],
537
- /,
538
- *,
539
- merged: bool = False,
540
- default: Metric | None = None,
541
- ) -> Metric | None:
542
- """
543
- Read metric within current scope context.
544
-
545
- Parameters
546
- ----------
547
- metric: type[Metric]
548
- type of metric to be read from current context.
549
-
550
- merged: bool
551
- control wheather to merge metrics from nested scopes (True)\
552
- or access only the current scope value (False) without combining them
553
-
554
- default: Metric | None
555
- default value to return when metric was not recorded yet.
556
-
557
- Returns
558
- -------
559
- Metric | None
560
- """
561
-
562
- value: Metric | None = await MetricsContext.read(
563
- metric,
564
- merged=merged,
565
- )
566
- if value is None:
567
- return default
568
-
569
- return value
570
-
571
516
  @staticmethod
572
517
  def log_error(
573
518
  message: str,
haiway/context/metrics.py CHANGED
@@ -9,7 +9,6 @@ from haiway.state import State
9
9
  __all__ = [
10
10
  "MetricsContext",
11
11
  "MetricsHandler",
12
- "MetricsReading",
13
12
  "MetricsRecording",
14
13
  "MetricsScopeEntering",
15
14
  "MetricsScopeExiting",
@@ -26,18 +25,6 @@ class MetricsRecording(Protocol):
26
25
  ) -> None: ...
27
26
 
28
27
 
29
- @runtime_checkable
30
- class MetricsReading(Protocol):
31
- async def __call__[Metric: State](
32
- self,
33
- scope: ScopeIdentifier,
34
- /,
35
- *,
36
- metric: type[Metric],
37
- merged: bool,
38
- ) -> Metric | None: ...
39
-
40
-
41
28
  @runtime_checkable
42
29
  class MetricsScopeEntering(Protocol):
43
30
  def __call__[Metric: State](
@@ -58,7 +45,6 @@ class MetricsScopeExiting(Protocol):
58
45
 
59
46
  class MetricsHandler(State):
60
47
  record: MetricsRecording
61
- read: MetricsReading
62
48
  enter_scope: MetricsScopeEntering
63
49
  exit_scope: MetricsScopeExiting
64
50
 
@@ -114,30 +100,6 @@ class MetricsContext:
114
100
  exception=exc,
115
101
  )
116
102
 
117
- @classmethod
118
- async def read[Metric: State](
119
- cls,
120
- metric: type[Metric],
121
- /,
122
- merged: bool,
123
- ) -> Metric | None:
124
- try: # catch exceptions - we don't wan't to blow up on metrics
125
- metrics: Self = cls._context.get()
126
-
127
- if metrics._metrics is not None:
128
- return await metrics._metrics.read(
129
- metrics._scope,
130
- metric=metric,
131
- merged=merged,
132
- )
133
-
134
- except Exception as exc:
135
- LoggerContext.log_error(
136
- "Failed to read metric: %s",
137
- metric.__qualname__,
138
- exception=exc,
139
- )
140
-
141
103
  __slots__ = (
142
104
  "_metrics",
143
105
  "_scope",
haiway/helpers/metrics.py CHANGED
@@ -105,7 +105,6 @@ class MetricsHolder:
105
105
  store_handler: Self = cls()
106
106
  return MetricsHandler(
107
107
  record=store_handler.record,
108
- read=store_handler.read,
109
108
  enter_scope=store_handler.enter_scope,
110
109
  exit_scope=store_handler.exit_scope,
111
110
  )
@@ -135,23 +134,6 @@ class MetricsHolder:
135
134
 
136
135
  metrics[type(metric)] = metric
137
136
 
138
- async def read[Metric: State](
139
- self,
140
- scope: ScopeIdentifier,
141
- /,
142
- *,
143
- metric: type[Metric],
144
- merged: bool,
145
- ) -> Metric | None:
146
- assert self.root_scope is not None # nosec: B101
147
- assert scope.scope_id in self.scopes # nosec: B101
148
-
149
- if merged:
150
- return self.scopes[scope.scope_id].merged(metric)
151
-
152
- else:
153
- return cast(Metric | None, self.scopes[scope.scope_id].metrics.get(metric))
154
-
155
137
  def enter_scope[Metric: State](
156
138
  self,
157
139
  scope: ScopeIdentifier,
@@ -207,7 +189,6 @@ class MetricsLogger:
207
189
  )
208
190
  return MetricsHandler(
209
191
  record=logger_handler.record,
210
- read=logger_handler.read,
211
192
  enter_scope=logger_handler.enter_scope,
212
193
  exit_scope=logger_handler.exit_scope,
213
194
  )
@@ -251,23 +232,6 @@ class MetricsLogger:
251
232
  ):
252
233
  ctx.log_debug(f"Recorded metric:\n⎡ {type(metric).__qualname__}:{log}\n⌊")
253
234
 
254
- async def read[Metric: State](
255
- self,
256
- scope: ScopeIdentifier,
257
- /,
258
- *,
259
- metric: type[Metric],
260
- merged: bool,
261
- ) -> Metric | None:
262
- assert self.root_scope is not None # nosec: B101
263
- assert scope.scope_id in self.scopes # nosec: B101
264
-
265
- if merged:
266
- return self.scopes[scope.scope_id].merged(metric)
267
-
268
- else:
269
- return cast(Metric | None, self.scopes[scope.scope_id].metrics.get(metric))
270
-
271
235
  def enter_scope[Metric: State](
272
236
  self,
273
237
  scope: ScopeIdentifier,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haiway
3
- Version: 0.15.2
3
+ Version: 0.17.0
4
4
  Summary: Framework for dependency injection and state management within structured concurrency model.
5
5
  Project-URL: Homepage, https://miquido.com
6
6
  Project-URL: Repository, https://github.com/miquido/haiway.git
@@ -1,18 +1,18 @@
1
- haiway/__init__.py,sha256=XahuBwbI7ZFBBkcbs5882Go7QrzLtEq9XylQzuR1AJY,2125
1
+ haiway/__init__.py,sha256=6MMG7skee77t_K4dPDjL-TDt_6iYa-nQGBTXAGApWJ4,2083
2
2
  haiway/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- haiway/context/__init__.py,sha256=feqd0eJnGQwh4B8BZXpS0fQRE-DqoFCFOHipF1jOY8A,762
4
- haiway/context/access.py,sha256=yW6GNZtSWaxtBRTViP3BiJJYEsLbKkS6Zyzrp1uKgvo,19122
3
+ haiway/context/__init__.py,sha256=ZG9-bareYjGWZGGXChzGs0z0bh4hlisBJ6tDdS5w5Wo,720
4
+ haiway/context/access.py,sha256=SOwr4u7auS_E9Y4t6Bb5Z6ucjQw_1ZQtpyhvbND4A9A,17908
5
5
  haiway/context/disposables.py,sha256=vcsh8jRaJ8Q1ob7oh5LsrSPw9f5AMTcaD_p_Gb7tXAI,2588
6
6
  haiway/context/identifier.py,sha256=lz-FuspOtsaEsfb7QPrEVWYfbcMJgd3A6BGG3kLbaV0,3914
7
7
  haiway/context/logging.py,sha256=F3dr6MLjodg3MX5WTInxn3r3JuihG-giBzumI0GGUQw,5590
8
- haiway/context/metrics.py,sha256=N20XQtC8au_e_3iWrsZdej78YBEIWF44fdtWcZBWono,5223
8
+ haiway/context/metrics.py,sha256=WRcyRHDiHROluyYvnCt_Nk8sZ6-DXT_q-uVhedf_WDI,4244
9
9
  haiway/context/state.py,sha256=61SndKeMF3uS_HNeF-6gZUyVI6f4hi5pUXNG95VZLA8,5981
10
10
  haiway/context/tasks.py,sha256=VjYrsf9OxQb_m0etmEO0BAs0syLGC728E5TjkdMUMEE,2913
11
11
  haiway/context/types.py,sha256=VvJA7wAPZ3ISpgyThVguioYUXqhHf0XkPfRd0M1ERiQ,142
12
12
  haiway/helpers/__init__.py,sha256=ZKDlL3twDqXyI1a9FDgRy3m1-Dfycvke6BJ4C3CndEk,671
13
13
  haiway/helpers/asynchrony.py,sha256=pmPvlH4UiIaHXfQNsHvlDmzu5gCa8Pzc0_gNBAPgirU,6266
14
14
  haiway/helpers/caching.py,sha256=3M5JVI6dq-Xx6qI2DbLw2wek8U7xVjqbCZowldApXnc,13257
15
- haiway/helpers/metrics.py,sha256=VNxgPgV8pgt-51f2CANy1IVx8VMYIAxT3F849t3IeQs,14604
15
+ haiway/helpers/metrics.py,sha256=6F4WYDxm8Pqpq9JZWSw03miMTp4Ew2igGF2LtHJxOQ8,13563
16
16
  haiway/helpers/retries.py,sha256=3m1SsJW_YY_HPufX9LEzcd_MEyRRFNXvSExLeEti8W8,7539
17
17
  haiway/helpers/throttling.py,sha256=r9HnUuo4nX36Pf-oMFHUJk-ZCDeXQ__JTDHlkSltRhA,4121
18
18
  haiway/helpers/timeouted.py,sha256=DthIm4ytKhmiIKf-pcO_vrO1X-ImZh-sLNCWcLY9gfw,3337
@@ -37,7 +37,7 @@ haiway/utils/mimic.py,sha256=BkVjTVP2TxxC8GChPGyDV6UXVwJmiRiSWeOYZNZFHxs,1828
37
37
  haiway/utils/noop.py,sha256=qgbZlOKWY6_23Zs43OLukK2HagIQKRyR04zrFVm5rWI,344
38
38
  haiway/utils/queue.py,sha256=mF0wayKg6MegfBkgxghPDVCbX2rka6sX7KCzQCGl10s,4120
39
39
  haiway/utils/stream.py,sha256=Vqyi0EwcupkVyKQ7eple6z9DkcbSHkE-6yMw85mak9Q,2832
40
- haiway-0.15.2.dist-info/METADATA,sha256=7a2-GisdHxpclkxPfGlwN_ih9P4z0laUGNCz4HzlR4U,4299
41
- haiway-0.15.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
42
- haiway-0.15.2.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
43
- haiway-0.15.2.dist-info/RECORD,,
40
+ haiway-0.17.0.dist-info/METADATA,sha256=2G26J5-sV_PEm9hJIDfdRVxk41yQILsCJqRF4BJdHWU,4299
41
+ haiway-0.17.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
42
+ haiway-0.17.0.dist-info/licenses/LICENSE,sha256=3phcpHVNBP8jsi77gOO0E7rgKeDeu99Pi7DSnK9YHoQ,1069
43
+ haiway-0.17.0.dist-info/RECORD,,