Skip to content

Commit c4121c2

Browse files
committed
feat(uv): migrate to uv
BREAKING-CHANGE: see README.md for instructions #1
1 parent ee4e903 commit c4121c2

16 files changed

+308
-395
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

README.md

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,36 @@ optimal as it reduces necessary computation for expensive services and reduces
3434
With 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!
4142
def my_function(a: str = providers.ExistingSingleton("hello world")):
42-
return a
43+
return a
4344

4445

4546
if __name__ == "__main__":
46-
assert "hello world" == my_function()
47+
assert "hello world" == my_function()
4748
```
4849

4950
### Module Injection
5051

5152
With 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

5759
def my_function(a: str = providers.ExistingSingleton("hello world")):
58-
return a
60+
return a
5961

6062

6163
if __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
7577
override 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

8083
StringProvider = providers.ExistingSingleton("hello world")
8184

8285

8386
@wiring.inject
8487
def my_function(a: str = StringProvider):
85-
return a
88+
return a
8689

8790

8891
if __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

98101
If 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

103107
StringProvider = providers.ExistingSingleton("hello world")
104108

105109

106110
@wiring.inject
107111
def my_function(a: str = StringProvider):
108-
return a
112+
return a
109113

110114

111115
if __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

141145
2. Configure pre-commit hooks 🪝
@@ -149,7 +153,7 @@ If you would like to see more examples, feel free to check out [examples/](examp
149153
4. Run test cases 🧪
150154

151155
```shell
152-
pytest tests/
156+
pytest
153157
```
154158

155159
5. Submit a Pull Request ↖️

poetry.lock

Lines changed: 0 additions & 356 deletions
This file was deleted.

pyproject.toml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
[tool.poetry]
1+
[project]
22
name = "python-injection-framework"
33
version = "0.0.2"
44
description = "Another Python Dependency injector framework."
5-
authors = ["Zac Scott <[email protected]>"]
6-
license = "BSD-3"
75
readme = "README.md"
8-
packages = [{ include = "pif" }]
6+
requires-python = "<4.0,>=3.11"
7+
authors = [
8+
{ name = "Zac Scott", email = "[email protected]" },
9+
]
10+
license = { text = "BSD-3" }
11+
dependencies = []
912

10-
[tool.poetry.dependencies]
11-
python = "^3.10"
13+
[dependency-groups]
14+
dev = [
15+
"anybadge>=1.16.0",
16+
"coverage>=7.6.12",
17+
"pre-commit>=4.1.0",
18+
"pytest>=8.3.4",
19+
]
1220

1321
[tool.pytest.ini_options]
22+
pythonpath = "src"
1423
log_cli = true
1524
log_cli_level = "INFO"
1625
log_cli_format = "%(asctime)s [%(levelname)4s] [%(name)9s] %(message)s (%(filename)s:%(lineno)s)"
@@ -33,7 +42,3 @@ fixable = ["ALL"]
3342

3443
[tool.ruff.lint.per-file-ignores]
3544
"__init__.py" = ["F401"] # Unused imports
36-
37-
[build-system]
38-
requires = ["poetry-core"]
39-
build-backend = "poetry.core.masonry.api"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

pif/providers/factory.py renamed to src/pif/providers/factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
# https://github.com/scottzach1/python-injector-framework
1010

1111
import functools
12-
from typing import Callable, TypeVar
12+
from collections.abc import Callable
13+
from typing import TypeVar
1314

1415
from pif.providers.provider import Provider
1516
from pif.providers.util import intercept_args
File renamed without changes.

pif/providers/singleton.py renamed to src/pif/providers/singleton.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
# https://github.com/scottzach1/python-injector-framework
1010

1111
import functools
12-
from typing import Callable, TypeVar
12+
from collections.abc import Callable
13+
from typing import TypeVar
1314

1415
from pif.providers.provider import Provider
1516
from pif.providers.util import intercept_args
File renamed without changes.

pif/wiring.py renamed to src/pif/wiring.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
import inspect
1414
import itertools
1515
import types
16-
from typing import Any, Callable, TypeVar
16+
from collections.abc import Callable
17+
from typing import Any, TypeVar
1718

1819
from pif.providers.provider import Provider
1920

tests/test_providers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from collections import namedtuple
22

33
import pytest
4-
54
from pif import exceptions, providers
65

76

0 commit comments

Comments
 (0)