omdev 0.0.0.dev29__py3-none-any.whl → 0.0.0.dev31__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.
omdev/cache/comp/types.py DELETED
@@ -1,92 +0,0 @@
1
- import abc
2
- import typing as ta
3
-
4
- from omlish import cached
5
- from omlish import collections as col
6
- from omlish import dataclasses as dc
7
- from omlish import lang
8
-
9
-
10
- T = ta.TypeVar('T')
11
-
12
-
13
- ##
14
-
15
-
16
- CacheableNameT = ta.TypeVar('CacheableNameT', bound='CacheableName')
17
-
18
-
19
- class CacheableName(lang.Abstract):
20
- pass
21
-
22
-
23
- ##
24
-
25
-
26
- CacheableVersion: ta.TypeAlias = ta.Hashable
27
- CacheableVersionMap: ta.TypeAlias = col.frozendict['CacheableName', CacheableVersion]
28
-
29
-
30
- def merge_version_maps(
31
- *dcts: ta.Mapping[CacheableName, CacheableVersion],
32
- ) -> CacheableVersionMap:
33
- out: dict[CacheableName, CacheableVersion] = {}
34
- for dct in dcts:
35
- for name, version in dct.items():
36
- try:
37
- ex = out[name]
38
- except KeyError:
39
- out[name] = version
40
- else:
41
- if ex != version:
42
- raise Exception(f'Version mismatch: {ex} {version}')
43
- return col.frozendict(out)
44
-
45
-
46
- ##
47
-
48
-
49
- class Cacheable(lang.Abstract):
50
- @property
51
- @abc.abstractmethod
52
- def name(self) -> CacheableName:
53
- raise NotImplementedError
54
-
55
- @property
56
- @abc.abstractmethod
57
- def version(self) -> CacheableVersion:
58
- raise NotImplementedError
59
-
60
- @cached.property
61
- def as_version_map(self) -> CacheableVersionMap:
62
- return col.frozendict({self.name: self.version})
63
-
64
-
65
- ##
66
-
67
-
68
- @dc.dataclass(frozen=True)
69
- @dc.extra_params(cache_hash=True)
70
- class CacheKey(lang.Abstract, ta.Generic[CacheableNameT]):
71
- name: CacheableNameT
72
-
73
- @dc.validate
74
- def _check_types(self) -> bool:
75
- hash(self)
76
- return isinstance(self.name, CacheableName)
77
-
78
-
79
- @dc.dataclass(frozen=True)
80
- class CacheResult(ta.Generic[T], lang.Final):
81
- hit: bool
82
- versions: CacheableVersionMap
83
- value: T
84
-
85
-
86
- ##
87
-
88
-
89
- class CacheableResolver(lang.Abstract):
90
- @abc.abstractmethod
91
- def resolve(self, name: CacheableName) -> Cacheable:
92
- raise NotImplementedError
File without changes