preparse 1.0.13.post1.dev0__tar.gz → 1.0.13.post2__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.
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/PKG-INFO +1 -1
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/pyproject.toml +1 -1
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_items/Bundle.py +17 -13
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_items/Item.py +2 -2
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_items/Long.py +25 -15
- preparse-1.0.13.post2/src/preparse/_items/Option.py +53 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_items/Positional.py +9 -6
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_items/Special.py +0 -1
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_processing/__init__.py +4 -4
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_processing/digesting.py +6 -13
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_processing/parsing.py +10 -17
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/core/Click.py +3 -3
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/core/Optdict.py +22 -16
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/core/PreParser.py +92 -55
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/core/warnings.py +59 -44
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/tests/test_data_toml.py +3 -14
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/tests/test_expit_toml.py +5 -15
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/tests/test_optdict.py +0 -8
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse.egg-info/PKG-INFO +1 -1
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse.egg-info/SOURCES.txt +0 -2
- preparse-1.0.13.post1.dev0/src/preparse/_items/Option.py +0 -37
- preparse-1.0.13.post1.dev0/src/preparse/_utils/__init__.py +0 -3
- preparse-1.0.13.post1.dev0/src/preparse/_utils/dataprop.py +0 -23
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/LICENSE.txt +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/MANIFEST.in +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/README.rst +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/docs/v1.0.rst +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/setup.cfg +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/__init__.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_items/__init__.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_processing/deparsing.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/_processing/pulling.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/core/__init__.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/core/enums.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/py.typed +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/tests/__init__.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/tests/data.toml +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/tests/expit.toml +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/tests/test_enums.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse/tests/test_preparser.py +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse.egg-info/dependency_links.txt +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse.egg-info/requires.txt +0 -0
- {preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse.egg-info/top_level.txt +0 -0
|
@@ -1,21 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
1
3
|
__all__: list[str] = ["Bundle"]
|
|
2
4
|
|
|
3
5
|
from typing import Any, Self
|
|
4
6
|
|
|
5
7
|
import setdoc
|
|
6
8
|
|
|
7
|
-
from preparse._items.Item import Item
|
|
8
9
|
from preparse._items.Option import Option
|
|
9
|
-
from preparse._utils.dataprop import dataprop
|
|
10
|
-
from preparse.core.enums import Nargs, Tuning
|
|
11
10
|
|
|
12
11
|
|
|
13
12
|
class Bundle(Option):
|
|
14
13
|
|
|
15
|
-
chars: str
|
|
16
|
-
joined: bool
|
|
17
|
-
nargs: Nargs
|
|
18
|
-
right: str | None
|
|
14
|
+
# chars: str
|
|
15
|
+
# joined: bool
|
|
16
|
+
# nargs: Nargs
|
|
17
|
+
# right: str | None
|
|
19
18
|
|
|
20
19
|
__slots__ = ()
|
|
21
20
|
|
|
@@ -38,7 +37,7 @@ class Bundle(Option):
|
|
|
38
37
|
ans = list()
|
|
39
38
|
for x in chars:
|
|
40
39
|
if x == "-":
|
|
41
|
-
ans[-1]
|
|
40
|
+
ans[-1] += "-"
|
|
42
41
|
else:
|
|
43
42
|
ans.append(x)
|
|
44
43
|
return ans
|
|
@@ -61,9 +60,14 @@ class Bundle(Option):
|
|
|
61
60
|
x = x[:-1]
|
|
62
61
|
return ans
|
|
63
62
|
|
|
64
|
-
@
|
|
65
|
-
def chars(self: Self
|
|
66
|
-
return
|
|
63
|
+
@property
|
|
64
|
+
def chars(self: Self) -> str:
|
|
65
|
+
return self._data["chars"] # type: ignore[no-any-return]
|
|
66
|
+
|
|
67
|
+
@chars.setter
|
|
68
|
+
def chars(self: Self, x: Any) -> None:
|
|
69
|
+
self._data = getattr(self, "_data", dict())
|
|
70
|
+
self._data["chars"] = str(x)
|
|
67
71
|
|
|
68
72
|
def deparse(self: Self) -> list[str]:
|
|
69
73
|
if self.right is None:
|
|
@@ -73,8 +77,8 @@ class Bundle(Option):
|
|
|
73
77
|
else:
|
|
74
78
|
return ["-" + self.chars, self.right]
|
|
75
79
|
|
|
76
|
-
def split(self: Self, *, allowslong: bool) -> list[
|
|
77
|
-
ans: list[
|
|
80
|
+
def split(self: Self, *, allowslong: bool) -> list[Bundle]:
|
|
81
|
+
ans: list[Bundle]
|
|
78
82
|
parts: list[str]
|
|
79
83
|
x: str
|
|
80
84
|
if allowslong:
|
|
@@ -6,12 +6,12 @@ from typing import Any, Self
|
|
|
6
6
|
import setdoc
|
|
7
7
|
from copyable import Copyable
|
|
8
8
|
|
|
9
|
-
from preparse.core.enums import Nargs, Tuning
|
|
10
|
-
|
|
11
9
|
|
|
12
10
|
class Item(Copyable):
|
|
13
11
|
__slots__ = ("_data",)
|
|
14
12
|
|
|
13
|
+
_data: dict[str, Any]
|
|
14
|
+
|
|
15
15
|
@setdoc.basic
|
|
16
16
|
def copy(self: Self) -> Self:
|
|
17
17
|
return type(self)(**self.todict())
|
|
@@ -6,18 +6,16 @@ from typing import Any, Self, SupportsIndex
|
|
|
6
6
|
import setdoc
|
|
7
7
|
|
|
8
8
|
from preparse._items.Option import Option
|
|
9
|
-
from preparse._utils.dataprop import dataprop
|
|
10
|
-
from preparse.core.enums import Nargs, Tuning
|
|
11
9
|
|
|
12
10
|
|
|
13
11
|
class Long(Option):
|
|
14
12
|
|
|
15
|
-
abbr: str
|
|
16
|
-
abbrlen: int | None
|
|
17
|
-
fullkey: str
|
|
18
|
-
joined: bool
|
|
19
|
-
nargs: Nargs
|
|
20
|
-
right: str | None
|
|
13
|
+
# abbr: str
|
|
14
|
+
# abbrlen: int | None
|
|
15
|
+
# fullkey: str
|
|
16
|
+
# joined: bool
|
|
17
|
+
# nargs: Nargs
|
|
18
|
+
# right: str | None
|
|
21
19
|
|
|
22
20
|
__slots__ = ()
|
|
23
21
|
|
|
@@ -27,7 +25,7 @@ class Long(Option):
|
|
|
27
25
|
*,
|
|
28
26
|
abbrlen: int | None = None,
|
|
29
27
|
fullkey: str,
|
|
30
|
-
joined: bool
|
|
28
|
+
joined: bool = False,
|
|
31
29
|
right: str | None = None,
|
|
32
30
|
) -> None:
|
|
33
31
|
self.fullkey = fullkey
|
|
@@ -39,10 +37,17 @@ class Long(Option):
|
|
|
39
37
|
def abbr(self: Self) -> str:
|
|
40
38
|
return self.fullkey[: self.abbrlen]
|
|
41
39
|
|
|
42
|
-
@
|
|
43
|
-
def abbrlen(self: Self
|
|
40
|
+
@property
|
|
41
|
+
def abbrlen(self: Self) -> int | None:
|
|
42
|
+
return self._data["abbrlen"] # type: ignore[no-any-return]
|
|
43
|
+
|
|
44
|
+
@abbrlen.setter
|
|
45
|
+
def abbrlen(self: Self, x: SupportsIndex | None) -> None:
|
|
46
|
+
self._data = getattr(self, "_data", dict())
|
|
44
47
|
if x is not None:
|
|
45
|
-
|
|
48
|
+
self._data["abbrlen"] = operator.index(x)
|
|
49
|
+
else:
|
|
50
|
+
self._data["abbrlen"] = None
|
|
46
51
|
|
|
47
52
|
def deparse(self: Self) -> list[str]:
|
|
48
53
|
if self.right is None:
|
|
@@ -52,6 +57,11 @@ class Long(Option):
|
|
|
52
57
|
else:
|
|
53
58
|
return [self.abbr, self.right]
|
|
54
59
|
|
|
55
|
-
@
|
|
56
|
-
def fullkey(self: Self
|
|
57
|
-
return
|
|
60
|
+
@property
|
|
61
|
+
def fullkey(self: Self) -> str:
|
|
62
|
+
return self._data["fullkey"] # type: ignore[no-any-return]
|
|
63
|
+
|
|
64
|
+
@fullkey.setter
|
|
65
|
+
def fullkey(self: Self, x: Any) -> None:
|
|
66
|
+
self._data = getattr(self, "_data", dict())
|
|
67
|
+
self._data["fullkey"] = str(x)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
__all__: list[str] = ["Option"]
|
|
2
|
+
|
|
3
|
+
import operator
|
|
4
|
+
from typing import Any, Self, SupportsIndex
|
|
5
|
+
|
|
6
|
+
from preparse._items.Item import Item
|
|
7
|
+
from preparse.core.enums import Nargs
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class Option(Item):
|
|
11
|
+
|
|
12
|
+
# joined: bool
|
|
13
|
+
# nargs: Nargs
|
|
14
|
+
# right: str | None
|
|
15
|
+
|
|
16
|
+
__slots__ = ()
|
|
17
|
+
|
|
18
|
+
def ishungry(self: Self) -> bool:
|
|
19
|
+
return (self.right is None) and (self.nargs == Nargs.REQUIRED_ARGUMENT)
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def joined(self: Self) -> bool:
|
|
23
|
+
return self._data["joined"] # type: ignore[no-any-return]
|
|
24
|
+
|
|
25
|
+
@joined.setter
|
|
26
|
+
def joined(self: Self, x: SupportsIndex) -> None:
|
|
27
|
+
self._data = getattr(self, "_data", dict())
|
|
28
|
+
self._data["joined"] = bool(operator.index(x))
|
|
29
|
+
|
|
30
|
+
@property
|
|
31
|
+
def nargs(self: Self) -> Nargs:
|
|
32
|
+
return self._data["nargs"] # type: ignore[no-any-return]
|
|
33
|
+
|
|
34
|
+
@nargs.setter
|
|
35
|
+
def nargs(self: Self, x: Any) -> None:
|
|
36
|
+
self._data = getattr(self, "_data", dict())
|
|
37
|
+
self._data["nargs"] = Nargs(x)
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def right(self: Self) -> str | None:
|
|
41
|
+
return self._data["right"] # type: ignore[no-any-return]
|
|
42
|
+
|
|
43
|
+
@right.setter
|
|
44
|
+
def right(self: Self, x: Any) -> None:
|
|
45
|
+
self._data = getattr(self, "_data", dict())
|
|
46
|
+
if x is not None:
|
|
47
|
+
self._data["right"] = str(x)
|
|
48
|
+
else:
|
|
49
|
+
self._data["right"] = None
|
|
50
|
+
|
|
51
|
+
@classmethod
|
|
52
|
+
def sortkey(cls: type[Self]) -> int:
|
|
53
|
+
return 0
|
|
@@ -5,13 +5,11 @@ from typing import Any, Self
|
|
|
5
5
|
import setdoc
|
|
6
6
|
|
|
7
7
|
from preparse._items.Item import Item
|
|
8
|
-
from preparse._utils.dataprop import dataprop
|
|
9
|
-
from preparse.core.enums import Nargs, Tuning
|
|
10
8
|
|
|
11
9
|
|
|
12
10
|
class Positional(Item):
|
|
13
11
|
|
|
14
|
-
value: str
|
|
12
|
+
# value: str
|
|
15
13
|
|
|
16
14
|
__slots__ = ()
|
|
17
15
|
|
|
@@ -29,6 +27,11 @@ class Positional(Item):
|
|
|
29
27
|
def sortkey(cls: type[Self]) -> int:
|
|
30
28
|
return 2
|
|
31
29
|
|
|
32
|
-
@
|
|
33
|
-
def value(self: Self
|
|
34
|
-
return
|
|
30
|
+
@property
|
|
31
|
+
def value(self: Self) -> str:
|
|
32
|
+
return self._data["value"] # type: ignore[no-any-return]
|
|
33
|
+
|
|
34
|
+
@value.setter
|
|
35
|
+
def value(self: Self, x: Any) -> None:
|
|
36
|
+
self._data = getattr(self, "_data", dict())
|
|
37
|
+
self._data["value"] = str(x)
|
|
@@ -4,12 +4,11 @@ from collections.abc import Iterable
|
|
|
4
4
|
from types import FunctionType
|
|
5
5
|
from typing import Any
|
|
6
6
|
|
|
7
|
-
from preparse._items import
|
|
7
|
+
from preparse._items import Item, Positional
|
|
8
8
|
from preparse._processing.deparsing import deparse
|
|
9
9
|
from preparse._processing.digesting import digest
|
|
10
10
|
from preparse._processing.parsing import parse
|
|
11
11
|
from preparse._processing.pulling import pull
|
|
12
|
-
from preparse._utils import dataprop
|
|
13
12
|
from preparse.core.enums import Nargs, Tuning
|
|
14
13
|
|
|
15
14
|
|
|
@@ -30,9 +29,10 @@ def process(
|
|
|
30
29
|
) -> list[str]:
|
|
31
30
|
"This method parses args."
|
|
32
31
|
items: list[Item]
|
|
33
|
-
|
|
32
|
+
positionals: list[Positional]
|
|
33
|
+
positionals = pull(args)
|
|
34
34
|
items = parse(
|
|
35
|
-
|
|
35
|
+
positionals,
|
|
36
36
|
allowslong=allowslong,
|
|
37
37
|
allowsshort=allowsshort,
|
|
38
38
|
expectsabbr=expectsabbr,
|
|
@@ -8,14 +8,7 @@ from preparse._items.Long import Long
|
|
|
8
8
|
from preparse._items.Option import Option
|
|
9
9
|
from preparse._items.Positional import Positional
|
|
10
10
|
from preparse._items.Special import Special
|
|
11
|
-
from preparse.core.enums import
|
|
12
|
-
from preparse.core.warnings import (
|
|
13
|
-
PreparseAmbiguousOptionWarning,
|
|
14
|
-
PreparseInvalidOptionWarning,
|
|
15
|
-
PreparseRequiredArgumentWarning,
|
|
16
|
-
PreparseUnallowedArgumentWarning,
|
|
17
|
-
PreparseWarning,
|
|
18
|
-
)
|
|
11
|
+
from preparse.core.enums import Tuning
|
|
19
12
|
|
|
20
13
|
|
|
21
14
|
def digest(
|
|
@@ -146,7 +139,7 @@ def digest_order(
|
|
|
146
139
|
if isinstance(ans[index], Special):
|
|
147
140
|
comp = True
|
|
148
141
|
break
|
|
149
|
-
if not ans[index].isobvious():
|
|
142
|
+
if not ans[index].isobvious(): # type: ignore[attr-defined]
|
|
150
143
|
comp = False
|
|
151
144
|
if not comp:
|
|
152
145
|
ans.insert(index + 1, Special())
|
|
@@ -183,9 +176,9 @@ def digest_special_max(items: list[Item]) -> list[Item]:
|
|
|
183
176
|
break
|
|
184
177
|
if isinstance(ans[index], Positional):
|
|
185
178
|
continue
|
|
186
|
-
if ans[index].ishungry():
|
|
187
|
-
ans[index].joined = False
|
|
188
|
-
ans[index].right = "--"
|
|
179
|
+
if ans[index].ishungry(): # type: ignore[attr-defined]
|
|
180
|
+
ans[index].joined = False # type: ignore[attr-defined]
|
|
181
|
+
ans[index].right = "--" # type: ignore[attr-defined]
|
|
189
182
|
ans.insert(index + 1, Special())
|
|
190
183
|
break
|
|
191
184
|
return ans
|
|
@@ -215,7 +208,7 @@ def digest_special_min(
|
|
|
215
208
|
break
|
|
216
209
|
if isinstance(ans[index], Special):
|
|
217
210
|
break
|
|
218
|
-
isdel = ans[index].isobvious()
|
|
211
|
+
isdel = ans[index].isobvious() # type: ignore[attr-defined]
|
|
219
212
|
if not (isdel or isposix):
|
|
220
213
|
break
|
|
221
214
|
if isdel:
|
|
@@ -10,21 +10,14 @@ from preparse._items.Long import Long
|
|
|
10
10
|
from preparse._items.Option import Option
|
|
11
11
|
from preparse._items.Positional import Positional
|
|
12
12
|
from preparse._items.Special import Special
|
|
13
|
-
from preparse.core import
|
|
14
|
-
from preparse.core.
|
|
13
|
+
from preparse.core.enums import Nargs
|
|
14
|
+
from preparse.core.warnings import PreparseAmbiguousOptionWarning as PAOW
|
|
15
|
+
from preparse.core.warnings import PreparseInvalidOptionWarning as PIOW
|
|
16
|
+
from preparse.core.warnings import PreparseRequiredArgumentWarning as PRAW
|
|
17
|
+
from preparse.core.warnings import PreparseUnallowedArgumentWarning as PUAW
|
|
15
18
|
|
|
16
|
-
PAOW: type[Any]
|
|
17
|
-
PIOW: type[Any]
|
|
18
|
-
PRAW: type[Any]
|
|
19
|
-
PUAW: type[Any]
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
PIOW = warnings.PreparseInvalidOptionWarning
|
|
23
|
-
PUAW = warnings.PreparseUnallowedArgumentWarning
|
|
24
|
-
PRAW = warnings.PreparseRequiredArgumentWarning
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def parse(args: list[str], **kwargs: Any) -> list[Item]:
|
|
20
|
+
def parse(args: list[Positional], **kwargs: Any) -> list[Item]:
|
|
28
21
|
return list(parse_generator(args, **kwargs))
|
|
29
22
|
|
|
30
23
|
|
|
@@ -64,7 +57,7 @@ def parse_cause(
|
|
|
64
57
|
def ans(cls: type[Any], **kwargs: Any) -> None:
|
|
65
58
|
warn(cls(prog=prog, **kwargs))
|
|
66
59
|
|
|
67
|
-
return ans
|
|
60
|
+
return ans # type: ignore[return-value]
|
|
68
61
|
|
|
69
62
|
|
|
70
63
|
def parse_generator(
|
|
@@ -77,11 +70,11 @@ def parse_generator(
|
|
|
77
70
|
optdict: dict[str, Nargs],
|
|
78
71
|
prog: str,
|
|
79
72
|
warn: FunctionType,
|
|
80
|
-
) -> Generator[
|
|
73
|
+
) -> Generator[Item, None, None]:
|
|
81
74
|
broken: bool
|
|
82
75
|
cause: FunctionType
|
|
83
76
|
item: Positional
|
|
84
|
-
last:
|
|
77
|
+
last: Long | Bundle | None
|
|
85
78
|
broken = not (allowslong or allowsshort)
|
|
86
79
|
cause = parse_cause(prog=prog, warn=warn)
|
|
87
80
|
last = None
|
|
@@ -196,7 +189,7 @@ def parse_option(
|
|
|
196
189
|
expectsabbr: bool,
|
|
197
190
|
optdict: dict[str, Nargs],
|
|
198
191
|
**kwargs: Any,
|
|
199
|
-
) ->
|
|
192
|
+
) -> Bundle | Long:
|
|
200
193
|
if parse_islong(arg, **kwargs):
|
|
201
194
|
return parse_long(
|
|
202
195
|
arg,
|
|
@@ -32,7 +32,7 @@ class Click(Copyable):
|
|
|
32
32
|
return "method"
|
|
33
33
|
return "other"
|
|
34
34
|
|
|
35
|
-
@__call__.overload("function")
|
|
35
|
+
@__call__.overload("function") # type: ignore[no-redef]
|
|
36
36
|
def __call__(self: Self, target: types.FunctionType) -> types.FunctionType:
|
|
37
37
|
@functools.wraps(target)
|
|
38
38
|
def ans(cmd: Any, ctx: Any, args: Any) -> Any:
|
|
@@ -46,13 +46,13 @@ class Click(Copyable):
|
|
|
46
46
|
|
|
47
47
|
return ans
|
|
48
48
|
|
|
49
|
-
@__call__.overload("method")
|
|
49
|
+
@__call__.overload("method") # type: ignore[no-redef]
|
|
50
50
|
def __call__(self: Self, target: types.MethodType) -> types.MethodType:
|
|
51
51
|
func: Callable[..., Any]
|
|
52
52
|
func = self(target.__func__)
|
|
53
53
|
return types.MethodType(func, target.__self__)
|
|
54
54
|
|
|
55
|
-
@__call__.overload("other")
|
|
55
|
+
@__call__.overload("other") # type: ignore[no-redef]
|
|
56
56
|
def __call__(self: Self, target: Any) -> Any:
|
|
57
57
|
target.parse_args = self(target.parse_args)
|
|
58
58
|
return target
|
|
@@ -1,47 +1,53 @@
|
|
|
1
1
|
__all__: list[str] = ["Optdict"]
|
|
2
2
|
|
|
3
|
-
from collections.abc import Iterator
|
|
4
|
-
from typing import Any, Self
|
|
3
|
+
from collections.abc import Iterable, Iterator
|
|
4
|
+
from typing import Any, Self, overload
|
|
5
5
|
|
|
6
6
|
import cmp3
|
|
7
7
|
import datahold
|
|
8
|
+
import datahold.typing
|
|
8
9
|
import setdoc
|
|
9
10
|
from datarepr import datarepr
|
|
10
11
|
from frozendict import frozendict
|
|
11
12
|
|
|
12
|
-
from preparse.core.enums import Nargs
|
|
13
|
-
from preparse.core.warnings import (
|
|
14
|
-
PreparseAmbiguousOptionWarning,
|
|
15
|
-
PreparseInvalidOptionWarning,
|
|
16
|
-
PreparseRequiredArgumentWarning,
|
|
17
|
-
PreparseUnallowedArgumentWarning,
|
|
18
|
-
PreparseWarning,
|
|
19
|
-
)
|
|
13
|
+
from preparse.core.enums import Nargs
|
|
20
14
|
|
|
21
15
|
|
|
22
16
|
class Optdict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
|
|
23
17
|
__slots__ = ()
|
|
24
18
|
|
|
25
|
-
data: frozendict[str, Nargs]
|
|
26
|
-
|
|
27
19
|
@setdoc.basic
|
|
28
20
|
def __cmp__(self: Self, other: Any, /) -> int | None:
|
|
29
21
|
if type(self) is type(other):
|
|
30
|
-
return cmp3.cmp(self._data, other._data, mode="eq_strict")
|
|
22
|
+
return cmp3.cmp(self._data, other._data, mode="eq_strict") # type: ignore[no-any-return]
|
|
31
23
|
else:
|
|
32
|
-
return cmp3.cmp(self._data, other, mode="eq_strict")
|
|
24
|
+
return cmp3.cmp(self._data, other, mode="eq_strict") # type: ignore[no-any-return]
|
|
33
25
|
|
|
34
26
|
__format__ = object.__format__
|
|
35
27
|
|
|
28
|
+
@setdoc.basic
|
|
29
|
+
def __init__(
|
|
30
|
+
self: Self,
|
|
31
|
+
other: (
|
|
32
|
+
datahold.typing.SupportsKeysAndGetitem.SupportsKeysAndGetitem[
|
|
33
|
+
object, object
|
|
34
|
+
]
|
|
35
|
+
| Iterable[tuple[object, object]]
|
|
36
|
+
) = (),
|
|
37
|
+
/,
|
|
38
|
+
**kwargs: object,
|
|
39
|
+
) -> None:
|
|
40
|
+
datahold.HoldDict.__init__(self, other, **kwargs)
|
|
41
|
+
|
|
36
42
|
@setdoc.basic
|
|
37
43
|
def __repr__(self: Self, /) -> str:
|
|
38
44
|
return datarepr(type(self).__name__, dict(self._data))
|
|
39
45
|
|
|
40
46
|
__str__ = object.__str__
|
|
41
47
|
|
|
42
|
-
@property
|
|
48
|
+
@property # type: ignore[override]
|
|
43
49
|
def data(self: Self) -> frozendict[str, Nargs]:
|
|
44
|
-
return frozendict[str, Nargs](self._data)
|
|
50
|
+
return frozendict[str, Nargs](self._data) # type: ignore[arg-type]
|
|
45
51
|
|
|
46
52
|
@data.setter
|
|
47
53
|
def data(self: Self, value: Any) -> None:
|
|
@@ -15,33 +15,13 @@ from datarepr import datarepr
|
|
|
15
15
|
from tofunc import tofunc
|
|
16
16
|
|
|
17
17
|
from preparse._processing import process
|
|
18
|
-
from preparse._utils.dataprop import dataprop
|
|
19
18
|
from preparse.core.Click import Click
|
|
20
19
|
from preparse.core.enums import Nargs, Tuning
|
|
21
20
|
from preparse.core.Optdict import Optdict
|
|
22
|
-
from preparse.core.warnings import (
|
|
23
|
-
PreparseAmbiguousOptionWarning,
|
|
24
|
-
PreparseInvalidOptionWarning,
|
|
25
|
-
PreparseRequiredArgumentWarning,
|
|
26
|
-
PreparseUnallowedArgumentWarning,
|
|
27
|
-
PreparseWarning,
|
|
28
|
-
)
|
|
29
21
|
|
|
30
22
|
|
|
31
23
|
class PreParser(Copyable):
|
|
32
24
|
|
|
33
|
-
allowslong: bool
|
|
34
|
-
allowsshort: bool
|
|
35
|
-
bundling: Tuning
|
|
36
|
-
expandsabbr: bool
|
|
37
|
-
expectsabbr: bool
|
|
38
|
-
expectsposix: bool
|
|
39
|
-
optdict: Optdict
|
|
40
|
-
prog: str
|
|
41
|
-
reconcilesorders: bool
|
|
42
|
-
special: Tuning
|
|
43
|
-
warn: types.FunctionType
|
|
44
|
-
|
|
45
25
|
__slots__ = ("_data",)
|
|
46
26
|
|
|
47
27
|
@setdoc.basic
|
|
@@ -76,18 +56,33 @@ class PreParser(Copyable):
|
|
|
76
56
|
def __repr__(self: Self) -> str:
|
|
77
57
|
return datarepr(type(self).__name__, **self.todict())
|
|
78
58
|
|
|
79
|
-
@
|
|
80
|
-
def allowslong(self: Self
|
|
81
|
-
return
|
|
59
|
+
@property
|
|
60
|
+
def allowslong(self: Self) -> bool:
|
|
61
|
+
return self._data["allowslong"]
|
|
62
|
+
|
|
63
|
+
@allowslong.setter
|
|
64
|
+
def allowslong(self: Self, value: Any) -> None:
|
|
65
|
+
self._data = getattr(self, "_data", dict())
|
|
66
|
+
self._data["allowslong"] = bool(value)
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def allowsshort(self: Self) -> bool:
|
|
70
|
+
return self._data["allowsshort"] # type: ignore[no-any-return]
|
|
82
71
|
|
|
83
|
-
@
|
|
84
|
-
def allowsshort(self: Self, value: Any) ->
|
|
85
|
-
|
|
72
|
+
@allowsshort.setter
|
|
73
|
+
def allowsshort(self: Self, value: Any) -> None:
|
|
74
|
+
self._data = getattr(self, "_data", dict())
|
|
75
|
+
self._data["allowsshort"] = bool(value)
|
|
86
76
|
|
|
87
|
-
@
|
|
88
|
-
def bundling(self: Self
|
|
77
|
+
@property
|
|
78
|
+
def bundling(self: Self) -> Tuning:
|
|
89
79
|
"This property decides how to approach the bundling of short options."
|
|
90
|
-
return
|
|
80
|
+
return self._data["bundling"] # type: ignore[no-any-return]
|
|
81
|
+
|
|
82
|
+
@bundling.setter
|
|
83
|
+
def bundling(self: Self, value: Any) -> None:
|
|
84
|
+
self._data = getattr(self, "_data", dict())
|
|
85
|
+
self._data["bundling"] = Tuning(value)
|
|
91
86
|
|
|
92
87
|
def click(self: Self, cmd: Any = True, ctx: Any = True) -> Click:
|
|
93
88
|
"This method returns a decorator that infuses the current instance into parse_args."
|
|
@@ -97,31 +92,53 @@ class PreParser(Copyable):
|
|
|
97
92
|
def copy(self: Self) -> Self:
|
|
98
93
|
return type(self)(**self.todict())
|
|
99
94
|
|
|
100
|
-
@
|
|
101
|
-
def expandsabbr(self: Self
|
|
102
|
-
return
|
|
95
|
+
@property
|
|
96
|
+
def expandsabbr(self: Self) -> bool:
|
|
97
|
+
return self._data["expandsabbr"] # type: ignore[no-any-return]
|
|
98
|
+
|
|
99
|
+
@expandsabbr.setter
|
|
100
|
+
def expandsabbr(self: Self, value: Any) -> None:
|
|
101
|
+
self._data = getattr(self, "_data", dict())
|
|
102
|
+
self._data["expandsabbr"] = bool(value)
|
|
103
|
+
|
|
104
|
+
@property
|
|
105
|
+
def expectsabbr(self: Self) -> bool:
|
|
106
|
+
return self._data["expectsabbr"] # type: ignore[no-any-return]
|
|
103
107
|
|
|
104
|
-
@
|
|
105
|
-
def expectsabbr(self: Self, value: Any) ->
|
|
106
|
-
|
|
108
|
+
@expectsabbr.setter
|
|
109
|
+
def expectsabbr(self: Self, value: Any) -> None:
|
|
110
|
+
self._data = getattr(self, "_data", dict())
|
|
111
|
+
self._data["expectsabbr"] = bool(value)
|
|
107
112
|
|
|
108
|
-
@
|
|
109
|
-
def expectsposix(self: Self
|
|
113
|
+
@property
|
|
114
|
+
def expectsposix(self: Self) -> bool:
|
|
115
|
+
return self._data["expectsposix"] # type: ignore[no-any-return]
|
|
116
|
+
|
|
117
|
+
@expectsposix.setter
|
|
118
|
+
def expectsposix(self: Self, value: Any) -> None:
|
|
119
|
+
self._data = getattr(self, "_data", dict())
|
|
110
120
|
if value == "infer":
|
|
111
|
-
|
|
121
|
+
self._data["expectsposix"] = bool(
|
|
122
|
+
os.environ.get("POSIXLY_CORRECT")
|
|
123
|
+
)
|
|
112
124
|
else:
|
|
113
|
-
|
|
125
|
+
self._data["expectsposix"] = bool(value)
|
|
114
126
|
|
|
115
|
-
@
|
|
116
|
-
def optdict(self: Self
|
|
127
|
+
@property
|
|
128
|
+
def optdict(self: Self) -> Optdict:
|
|
117
129
|
"This property gives a dictionary of options."
|
|
130
|
+
return self._data["optdict"] # type: ignore[no-any-return]
|
|
131
|
+
|
|
132
|
+
@optdict.setter
|
|
133
|
+
def optdict(self: Self, value: Any) -> None:
|
|
118
134
|
dataA: Optdict
|
|
135
|
+
self._data = getattr(self, "_data", dict())
|
|
119
136
|
if "optdict" not in self._data.keys():
|
|
120
137
|
self._data["optdict"] = Optdict()
|
|
121
138
|
dataA = Optdict(value)
|
|
122
139
|
self._data["optdict"].clear()
|
|
123
140
|
self._data["optdict"].update(dataA)
|
|
124
|
-
|
|
141
|
+
self._data["optdict"] = self._data["optdict"]
|
|
125
142
|
|
|
126
143
|
def parse_args(
|
|
127
144
|
self: Self,
|
|
@@ -130,17 +147,27 @@ class PreParser(Copyable):
|
|
|
130
147
|
"This method parses args."
|
|
131
148
|
return process(args, **self.todict())
|
|
132
149
|
|
|
133
|
-
@
|
|
134
|
-
def prog(self: Self
|
|
150
|
+
@property
|
|
151
|
+
def prog(self: Self) -> str:
|
|
135
152
|
"This property represents the name of the program."
|
|
153
|
+
return self._data["prog"] # type: ignore[no-any-return]
|
|
154
|
+
|
|
155
|
+
@prog.setter
|
|
156
|
+
def prog(self: Self, value: Any) -> None:
|
|
157
|
+
self._data = getattr(self, "_data", dict())
|
|
136
158
|
if value is None:
|
|
137
|
-
|
|
159
|
+
self._data["prog"] = str(os.path.basename(sys.argv[0]))
|
|
138
160
|
else:
|
|
139
|
-
|
|
161
|
+
self._data["prog"] = str(value)
|
|
140
162
|
|
|
141
|
-
@
|
|
142
|
-
def reconcilesorders(self: Self
|
|
143
|
-
return
|
|
163
|
+
@property
|
|
164
|
+
def reconcilesorders(self: Self) -> bool:
|
|
165
|
+
return self._data["reconcilesorders"] # type: ignore[no-any-return]
|
|
166
|
+
|
|
167
|
+
@reconcilesorders.setter
|
|
168
|
+
def reconcilesorders(self: Self, value: Any) -> None:
|
|
169
|
+
self._data = getattr(self, "_data", dict())
|
|
170
|
+
self._data["reconcilesorders"] = bool(value)
|
|
144
171
|
|
|
145
172
|
def reflectClickCommand(self: Self, cmd: cl.Command) -> None:
|
|
146
173
|
"This method causes the current instance to reflect a click.Command object."
|
|
@@ -167,10 +194,15 @@ class PreParser(Copyable):
|
|
|
167
194
|
"This method causes the current instance to reflect a click.Context object."
|
|
168
195
|
self.prog = ctx.info_name
|
|
169
196
|
|
|
170
|
-
@
|
|
171
|
-
def special(self: Self
|
|
197
|
+
@property
|
|
198
|
+
def special(self: Self) -> Tuning:
|
|
172
199
|
"This Tuning property determines the approach towards the special argument."
|
|
173
|
-
return
|
|
200
|
+
return self._data["special"] # type: ignore[no-any-return]
|
|
201
|
+
|
|
202
|
+
@special.setter
|
|
203
|
+
def special(self: Self, value: Any) -> None:
|
|
204
|
+
self._data = getattr(self, "_data", dict())
|
|
205
|
+
self._data["special"] = Tuning(value)
|
|
174
206
|
|
|
175
207
|
def todict(self: Self) -> dict[str, Any]:
|
|
176
208
|
"This method returns a dict representing the current instance."
|
|
@@ -183,7 +215,12 @@ class PreParser(Copyable):
|
|
|
183
215
|
else:
|
|
184
216
|
return dict(ans)
|
|
185
217
|
|
|
186
|
-
@
|
|
187
|
-
def warn(self: Self
|
|
218
|
+
@property
|
|
219
|
+
def warn(self: Self) -> types.FunctionType:
|
|
188
220
|
"This property gives a function that takes in the warnings."
|
|
189
|
-
return
|
|
221
|
+
return self._data["warn"] # type: ignore[no-any-return]
|
|
222
|
+
|
|
223
|
+
@warn.setter
|
|
224
|
+
def warn(self: Self, value: Callable[..., Any]) -> None:
|
|
225
|
+
self._data = getattr(self, "_data", dict())
|
|
226
|
+
self._data["warn"] = tofunc(value)
|
|
@@ -14,13 +14,8 @@ import setdoc
|
|
|
14
14
|
from copyable import Copyable
|
|
15
15
|
from datarepr import datarepr
|
|
16
16
|
|
|
17
|
-
from preparse._utils import dataprop
|
|
18
|
-
|
|
19
17
|
|
|
20
18
|
class PreparseWarning(Warning, Copyable):
|
|
21
|
-
args: tuple[str]
|
|
22
|
-
option: str
|
|
23
|
-
prog: str
|
|
24
19
|
|
|
25
20
|
@setdoc.basic
|
|
26
21
|
def __repr__(self: Self) -> str:
|
|
@@ -31,7 +26,7 @@ class PreparseWarning(Warning, Copyable):
|
|
|
31
26
|
return f"{self.prog}: {self.getmsg()}"
|
|
32
27
|
|
|
33
28
|
@property
|
|
34
|
-
def args(self: Self) -> tuple[str]:
|
|
29
|
+
def args(self: Self) -> tuple[str]: # type: ignore[override]
|
|
35
30
|
"This property returns (str(self),)."
|
|
36
31
|
return (str(self),)
|
|
37
32
|
|
|
@@ -42,13 +37,23 @@ class PreparseWarning(Warning, Copyable):
|
|
|
42
37
|
@abstractmethod
|
|
43
38
|
def getmsg(self: Self) -> str: ...
|
|
44
39
|
|
|
45
|
-
@
|
|
46
|
-
def option(self: Self
|
|
47
|
-
return
|
|
40
|
+
@property
|
|
41
|
+
def option(self: Self) -> str:
|
|
42
|
+
return self._data["option"]
|
|
43
|
+
|
|
44
|
+
@option.setter
|
|
45
|
+
def option(self: Self, value: Any) -> None:
|
|
46
|
+
self._data = getattr(self, "_data", dict())
|
|
47
|
+
self._data["option"] = str(value)
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def prog(self: Self) -> str:
|
|
51
|
+
return self._data["prog"] # type: ignore[no-any-return]
|
|
48
52
|
|
|
49
|
-
@
|
|
50
|
-
def prog(self: Self, value: Any) ->
|
|
51
|
-
|
|
53
|
+
@prog.setter
|
|
54
|
+
def prog(self: Self, value: Any) -> None:
|
|
55
|
+
self._data = getattr(self, "_data", dict())
|
|
56
|
+
self._data["prog"] = str(value)
|
|
52
57
|
|
|
53
58
|
def todict(self: Self) -> dict[str, Any]:
|
|
54
59
|
"This method returns a dict representing the current instance."
|
|
@@ -64,56 +69,63 @@ class PreparseWarning(Warning, Copyable):
|
|
|
64
69
|
|
|
65
70
|
class PreparseDualWarning(PreparseWarning):
|
|
66
71
|
|
|
67
|
-
args: tuple[str]
|
|
68
|
-
option: str
|
|
69
|
-
prog: str
|
|
70
|
-
|
|
71
72
|
@setdoc.basic
|
|
72
73
|
def __init__(self: Self, *, islong: Any, option: Any, prog: Any) -> None:
|
|
73
74
|
self.prog = prog
|
|
74
75
|
self.option = option
|
|
75
76
|
self.islong = islong
|
|
76
77
|
|
|
78
|
+
@staticmethod
|
|
79
|
+
@abstractmethod
|
|
80
|
+
def _longmsg() -> str: ...
|
|
81
|
+
@staticmethod
|
|
82
|
+
@abstractmethod
|
|
83
|
+
def _shortmsg() -> str: ...
|
|
84
|
+
|
|
77
85
|
def getmsg(self: Self) -> str:
|
|
78
86
|
"This method returns the core message."
|
|
79
87
|
if self.islong:
|
|
80
|
-
return
|
|
88
|
+
return self._longmsg() % self.option
|
|
81
89
|
else:
|
|
82
|
-
return
|
|
90
|
+
return self._shortmsg() % self.option
|
|
83
91
|
|
|
84
|
-
@
|
|
85
|
-
def islong(self: Self
|
|
86
|
-
return
|
|
92
|
+
@property
|
|
93
|
+
def islong(self: Self) -> bool:
|
|
94
|
+
return self._data["islong"] # type: ignore[no-any-return]
|
|
95
|
+
|
|
96
|
+
@islong.setter
|
|
97
|
+
def islong(self: Self, value: Any) -> None:
|
|
98
|
+
self._data = getattr(self, "_data", dict())
|
|
99
|
+
self._data["islong"] = bool(value)
|
|
87
100
|
|
|
88
101
|
|
|
89
102
|
class PreparseInvalidOptionWarning(PreparseDualWarning):
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
@staticmethod
|
|
104
|
+
def _longmsg() -> str:
|
|
105
|
+
return "unrecognized option '%s'"
|
|
106
|
+
|
|
107
|
+
@staticmethod
|
|
108
|
+
def _shortmsg() -> str:
|
|
109
|
+
return "invalid option -- '%s'"
|
|
95
110
|
|
|
96
111
|
|
|
97
112
|
class PreparseRequiredArgumentWarning(PreparseDualWarning):
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
113
|
+
|
|
114
|
+
@staticmethod
|
|
115
|
+
def _longmsg() -> str:
|
|
116
|
+
return "option '%s' requires an argument"
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def _shortmsg() -> str:
|
|
120
|
+
return "option requires an argument -- '%s'"
|
|
103
121
|
|
|
104
122
|
|
|
105
123
|
class PreparseLongonlyWarning(PreparseWarning):
|
|
106
|
-
|
|
107
|
-
option: str
|
|
108
|
-
prog: str
|
|
124
|
+
pass
|
|
109
125
|
# only possible for long options
|
|
110
126
|
|
|
111
127
|
|
|
112
128
|
class PreparseAmbiguousOptionWarning(PreparseLongonlyWarning):
|
|
113
|
-
args: tuple[str]
|
|
114
|
-
option: str
|
|
115
|
-
possibilities: tuple[str, ...]
|
|
116
|
-
prog: str
|
|
117
129
|
|
|
118
130
|
@setdoc.basic
|
|
119
131
|
def __init__(
|
|
@@ -132,15 +144,18 @@ class PreparseAmbiguousOptionWarning(PreparseLongonlyWarning):
|
|
|
132
144
|
ans += " '%s'" % x
|
|
133
145
|
return ans
|
|
134
146
|
|
|
135
|
-
@
|
|
136
|
-
def possibilities(self: Self
|
|
137
|
-
return
|
|
147
|
+
@property
|
|
148
|
+
def possibilities(self: Self) -> tuple[str, ...]:
|
|
149
|
+
return self._data["possibilities"] # type: ignore[no-any-return]
|
|
150
|
+
|
|
151
|
+
@possibilities.setter
|
|
152
|
+
def possibilities(self: Self, value: Iterable[Any]) -> None:
|
|
153
|
+
self._data = getattr(self, "_data", dict())
|
|
154
|
+
self._data["possibilities"] = tuple(map(str, value))
|
|
138
155
|
|
|
139
156
|
|
|
140
157
|
class PreparseUnallowedArgumentWarning(PreparseLongonlyWarning):
|
|
141
|
-
|
|
142
|
-
option: str
|
|
143
|
-
prog: str
|
|
158
|
+
|
|
144
159
|
# option is always full key without value
|
|
145
160
|
|
|
146
161
|
@setdoc.basic
|
|
@@ -6,23 +6,11 @@ import unittest
|
|
|
6
6
|
from importlib import resources
|
|
7
7
|
from typing import Any, Self
|
|
8
8
|
|
|
9
|
-
from preparse.core import
|
|
10
|
-
Click,
|
|
11
|
-
Nargs,
|
|
12
|
-
Optdict,
|
|
13
|
-
PreparseAmbiguousOptionWarning,
|
|
14
|
-
PreparseInvalidOptionWarning,
|
|
15
|
-
PreParser,
|
|
16
|
-
PreparseRequiredArgumentWarning,
|
|
17
|
-
PreparseUnallowedArgumentWarning,
|
|
18
|
-
PreparseWarning,
|
|
19
|
-
Tuning,
|
|
20
|
-
enums,
|
|
21
|
-
warnings,
|
|
22
|
-
)
|
|
9
|
+
from preparse.core import PreParser
|
|
23
10
|
|
|
24
11
|
|
|
25
12
|
class utils:
|
|
13
|
+
@staticmethod
|
|
26
14
|
def get_data() -> dict[str, Any]:
|
|
27
15
|
data: dict[str, Any]
|
|
28
16
|
text: str
|
|
@@ -30,6 +18,7 @@ class utils:
|
|
|
30
18
|
data = tomllib.loads(text)
|
|
31
19
|
return data
|
|
32
20
|
|
|
21
|
+
@staticmethod
|
|
33
22
|
def istestable(x: Any) -> bool:
|
|
34
23
|
if not isinstance(x, float):
|
|
35
24
|
return True
|
|
@@ -9,24 +9,12 @@ from typing import Any, Self
|
|
|
9
9
|
import click
|
|
10
10
|
from click.testing import CliRunner
|
|
11
11
|
|
|
12
|
-
from preparse.core import
|
|
13
|
-
Click,
|
|
14
|
-
Nargs,
|
|
15
|
-
Optdict,
|
|
16
|
-
PreparseAmbiguousOptionWarning,
|
|
17
|
-
PreparseInvalidOptionWarning,
|
|
18
|
-
PreParser,
|
|
19
|
-
PreparseRequiredArgumentWarning,
|
|
20
|
-
PreparseUnallowedArgumentWarning,
|
|
21
|
-
PreparseWarning,
|
|
22
|
-
Tuning,
|
|
23
|
-
enums,
|
|
24
|
-
warnings,
|
|
25
|
-
)
|
|
12
|
+
from preparse.core import PreParser
|
|
26
13
|
|
|
27
14
|
|
|
28
15
|
class expit:
|
|
29
16
|
|
|
17
|
+
@staticmethod
|
|
30
18
|
def function(x: float) -> float:
|
|
31
19
|
p: float
|
|
32
20
|
try:
|
|
@@ -35,7 +23,7 @@ class expit:
|
|
|
35
23
|
p = float("+inf")
|
|
36
24
|
return 1 / (1 + p)
|
|
37
25
|
|
|
38
|
-
@PreParser(reconcilesorders=True, expectsposix=False).click()
|
|
26
|
+
@PreParser(reconcilesorders=True, expectsposix=False).click() # type: ignore
|
|
39
27
|
@click.command(add_help_option=False)
|
|
40
28
|
@click.help_option("-h", "--help")
|
|
41
29
|
@click.version_option("1.2.3", "-V", "--version")
|
|
@@ -46,6 +34,7 @@ class expit:
|
|
|
46
34
|
|
|
47
35
|
|
|
48
36
|
class utils:
|
|
37
|
+
@staticmethod
|
|
49
38
|
def get_data() -> dict[str, Any]:
|
|
50
39
|
data: dict[str, Any]
|
|
51
40
|
text: str
|
|
@@ -53,6 +42,7 @@ class utils:
|
|
|
53
42
|
data = tomllib.loads(text)
|
|
54
43
|
return data
|
|
55
44
|
|
|
45
|
+
@staticmethod
|
|
56
46
|
def istestable(x: Any) -> bool:
|
|
57
47
|
if not isinstance(x, float):
|
|
58
48
|
return True
|
|
@@ -3,15 +3,7 @@ __all__: list[str] = ["TestPreparse"]
|
|
|
3
3
|
import unittest
|
|
4
4
|
from typing import Self
|
|
5
5
|
|
|
6
|
-
from preparse.core.enums import Nargs, Tuning
|
|
7
6
|
from preparse.core.Optdict import Optdict
|
|
8
|
-
from preparse.core.warnings import (
|
|
9
|
-
PreparseAmbiguousOptionWarning,
|
|
10
|
-
PreparseInvalidOptionWarning,
|
|
11
|
-
PreparseRequiredArgumentWarning,
|
|
12
|
-
PreparseUnallowedArgumentWarning,
|
|
13
|
-
PreparseWarning,
|
|
14
|
-
)
|
|
15
7
|
|
|
16
8
|
|
|
17
9
|
class TestPreparse(unittest.TestCase):
|
|
@@ -23,8 +23,6 @@ src/preparse/_processing/deparsing.py
|
|
|
23
23
|
src/preparse/_processing/digesting.py
|
|
24
24
|
src/preparse/_processing/parsing.py
|
|
25
25
|
src/preparse/_processing/pulling.py
|
|
26
|
-
src/preparse/_utils/__init__.py
|
|
27
|
-
src/preparse/_utils/dataprop.py
|
|
28
26
|
src/preparse/core/Click.py
|
|
29
27
|
src/preparse/core/Optdict.py
|
|
30
28
|
src/preparse/core/PreParser.py
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
__all__: list[str] = ["Option"]
|
|
2
|
-
|
|
3
|
-
import operator
|
|
4
|
-
from typing import Any, Self, SupportsIndex
|
|
5
|
-
|
|
6
|
-
from preparse._items.Item import Item
|
|
7
|
-
from preparse._utils.dataprop import dataprop
|
|
8
|
-
from preparse.core.enums import Nargs, Tuning
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class Option(Item):
|
|
12
|
-
|
|
13
|
-
joined: bool
|
|
14
|
-
nargs: Nargs
|
|
15
|
-
right: str | None
|
|
16
|
-
|
|
17
|
-
__slots__ = ()
|
|
18
|
-
|
|
19
|
-
def ishungry(self: Self) -> bool:
|
|
20
|
-
return (self.right is None) and (self.nargs == Nargs.REQUIRED_ARGUMENT)
|
|
21
|
-
|
|
22
|
-
@dataprop
|
|
23
|
-
def joined(self: Self, x: SupportsIndex) -> bool:
|
|
24
|
-
return bool(operator.index(x))
|
|
25
|
-
|
|
26
|
-
@dataprop
|
|
27
|
-
def nargs(self: Self, x: Any) -> Nargs:
|
|
28
|
-
return Nargs(x)
|
|
29
|
-
|
|
30
|
-
@dataprop
|
|
31
|
-
def right(self: Self, x: Any) -> str | None:
|
|
32
|
-
if x is not None:
|
|
33
|
-
return str(x)
|
|
34
|
-
|
|
35
|
-
@classmethod
|
|
36
|
-
def sortkey(cls: type[Self]) -> int:
|
|
37
|
-
return 0
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
__all__: list[str] = ["dataprop"]
|
|
2
|
-
|
|
3
|
-
from collections.abc import Callable
|
|
4
|
-
from typing import Any, Self
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def dataprop(func: Callable[..., Any]) -> property:
|
|
8
|
-
"This magic method implements calling the current instance."
|
|
9
|
-
|
|
10
|
-
kwargs: dict[str, Any]
|
|
11
|
-
|
|
12
|
-
def fget(self: Self) -> Any:
|
|
13
|
-
return self._data[func.__name__]
|
|
14
|
-
|
|
15
|
-
def fset(self: Self, value: Any) -> None:
|
|
16
|
-
self._data = getattr(self, "_data", dict())
|
|
17
|
-
self._data[func.__name__] = func(self, value)
|
|
18
|
-
|
|
19
|
-
kwargs = dict()
|
|
20
|
-
kwargs["doc"] = func.__doc__
|
|
21
|
-
kwargs["fget"] = fget
|
|
22
|
-
kwargs["fset"] = fset
|
|
23
|
-
return property(**kwargs)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{preparse-1.0.13.post1.dev0 → preparse-1.0.13.post2}/src/preparse.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|