ashka-lifecycle 0.2.1__tar.gz → 0.2.2__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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: ashka-lifecycle
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: dishka lifecycle support
5
5
  Author: handsome-Druid
6
6
  Author-email: handsome-Druid <102826168@qq.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ashka-lifecycle"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "dishka lifecycle support"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10,<3.15"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ashka-lifecycle"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  description = "dishka lifecycle support"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -23,6 +23,7 @@ async def __aenter__(self: AsyncContainer) -> AsyncContainer:
23
23
  aenter: AsyncContainer = await _aenter(self)
24
24
 
25
25
  if self.scope is Scope.APP:
26
+ _logger.debug("Initiating bootstrap factories.")
26
27
  await gather(
27
28
  *(
28
29
  self.get(key.type_hint, key.component)
@@ -30,6 +31,10 @@ async def __aenter__(self: AsyncContainer) -> AsyncContainer:
30
31
  if key.type_hint in bootstrap_types
31
32
  )
32
33
  )
34
+ else:
35
+ _logger.debug(
36
+ f"'<dishka_container>.scope': {self.scope!r} is not 'Scope.APP', skipping bootstrap"
37
+ )
33
38
 
34
39
  return aenter
35
40
 
@@ -37,7 +42,7 @@ async def __aenter__(self: AsyncContainer) -> AsyncContainer:
37
42
  async def init(self: AsyncContainer) -> None:
38
43
  if not self.scope is Scope.APP:
39
44
  _logger.warning(
40
- f"With scope = {self.scope}, container.init() won't do any bootstrap."
45
+ f"'<dishka_container>.scope': {self.scope!r} is not 'Scope.APP', 'container.init()' won't do any bootstrap."
41
46
  )
42
47
  await self.__aenter__()
43
48
 
@@ -20,9 +20,14 @@ def __enter__(self: Container) -> Container:
20
20
  enter: Container = _enter(self)
21
21
 
22
22
  if self.scope is Scope.APP:
23
+ _logger.debug("Initiating bootstrap factories.")
23
24
  for key in self.registry.factories:
24
25
  if key.type_hint in bootstrap_types:
25
26
  self.get(key.type_hint, key.component)
27
+ else:
28
+ _logger.debug(
29
+ f"'<dishka_container>.scope': {self.scope!r} is not 'Scope.APP', skipping bootstrap"
30
+ )
26
31
 
27
32
  return enter
28
33
 
@@ -30,7 +35,7 @@ def __enter__(self: Container) -> Container:
30
35
  def init(self: Container) -> None:
31
36
  if not self.scope is Scope.APP:
32
37
  _logger.warning(
33
- f"With scope = {self.scope}, container.init() won't do any bootstrap."
38
+ f"'<dishka_container>.scope': {self.scope!r} is not 'Scope.APP', 'container.init()' won't do any bootstrap."
34
39
  )
35
40
  self.__enter__()
36
41
 
@@ -1,5 +1,6 @@
1
1
  from collections.abc import Callable
2
2
  from inspect import isbuiltin, isclass, isfunction
3
+ from logging import getLogger
3
4
  from typing import Any, NewType, get_origin, get_type_hints, overload
4
5
 
5
6
  from ashka_lifecycle.entities.bootstrap import (
@@ -20,6 +21,8 @@ from dishka.provider.make_factory import (
20
21
 
21
22
  __all__: list[str] = ["provide"]
22
23
 
24
+ _logger = getLogger(__name__)
25
+
23
26
 
24
27
  def activate(): ...
25
28
 
@@ -55,6 +58,14 @@ def provide(
55
58
  return _provide(source, scope=scope, **kwargs)
56
59
 
57
60
  def scoped(source: ProvideSource) -> CompositeDependencySource: # pyright: ignore[reportUnknownParameterType]
61
+ _logger.debug(
62
+ f"Adding {getattr(source, '__name__', source)!r} to bootstrap list..." # pyright: ignore[reportUnknownArgumentType]
63
+ )
64
+ bootstrap_types.add(
65
+ new_type := NewType(
66
+ "ashka_lifecycle.provider.make_factory.provide", AshkaScope
67
+ )
68
+ )
58
69
  try:
59
70
  return (
60
71
  _provide(
@@ -65,8 +76,7 @@ def provide(
65
76
  ],
66
77
  **_kwargs,
67
78
  )
68
- if bootstrap_types.add(new_type := NewType("_", object)) is None
69
- and (provides := "provides") in kwargs
79
+ if (provides := "provides") in kwargs
70
80
  else _provide(
71
81
  source,
72
82
  scope=Scope.APP,
@@ -94,6 +104,7 @@ def provide(
94
104
  )
95
105
  )
96
106
  except KeyError as e:
107
+ bootstrap_types.remove(new_type)
97
108
  raise MissingReturnHintError(source) from e
98
109
 
99
110
  return scoped if source is None else scoped(source) # pyright: ignore[reportUnknownVariableType]