python-injection 0.18.0.post1__py3-none-any.whl → 0.18.2__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.
injection/_core/module.py CHANGED
@@ -156,6 +156,12 @@ class ModulePriorityUpdated(ModuleEvent):
156
156
  )
157
157
 
158
158
 
159
+ @dataclass(frozen=True, slots=True)
160
+ class UnlockCalled(Event):
161
+ def __str__(self) -> str:
162
+ return "An `unlock` method has been called."
163
+
164
+
159
165
  """
160
166
  Broker
161
167
  """
@@ -802,8 +808,11 @@ class Module(Broker, EventListener):
802
808
  return self
803
809
 
804
810
  def unlock(self) -> Self:
805
- for broker in self.__brokers:
806
- broker.unlock()
811
+ event = UnlockCalled()
812
+
813
+ with self.dispatch(event, lock_bypass=True):
814
+ for broker in self.__brokers:
815
+ broker.unlock()
807
816
 
808
817
  return self
809
818
 
@@ -816,11 +825,11 @@ class Module(Broker, EventListener):
816
825
  self.unlock().init_modules(*modules)
817
826
 
818
827
  @contextmanager
819
- def cleaner() -> Iterator[Self]:
828
+ def unload() -> Iterator[Self]:
820
829
  yield self
821
830
  self.unlock().init_modules()
822
831
 
823
- return cleaner()
832
+ return unload()
824
833
 
825
834
  async def all_ready(self) -> None:
826
835
  for broker in self.__brokers:
@@ -838,20 +847,20 @@ class Module(Broker, EventListener):
838
847
  self.__channel.remove_listener(listener)
839
848
  return self
840
849
 
841
- def on_event(self, event: Event, /) -> ContextManager[None] | None:
850
+ def on_event(self, event: Event, /) -> ContextManager[None]:
842
851
  self_event = ModuleEventProxy(self, event)
843
852
  return self.dispatch(self_event)
844
853
 
845
854
  @contextmanager
846
- def dispatch(self, event: Event) -> Iterator[None]:
847
- self.__check_locking()
855
+ def dispatch(self, event: Event, *, lock_bypass: bool = False) -> Iterator[None]:
856
+ if not lock_bypass:
857
+ self.__check_locking()
848
858
 
849
859
  with self.__channel.dispatch(event):
850
860
  try:
851
861
  yield
852
862
  finally:
853
- message = str(event)
854
- self.__debug(message)
863
+ self.__debug(event)
855
864
 
856
865
  def __debug(self, message: object) -> None:
857
866
  for logger in self.__loggers:
injection/entrypoint.py CHANGED
@@ -105,6 +105,14 @@ class Entrypoint[**P, T]:
105
105
  ) -> Self:
106
106
  return self.setup(lambda: loader.load(*packages))
107
107
 
108
+ def load_profile(self, /, *names: str) -> Self:
109
+ @contextmanager
110
+ def decorator(module: Module) -> Iterator[None]:
111
+ with module.load_profile(*names):
112
+ yield
113
+
114
+ return self.decorate(decorator(self.module))
115
+
108
116
  def setup(self, function: Callable[..., Any], /) -> Self:
109
117
  @contextmanager
110
118
  def decorator() -> Iterator[Any]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.18.0.post1
3
+ Version: 0.18.2
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Project-URL: Repository, https://github.com/100nm/python-injection
6
6
  Author: remimd
@@ -1,13 +1,13 @@
1
1
  injection/__init__.py,sha256=7ZRUlO5EEPWO7IlbYHD-8DOX-cg4Np4nYq5fpw-U56o,1259
2
2
  injection/__init__.pyi,sha256=O2W6ZWcwH58JnDmJNkJ6cdoaO0D2NE7PEVFgfJNTwB0,10717
3
- injection/entrypoint.py,sha256=UImrgGmzbkjVZemzzmpr-5hazej3NdI65_RuUbyHuJs,4205
3
+ injection/entrypoint.py,sha256=oTOwU2MXAaATuawADQ4KOPp5Tet2gL4dJD0IdClZ8sY,4461
4
4
  injection/exceptions.py,sha256=v57yMujiq6H_zwwn30A8UYEZX9R9k-bY8FnsdaimPM4,1025
5
5
  injection/loaders.py,sha256=8tS3zVvmxKf5E1ZJBTBjZpHkXETxNCL1dq8rbh2vzy4,4075
6
6
  injection/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  injection/_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  injection/_core/descriptors.py,sha256=jH0pyIlPurMmU4yXr-HKS_7BJ-9d0XUvEx4pQre3QeI,704
9
9
  injection/_core/injectables.py,sha256=Rg1nxDkbcpeX4ELohrNVMguPhN36SNQuD0JKfyfL6bI,6192
10
- injection/_core/module.py,sha256=7jTp3dHHQqJ_b95iHHMp9TKRF794Msgla7UfBsLysV8,31988
10
+ injection/_core/module.py,sha256=uQ3XecRoskPSidz9_eosfHnILAC4jQUeYMJS2uMSa1A,32243
11
11
  injection/_core/scope.py,sha256=OBzVY1mUApryqIZKQtwHz7wiuY13MfouyaHp50DpWeQ,8300
12
12
  injection/_core/slots.py,sha256=g9TG6CbqRzCsjg01iPyfRtTTUCJnnJOwcj9mJabH0dc,37
13
13
  injection/_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -22,7 +22,7 @@ injection/ext/fastapi.py,sha256=layUUer5IWiZX6Mmx1_RCYDLNCtEHtpya5ZL6TTBOkY,968
22
22
  injection/ext/fastapi.pyi,sha256=8OZEUjHFB9n7QXv_dtXdDuXW-r2huQEFsJ03gJOOvwQ,125
23
23
  injection/testing/__init__.py,sha256=PsrvNxYvn11if8CJpEYxcTxniqMt2w_7fBaDkY9RA5o,898
24
24
  injection/testing/__init__.pyi,sha256=iOii0i9F5n7znltGeGQYI2KXC_if9SAogLh1h03yx-0,540
25
- python_injection-0.18.0.post1.dist-info/METADATA,sha256=D9sJDVaoT9GZdhm0WmbB0v_e5WqqrRL44tvbTsEVxLc,3403
26
- python_injection-0.18.0.post1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- python_injection-0.18.0.post1.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
28
- python_injection-0.18.0.post1.dist-info/RECORD,,
25
+ python_injection-0.18.2.dist-info/METADATA,sha256=wDfJH-b-1sFSofUm1YwhDWZVbFt-E0QZjWR9Icwa_HA,3397
26
+ python_injection-0.18.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ python_injection-0.18.2.dist-info/licenses/LICENSE,sha256=oC77BOa9kaaQni5rW-Z-ytz3E5h4EVg248BHg9UFgyg,1063
28
+ python_injection-0.18.2.dist-info/RECORD,,