engin 0.0.5__py3-none-any.whl → 0.0.7__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.
engin/_dependency.py CHANGED
@@ -136,7 +136,7 @@ class Provide(Dependency[Any, T]):
136
136
  return_type = self._func # __init__ returns self
137
137
  else:
138
138
  try:
139
- return_type = get_type_hints(self._func)["return"]
139
+ return_type = get_type_hints(self._func, include_extras=True)["return"]
140
140
  except KeyError as err:
141
141
  raise RuntimeError(
142
142
  f"Dependency '{self.name}' requires a return typehint"
engin/_engin.py CHANGED
@@ -35,8 +35,7 @@ class Engin:
35
35
  Supply) and at least one invocation (Invoke or Entrypoint).
36
36
 
37
37
  When instantiated the Engin can be run. This is typically done via the `run` method,
38
- but certain use cases, e.g. testing, it can be easier to use the `start` and `stop`
39
- methods.
38
+ but for advanced usecases it can be easier to use the `start` and `stop` methods.
40
39
 
41
40
  When ran the Engin takes care of the complete application lifecycle:
42
41
  1. The Engin assembles all Invocations. Only Providers that are required to satisfy
@@ -81,8 +80,6 @@ class Engin:
81
80
  Args:
82
81
  *options: an instance of Provide, Supply, Invoke, Entrypoint or a Block.
83
82
  """
84
- self._providers: dict[TypeId, Provide] = {TypeId.from_type(Engin): Provide(self._self)}
85
- self._invokables: list[Invoke] = []
86
83
 
87
84
  self._stop_requested_event = Event()
88
85
  self._stop_complete_event = Event()
@@ -90,8 +87,16 @@ class Engin:
90
87
  self._shutdown_task: Task | None = None
91
88
  self._run_task: Task | None = None
92
89
 
90
+ # TODO: refactor _destruct_options and related attributes into a dedicated class?
91
+ self._providers: dict[TypeId, Provide] = {TypeId.from_type(Engin): Provide(self._self)}
92
+ self._multiproviders: dict[TypeId, list[Provide]] = {}
93
+ self._invocations: list[Invoke] = []
94
+ # populates the above
93
95
  self._destruct_options(chain(self._LIB_OPTIONS, options))
94
- self._assembler = Assembler(self._providers.values())
96
+ multi_providers = [p for multi in self._multiproviders.values() for p in multi]
97
+ self._assembler = Assembler(chain(self._providers.values(), multi_providers))
98
+ self._providers.clear()
99
+ self._multiproviders.clear()
95
100
 
96
101
  @property
97
102
  def assembler(self) -> Assembler:
@@ -119,7 +124,7 @@ class Engin:
119
124
  """
120
125
  LOG.info("starting engin")
121
126
  assembled_invocations: list[AssembledDependency] = [
122
- await self._assembler.assemble(invocation) for invocation in self._invokables
127
+ await self._assembler.assemble(invocation) for invocation in self._invocations
123
128
  ]
124
129
 
125
130
  for invocation in assembled_invocations:
@@ -153,6 +158,8 @@ class Engin:
153
158
  started.
154
159
  """
155
160
  self._stop_requested_event.set()
161
+ if self._shutdown_task is None:
162
+ return
156
163
  await self._stop_complete_event.wait()
157
164
 
158
165
  async def _shutdown(self) -> None:
@@ -170,12 +177,19 @@ class Engin:
170
177
  if isinstance(opt, Block):
171
178
  self._destruct_options(opt)
172
179
  if isinstance(opt, Provide | Supply):
173
- existing = self._providers.get(opt.return_type_id)
174
- self._log_option(opt, overwrites=existing)
175
- self._providers[opt.return_type_id] = opt
180
+ if not opt.is_multiprovider:
181
+ existing = self._providers.get(opt.return_type_id)
182
+ self._log_option(opt, overwrites=existing)
183
+ self._providers[opt.return_type_id] = opt
184
+ else:
185
+ self._log_option(opt)
186
+ if opt.return_type_id in self._multiproviders:
187
+ self._multiproviders[opt.return_type_id].append(opt)
188
+ else:
189
+ self._multiproviders[opt.return_type_id] = [opt]
176
190
  elif isinstance(opt, Invoke):
177
191
  self._log_option(opt)
178
- self._invokables.append(opt)
192
+ self._invocations.append(opt)
179
193
 
180
194
  @staticmethod
181
195
  def _log_option(opt: Dependency, overwrites: Dependency | None = None) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: engin
3
- Version: 0.0.5
3
+ Version: 0.0.7
4
4
  Summary: An async-first modular application framework
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.10
@@ -1,8 +1,8 @@
1
1
  engin/__init__.py,sha256=yTc8k0HDGMIrxDdEEA90qGD_dExQjVIbXCyaOFRrnMg,508
2
2
  engin/_assembler.py,sha256=VCZA_Gq4hnH5LueB_vEVqsKbGXx-nI6KQ65YhzXw-VY,7575
3
3
  engin/_block.py,sha256=-5qTp1Hdm3H54nScDGitFpcXRHLIyVHlDYATg_3dnPw,2045
4
- engin/_dependency.py,sha256=oh1T7oR-c9MGcZ6ZFUgPnvHRf-n6AIvpbm59R97To80,5404
5
- engin/_engin.py,sha256=kk3U_SZLlGYDbFbPYmErvlRqKE855yPvHBlX6XH2Row,8212
4
+ engin/_dependency.py,sha256=vqBwKNHH_V3MZZQ29A1zWknFSkkzghJgpWN0mjvjtyY,5425
5
+ engin/_engin.py,sha256=lPce5p4fCz2AdBdmXdEFvehryIi4FPmD0zjvDFcL8Jc,8987
6
6
  engin/_exceptions.py,sha256=fsc4pTOIGHUh0x7oZhEXPJUTE268sIhswLoiqXaudiw,635
7
7
  engin/_lifecycle.py,sha256=_jQnGFj4RYXsxMpcXPJQagFOwnoTVh7oSN8oUYoYuW0,3246
8
8
  engin/_type_utils.py,sha256=C71kX2Dr-gluGSL018K4uihX3zkTe7QNWaHhFU10ZmA,2127
@@ -10,7 +10,7 @@ engin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  engin/ext/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  engin/ext/asgi.py,sha256=6vuC4zIhsvAdmwRn2I6uuUWPYfqobox1dv7skg2OWwE,1940
12
12
  engin/ext/fastapi.py,sha256=CH2Zi7Oh_Va0TJGx05e7_LqAiCsoI1qcu0Z59_rgfRk,899
13
- engin-0.0.5.dist-info/METADATA,sha256=7qu0kb9zWAZWkp0osgHkCqFKBwKykvYUrH4JcbmBY_M,1806
14
- engin-0.0.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
- engin-0.0.5.dist-info/licenses/LICENSE,sha256=XHh5LPUPKZWTBqBv2xxN2RU7D59nHoiJGb5RIt8f45w,1070
16
- engin-0.0.5.dist-info/RECORD,,
13
+ engin-0.0.7.dist-info/METADATA,sha256=mnVPfy7Bdtd_ilWcVn2zHyw1utyepBx3inRlAi3BCHc,1806
14
+ engin-0.0.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
+ engin-0.0.7.dist-info/licenses/LICENSE,sha256=XHh5LPUPKZWTBqBv2xxN2RU7D59nHoiJGb5RIt8f45w,1070
16
+ engin-0.0.7.dist-info/RECORD,,
File without changes