dycw-utilities 0.176.4__py3-none-any.whl → 0.176.5__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.
- {dycw_utilities-0.176.4.dist-info → dycw_utilities-0.176.5.dist-info}/METADATA +1 -1
- {dycw_utilities-0.176.4.dist-info → dycw_utilities-0.176.5.dist-info}/RECORD +6 -5
- {dycw_utilities-0.176.4.dist-info → dycw_utilities-0.176.5.dist-info}/WHEEL +1 -1
- utilities/__init__.py +1 -1
- utilities/packaging.py +87 -0
- {dycw_utilities-0.176.4.dist-info → dycw_utilities-0.176.5.dist-info}/entry_points.txt +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
utilities/__init__.py,sha256=
|
|
1
|
+
utilities/__init__.py,sha256=chOgc1NV48pH7zK_NN0RHPlWQSfdIFGjwBbOXK_Es2A,60
|
|
2
2
|
utilities/altair.py,sha256=TLfRFbG9HwG7SLXoJ-v0r-t49ZaGgTQZD82cpjVi4vs,9085
|
|
3
3
|
utilities/asyncio.py,sha256=aJySVxBY0gqsIYnoNmH7-1r8djKuf4vSsU69VCD08t8,16772
|
|
4
4
|
utilities/atomicwrites.py,sha256=tPo6r-Rypd9u99u66B9z86YBPpnLrlHtwox_8Z7T34Y,5790
|
|
@@ -44,6 +44,7 @@ utilities/operator.py,sha256=C3NylZWGTVWRpwYHOPVhaLgRhw0DfpS4_XQ8KfPhBLQ,3613
|
|
|
44
44
|
utilities/optuna.py,sha256=C-fhWYiXHVPo1l8QctYkFJ4DyhbSrGorzP1dJb_qvd8,1933
|
|
45
45
|
utilities/orjson.py,sha256=T_0SlK811ysg46d3orvIPY3JpBa4FRMpP2wlPQo7-gU,41854
|
|
46
46
|
utilities/os.py,sha256=kjKKSQfnRqFTTZ315iavaaGd3gGuYNoSWlxVLCJjyQs,4852
|
|
47
|
+
utilities/packaging.py,sha256=kuGenKbyAwxZWL_mbkMzkNXKjhyi9a9tfZQwitrYYlM,2401
|
|
47
48
|
utilities/parse.py,sha256=g7Qm9eBOIeDId2tGA021CIaeF6jp1TI8rx4srdvlyoo,17937
|
|
48
49
|
utilities/pathlib.py,sha256=N4Ip8R9eCM-6GfvxUJ3T9oQIle2C2P52F-13BCFRdTg,9345
|
|
49
50
|
utilities/permissions.py,sha256=vLXlWztSVYffbrxptne7ksj6dU1HLekm4fEvS4ny_4Q,8944
|
|
@@ -97,7 +98,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
|
|
|
97
98
|
utilities/whenever.py,sha256=F4ek0-OBWxHYrZdmoZt76N2RnNyKY5KrEHt7rqO4AQE,60183
|
|
98
99
|
utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
|
|
99
100
|
utilities/zoneinfo.py,sha256=tdIScrTB2-B-LH0ukb1HUXKooLknOfJNwHk10MuMYvA,3619
|
|
100
|
-
dycw_utilities-0.176.
|
|
101
|
-
dycw_utilities-0.176.
|
|
102
|
-
dycw_utilities-0.176.
|
|
103
|
-
dycw_utilities-0.176.
|
|
101
|
+
dycw_utilities-0.176.5.dist-info/WHEEL,sha256=KSLUh82mDPEPk0Bx0ScXlWL64bc8KmzIPNcpQZFV-6E,79
|
|
102
|
+
dycw_utilities-0.176.5.dist-info/entry_points.txt,sha256=cOGtKeJI0KXLSV7MJ8Dhc2G8jPgDcBDm53MVNJU4ycI,136
|
|
103
|
+
dycw_utilities-0.176.5.dist-info/METADATA,sha256=g6FzLC0r4g8uwbM_zouJhCaaHM0IsQ1q33xQyS5tZp0,1398
|
|
104
|
+
dycw_utilities-0.176.5.dist-info/RECORD,,
|
utilities/__init__.py
CHANGED
utilities/packaging.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import TYPE_CHECKING, Self, override
|
|
5
|
+
|
|
6
|
+
import packaging._parser
|
|
7
|
+
import packaging.requirements
|
|
8
|
+
from packaging.requirements import _parse_requirement
|
|
9
|
+
from packaging.specifiers import Specifier, SpecifierSet
|
|
10
|
+
|
|
11
|
+
from utilities.iterables import OneEmptyError, one
|
|
12
|
+
|
|
13
|
+
if TYPE_CHECKING:
|
|
14
|
+
from packaging._parser import MarkerList
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@dataclass(order=True, unsafe_hash=True, kw_only=True, slots=True)
|
|
18
|
+
class Requirement:
|
|
19
|
+
requirement: str
|
|
20
|
+
_parsed_req: packaging._parser.ParsedRequirement
|
|
21
|
+
_custom_req: _CustomRequirement
|
|
22
|
+
|
|
23
|
+
def __getitem__(self, key: str, /) -> str:
|
|
24
|
+
return self.specifier_set[key]
|
|
25
|
+
|
|
26
|
+
@override
|
|
27
|
+
def __str__(self) -> str:
|
|
28
|
+
return str(self._custom_req)
|
|
29
|
+
|
|
30
|
+
@classmethod
|
|
31
|
+
def new(cls, requirement: str, /) -> Self:
|
|
32
|
+
return cls(
|
|
33
|
+
requirement=requirement,
|
|
34
|
+
_parsed_req=_parse_requirement(requirement),
|
|
35
|
+
_custom_req=_CustomRequirement(requirement),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
@property
|
|
39
|
+
def extras(self) -> list[str]:
|
|
40
|
+
return self._parsed_req.extras
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def marker(self) -> MarkerList | None:
|
|
44
|
+
return self._parsed_req.marker
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def name(self) -> str:
|
|
48
|
+
return self._parsed_req.name
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def specifier(self) -> str:
|
|
52
|
+
return self._parsed_req.specifier
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def specifier_set(self) -> _CustomSpecifierSet:
|
|
56
|
+
return _CustomSpecifierSet(_parse_requirement(self.requirement).specifier)
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def url(self) -> str:
|
|
60
|
+
return self._parsed_req.url
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class _CustomRequirement(packaging.requirements.Requirement):
|
|
64
|
+
@override
|
|
65
|
+
def __init__(self, requirement_string: str) -> None:
|
|
66
|
+
super().__init__(requirement_string)
|
|
67
|
+
parsed = _parse_requirement(requirement_string)
|
|
68
|
+
self.specifier = _CustomSpecifierSet(parsed.specifier)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class _CustomSpecifierSet(SpecifierSet):
|
|
72
|
+
def __getitem__(self, key: str, /) -> str:
|
|
73
|
+
try:
|
|
74
|
+
return one(s.version for s in self if s.operator == key)
|
|
75
|
+
except OneEmptyError:
|
|
76
|
+
raise KeyError(key) from None
|
|
77
|
+
|
|
78
|
+
@override
|
|
79
|
+
def __str__(self) -> str:
|
|
80
|
+
specs = sorted(self._specs, key=self._key)
|
|
81
|
+
return ", ".join(map(str, specs))
|
|
82
|
+
|
|
83
|
+
def _key(self, spec: Specifier, /) -> int:
|
|
84
|
+
return [">=", "<"].index(spec.operator)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
__all__ = ["Requirement"]
|
|
File without changes
|