python-injection 0.19.6__tar.gz → 0.19.7__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.
Files changed (32) hide show
  1. {python_injection-0.19.6 → python_injection-0.19.7}/PKG-INFO +9 -3
  2. {python_injection-0.19.6 → python_injection-0.19.7}/README.md +8 -2
  3. python_injection-0.19.7/injection/_core/common/threading.py +11 -0
  4. {python_injection-0.19.6 → python_injection-0.19.7}/pyproject.toml +1 -1
  5. python_injection-0.19.6/injection/_core/common/threading.py +0 -7
  6. {python_injection-0.19.6 → python_injection-0.19.7}/.gitignore +0 -0
  7. {python_injection-0.19.6 → python_injection-0.19.7}/LICENSE +0 -0
  8. {python_injection-0.19.6 → python_injection-0.19.7}/injection/__init__.py +0 -0
  9. {python_injection-0.19.6 → python_injection-0.19.7}/injection/__init__.pyi +0 -0
  10. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/__init__.py +0 -0
  11. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/asfunction.py +0 -0
  12. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/common/__init__.py +0 -0
  13. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/common/asynchronous.py +0 -0
  14. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/common/event.py +0 -0
  15. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/common/invertible.py +0 -0
  16. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/common/key.py +0 -0
  17. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/common/lazy.py +0 -0
  18. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/common/type.py +0 -0
  19. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/descriptors.py +0 -0
  20. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/injectables.py +0 -0
  21. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/module.py +0 -0
  22. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/scope.py +0 -0
  23. {python_injection-0.19.6 → python_injection-0.19.7}/injection/_core/slots.py +0 -0
  24. {python_injection-0.19.6 → python_injection-0.19.7}/injection/entrypoint.py +0 -0
  25. {python_injection-0.19.6 → python_injection-0.19.7}/injection/exceptions.py +0 -0
  26. {python_injection-0.19.6 → python_injection-0.19.7}/injection/ext/__init__.py +0 -0
  27. {python_injection-0.19.6 → python_injection-0.19.7}/injection/ext/fastapi.py +0 -0
  28. {python_injection-0.19.6 → python_injection-0.19.7}/injection/ext/fastapi.pyi +0 -0
  29. {python_injection-0.19.6 → python_injection-0.19.7}/injection/loaders.py +0 -0
  30. {python_injection-0.19.6 → python_injection-0.19.7}/injection/py.typed +0 -0
  31. {python_injection-0.19.6 → python_injection-0.19.7}/injection/testing/__init__.py +0 -0
  32. {python_injection-0.19.6 → python_injection-0.19.7}/injection/testing/__init__.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-injection
3
- Version: 0.19.6
3
+ Version: 0.19.7
4
4
  Summary: Fast and easy dependency injection framework.
5
5
  Project-URL: Repository, https://github.com/100nm/python-injection
6
6
  Author: remimd
@@ -92,8 +92,14 @@ if __name__ == "__main__":
92
92
 
93
93
  ## Resources
94
94
 
95
- > ⚠️ The package isn't threadsafe, for better performance in single-threaded applications and those using `asyncio`.
96
- > So remember to use `threading.Lock` if you're writing a multithreaded program.
95
+ > ⚠️ The package isn't threadsafe by default, for better performance in single-threaded applications and those using
96
+ > `asyncio`.
97
+ >
98
+ > Non-threadsafe functions are those that resolve dependencies or define scopes. They all come with an optional
99
+ > parameter `threadsafe`.
100
+ >
101
+ > You can set `PYTHON_INJECTION_THREADSAFE=1` in environment variables to make the package fully threadsafe. The
102
+ > environment variable is resolved at the **Python module level**, so be careful if the variable is defined dynamically.
97
103
 
98
104
  * [**Basic usage**](https://github.com/100nm/python-injection/tree/prod/documentation/basic-usage.md)
99
105
  * [**Scoped dependencies**](https://github.com/100nm/python-injection/tree/prod/documentation/scoped-dependencies.md)
@@ -64,8 +64,14 @@ if __name__ == "__main__":
64
64
 
65
65
  ## Resources
66
66
 
67
- > ⚠️ The package isn't threadsafe, for better performance in single-threaded applications and those using `asyncio`.
68
- > So remember to use `threading.Lock` if you're writing a multithreaded program.
67
+ > ⚠️ The package isn't threadsafe by default, for better performance in single-threaded applications and those using
68
+ > `asyncio`.
69
+ >
70
+ > Non-threadsafe functions are those that resolve dependencies or define scopes. They all come with an optional
71
+ > parameter `threadsafe`.
72
+ >
73
+ > You can set `PYTHON_INJECTION_THREADSAFE=1` in environment variables to make the package fully threadsafe. The
74
+ > environment variable is resolved at the **Python module level**, so be careful if the variable is defined dynamically.
69
75
 
70
76
  * [**Basic usage**](https://github.com/100nm/python-injection/tree/prod/documentation/basic-usage.md)
71
77
  * [**Scoped dependencies**](https://github.com/100nm/python-injection/tree/prod/documentation/scoped-dependencies.md)
@@ -0,0 +1,11 @@
1
+ from contextlib import nullcontext
2
+ from os import getenv
3
+ from threading import RLock
4
+ from typing import Any, ContextManager, Final
5
+
6
+ _PYTHON_INJECTION_THREADSAFE: Final[bool] = bool(getenv("PYTHON_INJECTION_THREADSAFE"))
7
+
8
+
9
+ def get_lock(threadsafe: bool | None = None) -> ContextManager[Any]:
10
+ cond = _PYTHON_INJECTION_THREADSAFE if threadsafe is None else threadsafe
11
+ return RLock() if cond else nullcontext()
@@ -30,7 +30,7 @@ test = [
30
30
 
31
31
  [project]
32
32
  name = "python-injection"
33
- version = "0.19.6"
33
+ version = "0.19.7"
34
34
  description = "Fast and easy dependency injection framework."
35
35
  license = "MIT"
36
36
  license-files = ["LICENSE"]
@@ -1,7 +0,0 @@
1
- from contextlib import nullcontext
2
- from threading import RLock
3
- from typing import Any, ContextManager
4
-
5
-
6
- def get_lock(threadsafe: bool | None = None) -> ContextManager[Any]:
7
- return RLock() if threadsafe else nullcontext()