io-adapters 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.
- {io_adapters-0.2.1 → io_adapters-0.2.2}/LICENSE +1 -1
- {io_adapters-0.2.1 → io_adapters-0.2.2}/PKG-INFO +3 -3
- {io_adapters-0.2.1 → io_adapters-0.2.2}/README.md +2 -2
- {io_adapters-0.2.1 → io_adapters-0.2.2}/pyproject.toml +1 -1
- {io_adapters-0.2.1 → io_adapters-0.2.2}/src/io_adapters/_adapters.py +3 -3
- {io_adapters-0.2.1 → io_adapters-0.2.2}/src/io_adapters/_container.py +8 -2
- {io_adapters-0.2.1 → io_adapters-0.2.2}/src/io_adapters/__init__.py +0 -0
- {io_adapters-0.2.1 → io_adapters-0.2.2}/src/io_adapters/_clock.py +0 -0
- {io_adapters-0.2.1 → io_adapters-0.2.2}/src/io_adapters/_io_funcs.py +0 -0
- {io_adapters-0.2.1 → io_adapters-0.2.2}/src/io_adapters/_registries.py +0 -0
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: io-adapters
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Dependency Injection Adapters
|
|
5
5
|
Author: ed cuss
|
|
6
6
|
Author-email: ed cuss <edcussmusic@gmail.com>
|
|
@@ -109,7 +109,7 @@ orders_adapter: RealAdapter = get_real_adapter("orders")
|
|
|
109
109
|
some_usecase(orders_adapter, "some/path/to/file.json")
|
|
110
110
|
|
|
111
111
|
|
|
112
|
-
# in testing inject the fake which has all the same funcitonality as the
|
|
112
|
+
# in testing inject the fake which has all the same funcitonality as the
|
|
113
113
|
# `RealAdapter` and assert that the fakes end state is as expected
|
|
114
114
|
fake = get_fake_adapter("orders")
|
|
115
115
|
some_usecase(fake, "some/path/to/file.json")
|
|
@@ -147,4 +147,4 @@ assert fake.files["some/path/to/file.json"] == {"a": 1}
|
|
|
147
147
|
├── ruff.toml
|
|
148
148
|
└── uv.lock
|
|
149
149
|
::
|
|
150
|
-
```
|
|
150
|
+
```
|
|
@@ -97,7 +97,7 @@ orders_adapter: RealAdapter = get_real_adapter("orders")
|
|
|
97
97
|
some_usecase(orders_adapter, "some/path/to/file.json")
|
|
98
98
|
|
|
99
99
|
|
|
100
|
-
# in testing inject the fake which has all the same funcitonality as the
|
|
100
|
+
# in testing inject the fake which has all the same funcitonality as the
|
|
101
101
|
# `RealAdapter` and assert that the fakes end state is as expected
|
|
102
102
|
fake = get_fake_adapter("orders")
|
|
103
103
|
some_usecase(fake, "some/path/to/file.json")
|
|
@@ -135,4 +135,4 @@ assert fake.files["some/path/to/file.json"] == {"a": 1}
|
|
|
135
135
|
├── ruff.toml
|
|
136
136
|
└── uv.lock
|
|
137
137
|
::
|
|
138
|
-
```
|
|
138
|
+
```
|
|
@@ -165,13 +165,13 @@ class FakeAdapter(IoAdapter):
|
|
|
165
165
|
self.guid_fn = self.guid_fn or fake_guid
|
|
166
166
|
self.datetime_fn = self.datetime_fn or fake_datetime
|
|
167
167
|
|
|
168
|
-
def _read_fn(self, path: str) -> Data:
|
|
168
|
+
def _read_fn(self, path: str | Path) -> Data:
|
|
169
169
|
try:
|
|
170
|
-
return self.files[path]
|
|
170
|
+
return self.files[str(path)]
|
|
171
171
|
except KeyError as e:
|
|
172
172
|
raise FileNotFoundError(f"{path = } {self.files = }") from e
|
|
173
173
|
|
|
174
|
-
def _write_fn(self, data: Data, path: str) -> None:
|
|
174
|
+
def _write_fn(self, data: Data, path: str | Path) -> None:
|
|
175
175
|
self.files[str(path)] = data
|
|
176
176
|
|
|
177
177
|
def get_guid(self) -> str:
|
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import logging
|
|
4
4
|
from collections.abc import Callable, Hashable, Iterable
|
|
5
5
|
from enum import Enum, auto
|
|
6
|
+
from typing import TypeAlias
|
|
6
7
|
|
|
7
8
|
import attrs
|
|
8
9
|
from attrs.validators import deep_iterable, instance_of
|
|
@@ -18,6 +19,9 @@ class _FnType(Enum):
|
|
|
18
19
|
WRITE = auto()
|
|
19
20
|
|
|
20
21
|
|
|
22
|
+
DomainFns: TypeAlias = dict[Hashable, dict[Hashable, Callable]]
|
|
23
|
+
|
|
24
|
+
|
|
21
25
|
@attrs.define
|
|
22
26
|
class Container:
|
|
23
27
|
"""Registry and factory for domain-scoped I/O adapters.
|
|
@@ -92,10 +96,12 @@ class Container:
|
|
|
92
96
|
"""
|
|
93
97
|
|
|
94
98
|
domains: Iterable = attrs.field(validator=deep_iterable(member_validator=instance_of(Hashable)))
|
|
95
|
-
domain_fns:
|
|
99
|
+
domain_fns: DomainFns = attrs.field(init=False)
|
|
96
100
|
|
|
97
101
|
def __attrs_post_init__(self) -> None:
|
|
98
|
-
self.domain_fns
|
|
102
|
+
self.domain_fns: DomainFns = {
|
|
103
|
+
domain: {_FnType.READ: {}, _FnType.WRITE: {}} for domain in self.domains
|
|
104
|
+
}
|
|
99
105
|
|
|
100
106
|
def add_domain(self, domain: Hashable) -> None:
|
|
101
107
|
"""Add a domain to a ``Container``
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|