preparse 2.0.0.dev7__py3-none-any.whl → 2.0.0.dev11__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.
- preparse/_processing/__init__.py +2 -4
- preparse/_processing/parsing.py +41 -27
- preparse/core/PreParser.py +8 -14
- preparse/tests/data.toml +35486 -70661
- {preparse-2.0.0.dev7.dist-info → preparse-2.0.0.dev11.dist-info}/METADATA +1 -1
- {preparse-2.0.0.dev7.dist-info → preparse-2.0.0.dev11.dist-info}/RECORD +9 -9
- {preparse-2.0.0.dev7.dist-info → preparse-2.0.0.dev11.dist-info}/WHEEL +0 -0
- {preparse-2.0.0.dev7.dist-info → preparse-2.0.0.dev11.dist-info}/licenses/LICENSE.txt +0 -0
- {preparse-2.0.0.dev7.dist-info → preparse-2.0.0.dev11.dist-info}/top_level.txt +0 -0
preparse/_processing/__init__.py
CHANGED
|
@@ -15,11 +15,10 @@ __all__ = ["process"]
|
|
|
15
15
|
def process(
|
|
16
16
|
args: Optional[Iterable] = None,
|
|
17
17
|
*,
|
|
18
|
+
abbr: Optional[Tuning],
|
|
18
19
|
allowslong: bool,
|
|
19
20
|
allowsshort: bool,
|
|
20
21
|
bundling: Tuning,
|
|
21
|
-
expandsabbr: bool,
|
|
22
|
-
expectsabbr: bool,
|
|
23
22
|
expectsposix: bool,
|
|
24
23
|
optdict: dict,
|
|
25
24
|
prog: str,
|
|
@@ -32,10 +31,9 @@ def process(
|
|
|
32
31
|
items = pull(args)
|
|
33
32
|
items = parse(
|
|
34
33
|
items,
|
|
34
|
+
abbr=abbr,
|
|
35
35
|
allowslong=allowslong,
|
|
36
36
|
allowsshort=allowsshort,
|
|
37
|
-
expandsabbr=expandsabbr,
|
|
38
|
-
expectsabbr=expectsabbr,
|
|
39
37
|
expectsposix=expectsposix,
|
|
40
38
|
optdict=optdict,
|
|
41
39
|
prog=prog,
|
preparse/_processing/parsing.py
CHANGED
|
@@ -18,7 +18,10 @@ PUAW = warnings.PreparseUnallowedArgumentWarning
|
|
|
18
18
|
PRAW = warnings.PreparseRequiredArgumentWarning
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
def parse(
|
|
21
|
+
def parse(
|
|
22
|
+
args: list[str],
|
|
23
|
+
**kwargs: Any,
|
|
24
|
+
) -> list[Item]:
|
|
22
25
|
return list(parse_generator(args, **kwargs))
|
|
23
26
|
|
|
24
27
|
|
|
@@ -64,10 +67,9 @@ def parse_cause(
|
|
|
64
67
|
def parse_generator(
|
|
65
68
|
items: list[Positional],
|
|
66
69
|
*,
|
|
70
|
+
abbr: Optional[Tuning],
|
|
67
71
|
allowslong: bool,
|
|
68
72
|
allowsshort: bool,
|
|
69
|
-
expandsabbr: bool,
|
|
70
|
-
expectsabbr: bool,
|
|
71
73
|
expectsposix: bool,
|
|
72
74
|
optdict: dict,
|
|
73
75
|
prog: str,
|
|
@@ -103,11 +105,10 @@ def parse_generator(
|
|
|
103
105
|
continue
|
|
104
106
|
last = parse_option(
|
|
105
107
|
item.value,
|
|
108
|
+
abbr=abbr,
|
|
106
109
|
allowslong=allowslong,
|
|
107
110
|
allowsshort=allowsshort,
|
|
108
111
|
cause=cause,
|
|
109
|
-
expandsabbr=expandsabbr,
|
|
110
|
-
expectsabbr=expectsabbr,
|
|
111
112
|
optdict=optdict,
|
|
112
113
|
)
|
|
113
114
|
if not last.ishungry():
|
|
@@ -123,24 +124,12 @@ def parse_generator(
|
|
|
123
124
|
yield last
|
|
124
125
|
|
|
125
126
|
|
|
126
|
-
def parse_islong(
|
|
127
|
-
arg: str,
|
|
128
|
-
*,
|
|
129
|
-
allowslong: bool,
|
|
130
|
-
allowsshort: bool,
|
|
131
|
-
) -> bool:
|
|
132
|
-
if allowslong and allowsshort:
|
|
133
|
-
return arg.startswith("--")
|
|
134
|
-
else:
|
|
135
|
-
return not allowsshort
|
|
136
|
-
|
|
137
|
-
|
|
138
127
|
def parse_long(
|
|
139
128
|
arg: str,
|
|
140
129
|
*,
|
|
130
|
+
abbr: Optional[Tuning],
|
|
131
|
+
allowsshort: bool,
|
|
141
132
|
cause: FunctionType,
|
|
142
|
-
expandsabbr: bool,
|
|
143
|
-
expectsabbr: bool,
|
|
144
133
|
optdict: dict,
|
|
145
134
|
) -> Long:
|
|
146
135
|
ans: Long
|
|
@@ -153,7 +142,7 @@ def parse_long(
|
|
|
153
142
|
ans.abbrlen = len(ans.fullkey)
|
|
154
143
|
if ans.fullkey in optdict.keys():
|
|
155
144
|
parts = [ans.fullkey]
|
|
156
|
-
elif
|
|
145
|
+
elif abbr is not None:
|
|
157
146
|
parts = parse_long_startswith(ans.abbr, keys=optdict.keys())
|
|
158
147
|
else:
|
|
159
148
|
parts = list() # can be assumed
|
|
@@ -166,8 +155,17 @@ def parse_long(
|
|
|
166
155
|
cause(PAOW, option=arg, possibilities=parts)
|
|
167
156
|
return ans
|
|
168
157
|
(ans.fullkey,) = parts
|
|
169
|
-
if
|
|
158
|
+
if abbr == Tuning.MINIMIZE:
|
|
170
159
|
ans.abbrlen = len(ans.fullkey)
|
|
160
|
+
if abbr == Tuning.MAXIMIZE:
|
|
161
|
+
parts = list(optdict.keys())
|
|
162
|
+
parts.remove(ans.fullkey)
|
|
163
|
+
ans.abbrlen = parse_minlen(
|
|
164
|
+
abbr=ans.abbr,
|
|
165
|
+
allowsshort=allowsshort,
|
|
166
|
+
joined=ans.joined,
|
|
167
|
+
keys=tuple(parts),
|
|
168
|
+
)
|
|
171
169
|
ans.nargs = optdict[ans.fullkey]
|
|
172
170
|
if (ans.nargs == Nargs.NO_ARGUMENT) and (ans.right is not None):
|
|
173
171
|
cause(PUAW, option=ans.fullkey)
|
|
@@ -188,21 +186,37 @@ def parse_long_startswith(
|
|
|
188
186
|
return ans
|
|
189
187
|
|
|
190
188
|
|
|
189
|
+
def parse_minlen(
|
|
190
|
+
*,
|
|
191
|
+
abbr: str,
|
|
192
|
+
allowsshort: bool,
|
|
193
|
+
joined: bool,
|
|
194
|
+
keys: tuple[str, ...],
|
|
195
|
+
) -> int:
|
|
196
|
+
m: int
|
|
197
|
+
n: int
|
|
198
|
+
m = 2 + allowsshort - joined
|
|
199
|
+
n = len(abbr)
|
|
200
|
+
while n >= m and not any(z.startswith(abbr[:n]) for z in keys):
|
|
201
|
+
n -= 1
|
|
202
|
+
return n + 1
|
|
203
|
+
|
|
204
|
+
|
|
191
205
|
def parse_option(
|
|
192
206
|
arg: str,
|
|
193
207
|
*,
|
|
208
|
+
abbr: Optional[Tuning],
|
|
209
|
+
allowslong: bool,
|
|
210
|
+
allowsshort: bool,
|
|
194
211
|
cause: FunctionType,
|
|
195
|
-
expandsabbr: bool,
|
|
196
|
-
expectsabbr: bool,
|
|
197
212
|
optdict: dict,
|
|
198
|
-
**kwargs: Any,
|
|
199
213
|
) -> Option:
|
|
200
|
-
if
|
|
214
|
+
if (allowslong and arg.startswith("--")) or not allowsshort:
|
|
201
215
|
return parse_long(
|
|
202
216
|
arg,
|
|
217
|
+
abbr=abbr,
|
|
218
|
+
allowsshort=allowsshort,
|
|
203
219
|
cause=cause,
|
|
204
|
-
expandsabbr=expandsabbr,
|
|
205
|
-
expectsabbr=expectsabbr,
|
|
206
220
|
optdict=optdict,
|
|
207
221
|
)
|
|
208
222
|
else:
|
preparse/core/PreParser.py
CHANGED
|
@@ -23,11 +23,10 @@ __all__ = ["PreParser"]
|
|
|
23
23
|
|
|
24
24
|
class PreParser(Copyable):
|
|
25
25
|
|
|
26
|
+
abbr: Optional[Tuning]
|
|
26
27
|
allowslong: bool
|
|
27
28
|
allowsshort: bool
|
|
28
29
|
bundling: Tuning
|
|
29
|
-
expandsabbr: bool
|
|
30
|
-
expectsabbr: bool
|
|
31
30
|
expectsposix: bool
|
|
32
31
|
optdict: Optdict
|
|
33
32
|
prog: str
|
|
@@ -41,11 +40,10 @@ class PreParser(Copyable):
|
|
|
41
40
|
def __init__(
|
|
42
41
|
self: Self,
|
|
43
42
|
*,
|
|
43
|
+
abbr: Optional[Tuning] = Tuning.MINIMIZE,
|
|
44
44
|
allowslong: Any = True,
|
|
45
45
|
allowsshort: Any = True,
|
|
46
46
|
bundling: Any = Tuning.MAINTAIN,
|
|
47
|
-
expandsabbr: Any = True,
|
|
48
|
-
expectsabbr: Any = True,
|
|
49
47
|
expectsposix: Any = False,
|
|
50
48
|
optdict: Any = (),
|
|
51
49
|
prog: Any = None,
|
|
@@ -53,11 +51,10 @@ class PreParser(Copyable):
|
|
|
53
51
|
special: Any = Tuning.MAINTAIN,
|
|
54
52
|
warn: Callable = str,
|
|
55
53
|
) -> None:
|
|
54
|
+
self.abbr = abbr
|
|
56
55
|
self.allowslong = allowslong
|
|
57
56
|
self.allowsshort = allowsshort
|
|
58
57
|
self.bundling = bundling
|
|
59
|
-
self.expandsabbr = expandsabbr
|
|
60
|
-
self.expectsabbr = expectsabbr
|
|
61
58
|
self.expectsposix = expectsposix
|
|
62
59
|
self.optdict = optdict
|
|
63
60
|
self.prog = prog
|
|
@@ -69,6 +66,11 @@ class PreParser(Copyable):
|
|
|
69
66
|
def __repr__(self: Self) -> str:
|
|
70
67
|
return datarepr(type(self).__name__, **self.todict())
|
|
71
68
|
|
|
69
|
+
@dataprop
|
|
70
|
+
def abbr(self: Self, value: Any) -> bool:
|
|
71
|
+
if value is not None:
|
|
72
|
+
return Tuning(value)
|
|
73
|
+
|
|
72
74
|
@dataprop
|
|
73
75
|
def allowslong(self: Self, value: Any) -> bool:
|
|
74
76
|
return bool(value)
|
|
@@ -90,14 +92,6 @@ class PreParser(Copyable):
|
|
|
90
92
|
def copy(self: Self) -> Self:
|
|
91
93
|
return type(self)(**self.todict())
|
|
92
94
|
|
|
93
|
-
@dataprop
|
|
94
|
-
def expandsabbr(self: Self, value: Any) -> bool:
|
|
95
|
-
return bool(value)
|
|
96
|
-
|
|
97
|
-
@dataprop
|
|
98
|
-
def expectsabbr(self: Self, value: Any) -> bool:
|
|
99
|
-
return bool(value)
|
|
100
|
-
|
|
101
95
|
@dataprop
|
|
102
96
|
def expectsposix(self: Self, value: Any) -> bool:
|
|
103
97
|
if value == "infer":
|