@@ -34,34 +34,36 @@ optimal as it reduces necessary computation for expensive services and reduces
3434With this approach you can automatically inject functions at load time using the ` @wiring.inject ` decorator.
3535
3636``` python
37- from pif import wiring, providers
37+ from pif import providers
38+ from pif import wiring
3839
3940
4041@wiring.inject # <- automatically injects providers.Provider default arguments!
4142def my_function (a : str = providers.ExistingSingleton(" hello world" )):
42- return a
43+ return a
4344
4445
4546if __name__ == " __main__" :
46- assert " hello world" == my_function()
47+ assert " hello world" == my_function()
4748```
4849
4950### Module Injection
5051
5152With this approach you can wire all methods in the specified modules.
5253
5354``` python
54- from pif import wiring, providers
55+ from pif import providers
56+ from pif import wiring
5557
5658
5759def my_function (a : str = providers.ExistingSingleton(" hello world" )):
58- return a
60+ return a
5961
6062
6163if __name__ == " __main__" :
62- wiring.wire([__name__ ]) # <- dynamically inject methods with providers.Provider default arguments!
64+ wiring.wire([__name__ ]) # <- dynamically inject methods with providers.Provider default arguments!
6365
64- assert " hello world" == my_function()
66+ assert " hello world" == my_function()
6567```
6668
6769### Overriding
@@ -75,53 +77,55 @@ If you want to patch a value all you need to do is call `.override()` on the pro
7577override an existing singleton you may call the convenience method ` .override_existing() ` .
7678
7779``` python
78- from pif import wiring, providers
80+ from pif import providers
81+ from pif import wiring
7982
8083StringProvider = providers.ExistingSingleton(" hello world" )
8184
8285
8386@wiring.inject
8487def my_function (a : str = StringProvider):
85- return a
88+ return a
8689
8790
8891if __name__ == " __main__" :
89- assert " hello world" == my_function()
92+ assert " hello world" == my_function()
9093
91- override = StringProvider.override_existing(" overridden_1" )
94+ override = StringProvider.override_existing(" overridden_1" )
9295
93- assert " overridden_1"
96+ assert " overridden_1"
9497```
9598
9699### Context Managers
97100
98101If you want more control around the override lifecycles then you may use the ` Override ` context manager.
99102
100103``` python
101- from pif import wiring, providers
104+ from pif import providers
105+ from pif import wiring
102106
103107StringProvider = providers.ExistingSingleton(" hello world" )
104108
105109
106110@wiring.inject
107111def my_function (a : str = StringProvider):
108- return a
112+ return a
109113
110114
111115if __name__ == " __main__" :
112- assert " hello world" == my_function()
116+ assert " hello world" == my_function()
113117
114- OverrideProvider = providers.ExistingSingleton(" overridden_1" )
118+ OverrideProvider = providers.ExistingSingleton(" overridden_1" )
115119
116- with StringProvider.override(OverrideProvider):
117- assert " overridden_1" == my_function()
120+ with StringProvider.override(OverrideProvider):
121+ assert " overridden_1" == my_function()
118122
119- with OverrideProvider.override_existing(" overridden_2" ):
120- assert " overridden_2" == my_function() # You can even stack overrides!!
123+ with OverrideProvider.override_existing(" overridden_2" ):
124+ assert " overridden_2" == my_function() # You can even stack overrides!!
121125
122- assert " overridden_1" == my_function()
126+ assert " overridden_1" == my_function()
123127
124- assert " hello world" == my_function()
128+ assert " hello world" == my_function()
125129```
126130
127131## Examples
@@ -130,12 +134,12 @@ If you would like to see more examples, feel free to check out [examples/](examp
130134
131135## Contributing
132136
133- 1 . Clone the repository and configure Poetry 🪄
137+ 1 . Clone the repository and setup with uv 🪄
134138
135139 ``` shell
136140 git clone
[email protected] :scottzach1/Python-Injection-Framework.git
137141 cd Python-Injection-Framework
138- poetry install
142+ uv sync --dev
139143 ```
140144
1411452. Configure pre-commit hooks 🪝
@@ -149,7 +153,7 @@ If you would like to see more examples, feel free to check out [examples/](examp
1491534. Run test cases 🧪
150154
151155 ` ` ` shell
152- pytest tests/
156+ pytest
153157 ` ` `
154158
1551595. Submit a Pull Request ↖️
0 commit comments