preparse 1.0.11__tar.gz → 2.0.0.dev1__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.11/src/preparse.egg-info → preparse-2.0.0.dev1}/PKG-INFO +2 -2
- {preparse-1.0.11 → preparse-2.0.0.dev1}/docs/v1.0.rst +6 -6
- {preparse-1.0.11 → preparse-2.0.0.dev1}/pyproject.toml +2 -2
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_processing/__init__.py +2 -2
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_processing/digesting.py +0 -1
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_processing/parsing.py +16 -18
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/core/Optdict.py +2 -3
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/core/PreParser.py +20 -20
- preparse-2.0.0.dev1/src/preparse/core/PreparseWarning.py +6 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/core/__init__.py +1 -2
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/tests/data.toml +35328 -35328
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/tests/test_optdict.py +5 -6
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/tests/test_preparser.py +2 -3
- preparse-2.0.0.dev1/src/preparse/warners/AmbiguousOptionWarner.py +38 -0
- preparse-2.0.0.dev1/src/preparse/warners/DualWarner.py +33 -0
- preparse-2.0.0.dev1/src/preparse/warners/InvalidOptionWarner.py +14 -0
- preparse-2.0.0.dev1/src/preparse/warners/LongonlyWarner.py +13 -0
- preparse-2.0.0.dev1/src/preparse/warners/RequiredArgumentWarner.py +14 -0
- preparse-2.0.0.dev1/src/preparse/warners/UnallowedArgumentWarner.py +25 -0
- preparse-2.0.0.dev1/src/preparse/warners/WarnerABC.py +60 -0
- preparse-2.0.0.dev1/src/preparse/warners/__init__.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1/src/preparse.egg-info}/PKG-INFO +2 -2
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse.egg-info/SOURCES.txt +10 -2
- preparse-1.0.11/src/preparse/core/warnings.py +0 -152
- {preparse-1.0.11 → preparse-2.0.0.dev1}/LICENSE.txt +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/MANIFEST.in +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/README.rst +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/setup.cfg +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/__init__.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_items/Bundle.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_items/Item.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_items/Long.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_items/Option.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_items/Positional.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_items/Special.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_items/__init__.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_processing/deparsing.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_processing/pulling.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_utils/__init__.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/_utils/dataprop.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/core/Click.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/core/enums.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/tests/__init__.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/tests/expit.toml +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/tests/test_data_toml.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/tests/test_enums.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse/tests/test_expit_toml.py +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse.egg-info/dependency_links.txt +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse.egg-info/requires.txt +0 -0
- {preparse-1.0.11 → preparse-2.0.0.dev1}/src/preparse.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: preparse
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.0.dev1
|
|
4
4
|
Summary: This project preparses args for further parsing later on.
|
|
5
5
|
Author-email: Johannes <johannes.programming@gmail.com>
|
|
6
6
|
License: The MIT License (MIT)
|
|
@@ -28,7 +28,7 @@ Project-URL: Download, https://pypi.org/project/preparse/#files
|
|
|
28
28
|
Project-URL: Index, https://pypi.org/project/preparse/
|
|
29
29
|
Project-URL: Source, https://github.com/johannes-programming/preparse/
|
|
30
30
|
Project-URL: Website, https://preparse.johannes-programming.online/
|
|
31
|
-
Classifier: Development Status ::
|
|
31
|
+
Classifier: Development Status :: 3 - Alpha
|
|
32
32
|
Classifier: License :: OSI Approved :: MIT License
|
|
33
33
|
Classifier: Natural Language :: English
|
|
34
34
|
Classifier: Operating System :: OS Independent
|
|
@@ -64,7 +64,7 @@ Features
|
|
|
64
64
|
The PreParser class
|
|
65
65
|
~~~~~~~~~~~~~~~~~~~
|
|
66
66
|
|
|
67
|
-
``class preparse.PreParser(*, allowslong: Any = True, allowsshort: Any = True, bundling: Any = Tuning.MAINTAIN, expandsabbr: Any = True, expectsabbr: Any = True, expectsposix: Any = False,
|
|
67
|
+
``class preparse.PreParser(*, allowslong: Any = True, allowsshort: Any = True, bundling: Any = Tuning.MAINTAIN, expandsabbr: Any = True, expectsabbr: Any = True, expectsposix: Any = False, optDict: Any = (), prog: Any = None, reconcilesorders: Any = True, special: Any = preparse.Tuning.MAINTAIN, warn: Callable = str)``
|
|
68
68
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
69
69
|
|
|
70
70
|
This class is the centerpiece of the preparse. Its behaviour follows the principles of getopt from C.
|
|
@@ -109,7 +109,7 @@ This boolean property determines whether abbreviations of long options are expec
|
|
|
109
109
|
|
|
110
110
|
This boolean property determines whether the order of arguments to conform to the POSIX standard, i.e. all arguments after the first positional argument also being positonal.
|
|
111
111
|
|
|
112
|
-
``
|
|
112
|
+
``optDict: preparse.OptDict``
|
|
113
113
|
"""""""""""""""""""""""""""""
|
|
114
114
|
|
|
115
115
|
This property holds a dict-like object.
|
|
@@ -143,7 +143,7 @@ POSIX and the interleaving of options with positonal arguments, should be enforc
|
|
|
143
143
|
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
144
144
|
|
|
145
145
|
This method alters the current instance to reflect a ``click.Command`` object.
|
|
146
|
-
Concretely the
|
|
146
|
+
Concretely the optDict property is changed.
|
|
147
147
|
|
|
148
148
|
``reflectClickContext(ctx: click.Context) -> None``
|
|
149
149
|
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -202,15 +202,15 @@ This property determines if the ``reflectClickContext`` method of parser is to b
|
|
|
202
202
|
|
|
203
203
|
This property holds the parser to be embedded.
|
|
204
204
|
|
|
205
|
-
The
|
|
205
|
+
The OptDict class
|
|
206
206
|
~~~~~~~~~~~~~~~~~
|
|
207
207
|
|
|
208
|
-
``class preparse.
|
|
208
|
+
``class preparse.OptDict``
|
|
209
209
|
^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
210
210
|
|
|
211
211
|
This class is a subclass of ``datahold.HoldDict[str, preparse.Nargs]``
|
|
212
212
|
with strings as keys and with ``preparse.Nargs`` as values.
|
|
213
|
-
It is designed for ``preparse.PreParser.
|
|
213
|
+
It is designed for ``preparse.PreParser.optDict``.
|
|
214
214
|
|
|
215
215
|
The Enums
|
|
216
216
|
~~~~~~~~~
|
|
@@ -9,7 +9,7 @@ authors = [
|
|
|
9
9
|
{ email = "johannes.programming@gmail.com", name = "Johannes" },
|
|
10
10
|
]
|
|
11
11
|
classifiers = [
|
|
12
|
-
"Development Status ::
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
13
|
"License :: OSI Approved :: MIT License",
|
|
14
14
|
"Natural Language :: English",
|
|
15
15
|
"Operating System :: OS Independent",
|
|
@@ -34,7 +34,7 @@ keywords = []
|
|
|
34
34
|
name = "preparse"
|
|
35
35
|
readme = "README.rst"
|
|
36
36
|
requires-python = ">=3.11"
|
|
37
|
-
version = "
|
|
37
|
+
version = "2.0.0.dev1"
|
|
38
38
|
|
|
39
39
|
[project.license]
|
|
40
40
|
file = "LICENSE.txt"
|
|
@@ -21,7 +21,7 @@ def process(
|
|
|
21
21
|
expandsabbr: bool,
|
|
22
22
|
expectsabbr: bool,
|
|
23
23
|
expectsposix: bool,
|
|
24
|
-
|
|
24
|
+
optDict: dict,
|
|
25
25
|
prog: str,
|
|
26
26
|
reconcilesorders: bool,
|
|
27
27
|
special: Tuning,
|
|
@@ -36,7 +36,7 @@ def process(
|
|
|
36
36
|
allowsshort=allowsshort,
|
|
37
37
|
expectsabbr=expectsabbr,
|
|
38
38
|
expectsposix=expectsposix,
|
|
39
|
-
|
|
39
|
+
optDict=optDict,
|
|
40
40
|
prog=prog,
|
|
41
41
|
warn=warn,
|
|
42
42
|
)
|
|
@@ -7,16 +7,14 @@ from preparse._items.Long import Long
|
|
|
7
7
|
from preparse._items.Option import Option
|
|
8
8
|
from preparse._items.Positional import Positional
|
|
9
9
|
from preparse._items.Special import Special
|
|
10
|
-
from preparse.core import warnings
|
|
11
10
|
from preparse.core.enums import *
|
|
11
|
+
from preparse.warners.AmbiguousOptionWarner import AmbiguousOptionWarner as PAOW
|
|
12
|
+
from preparse.warners.InvalidOptionWarner import InvalidOptionWarner as PIOW
|
|
13
|
+
from preparse.warners.RequiredArgumentWarner import RequiredArgumentWarner as PRAW
|
|
14
|
+
from preparse.warners.UnallowedArgumentWarner import UnallowedArgumentWarner as PUAW
|
|
12
15
|
|
|
13
16
|
__all__ = ["parse"]
|
|
14
17
|
|
|
15
|
-
PAOW = warnings.PreparseAmbiguousOptionWarning
|
|
16
|
-
PIOW = warnings.PreparseInvalidOptionWarning
|
|
17
|
-
PUAW = warnings.PreparseUnallowedArgumentWarning
|
|
18
|
-
PRAW = warnings.PreparseRequiredArgumentWarning
|
|
19
|
-
|
|
20
18
|
|
|
21
19
|
def parse(args: list[str], **kwargs: Any) -> list[Item]:
|
|
22
20
|
return list(parse_generator(args, **kwargs))
|
|
@@ -26,7 +24,7 @@ def parse_bundling(
|
|
|
26
24
|
arg: str,
|
|
27
25
|
*,
|
|
28
26
|
cause: FunctionType,
|
|
29
|
-
|
|
27
|
+
optDict: dict,
|
|
30
28
|
) -> Bundle:
|
|
31
29
|
ans: Bundle
|
|
32
30
|
x: int
|
|
@@ -37,7 +35,7 @@ def parse_bundling(
|
|
|
37
35
|
continue
|
|
38
36
|
ans.chars += y
|
|
39
37
|
try:
|
|
40
|
-
ans.nargs =
|
|
38
|
+
ans.nargs = optDict["-" + y]
|
|
41
39
|
except KeyError:
|
|
42
40
|
cause(PIOW, option=y, islong=False)
|
|
43
41
|
ans.nargs = Nargs.NO_ARGUMENT
|
|
@@ -68,7 +66,7 @@ def parse_generator(
|
|
|
68
66
|
allowsshort: bool,
|
|
69
67
|
expectsabbr: bool,
|
|
70
68
|
expectsposix: bool,
|
|
71
|
-
|
|
69
|
+
optDict: dict,
|
|
72
70
|
prog: str,
|
|
73
71
|
warn: FunctionType,
|
|
74
72
|
) -> Generator[Any, Any, Any]:
|
|
@@ -106,7 +104,7 @@ def parse_generator(
|
|
|
106
104
|
allowsshort=allowsshort,
|
|
107
105
|
cause=cause,
|
|
108
106
|
expectsabbr=expectsabbr,
|
|
109
|
-
|
|
107
|
+
optDict=optDict,
|
|
110
108
|
)
|
|
111
109
|
if not last.ishungry():
|
|
112
110
|
yield last
|
|
@@ -138,7 +136,7 @@ def parse_long(
|
|
|
138
136
|
*,
|
|
139
137
|
cause: FunctionType,
|
|
140
138
|
expectsabbr: bool,
|
|
141
|
-
|
|
139
|
+
optDict: dict,
|
|
142
140
|
) -> Long:
|
|
143
141
|
ans: Long
|
|
144
142
|
parts: list[str]
|
|
@@ -148,13 +146,13 @@ def parse_long(
|
|
|
148
146
|
ans.joined = True
|
|
149
147
|
ans.right = parts.pop()
|
|
150
148
|
ans.abbrlen = len(ans.fullkey)
|
|
151
|
-
if ans.fullkey in
|
|
152
|
-
ans.nargs =
|
|
149
|
+
if ans.fullkey in optDict.keys():
|
|
150
|
+
ans.nargs = optDict[ans.fullkey]
|
|
153
151
|
if (ans.nargs == Nargs.NO_ARGUMENT) and (ans.right is not None):
|
|
154
152
|
cause(PUAW, option=ans.fullkey)
|
|
155
153
|
return ans
|
|
156
154
|
if expectsabbr:
|
|
157
|
-
parts = parse_long_startswith(ans.abbr, keys=
|
|
155
|
+
parts = parse_long_startswith(ans.abbr, keys=optDict.keys())
|
|
158
156
|
else:
|
|
159
157
|
parts = list() # can be assumed
|
|
160
158
|
if len(parts) == 0:
|
|
@@ -166,7 +164,7 @@ def parse_long(
|
|
|
166
164
|
cause(PAOW, option=arg, possibilities=parts)
|
|
167
165
|
return ans
|
|
168
166
|
(ans.fullkey,) = parts
|
|
169
|
-
ans.nargs =
|
|
167
|
+
ans.nargs = optDict[ans.fullkey]
|
|
170
168
|
return ans
|
|
171
169
|
|
|
172
170
|
|
|
@@ -189,7 +187,7 @@ def parse_option(
|
|
|
189
187
|
*,
|
|
190
188
|
cause: FunctionType,
|
|
191
189
|
expectsabbr: bool,
|
|
192
|
-
|
|
190
|
+
optDict: dict,
|
|
193
191
|
**kwargs: Any,
|
|
194
192
|
) -> Option:
|
|
195
193
|
if parse_islong(arg, **kwargs):
|
|
@@ -197,11 +195,11 @@ def parse_option(
|
|
|
197
195
|
arg,
|
|
198
196
|
cause=cause,
|
|
199
197
|
expectsabbr=expectsabbr,
|
|
200
|
-
|
|
198
|
+
optDict=optDict,
|
|
201
199
|
)
|
|
202
200
|
else:
|
|
203
201
|
return parse_bundling(
|
|
204
202
|
arg,
|
|
205
203
|
cause=cause,
|
|
206
|
-
|
|
204
|
+
optDict=optDict,
|
|
207
205
|
)
|
|
@@ -7,12 +7,11 @@ from datarepr import datarepr
|
|
|
7
7
|
from frozendict import frozendict
|
|
8
8
|
|
|
9
9
|
from preparse.core.enums import *
|
|
10
|
-
from preparse.core.warnings import *
|
|
11
10
|
|
|
12
|
-
__all__ = ["
|
|
11
|
+
__all__ = ["OptDict"]
|
|
13
12
|
|
|
14
13
|
|
|
15
|
-
class
|
|
14
|
+
class OptDict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
|
|
16
15
|
__slots__ = ()
|
|
17
16
|
|
|
18
17
|
data: frozendict[str, Nargs]
|
|
@@ -15,8 +15,8 @@ from preparse._processing import *
|
|
|
15
15
|
from preparse._utils.dataprop import dataprop
|
|
16
16
|
from preparse.core.Click import Click
|
|
17
17
|
from preparse.core.enums import *
|
|
18
|
-
from preparse.core.
|
|
19
|
-
from preparse.
|
|
18
|
+
from preparse.core.OptDict import OptDict
|
|
19
|
+
from preparse.warners import *
|
|
20
20
|
|
|
21
21
|
__all__ = ["PreParser"]
|
|
22
22
|
|
|
@@ -29,11 +29,11 @@ class PreParser(Copyable):
|
|
|
29
29
|
expandsabbr: bool
|
|
30
30
|
expectsabbr: bool
|
|
31
31
|
expectsposix: bool
|
|
32
|
-
|
|
32
|
+
optDict: OptDict
|
|
33
33
|
prog: str
|
|
34
34
|
reconcilesorders: bool
|
|
35
35
|
special: Tuning
|
|
36
|
-
warn:
|
|
36
|
+
warn: Callable
|
|
37
37
|
|
|
38
38
|
__slots__ = ("_data",)
|
|
39
39
|
|
|
@@ -47,11 +47,11 @@ class PreParser(Copyable):
|
|
|
47
47
|
expandsabbr: Any = True,
|
|
48
48
|
expectsabbr: Any = True,
|
|
49
49
|
expectsposix: Any = False,
|
|
50
|
-
|
|
50
|
+
optDict: Any = (),
|
|
51
51
|
prog: Any = None,
|
|
52
52
|
reconcilesorders: Any = True,
|
|
53
53
|
special: Any = Tuning.MAINTAIN,
|
|
54
|
-
warn:
|
|
54
|
+
warn: types.FunctionType = str,
|
|
55
55
|
) -> None:
|
|
56
56
|
self.allowslong = allowslong
|
|
57
57
|
self.allowsshort = allowsshort
|
|
@@ -59,7 +59,7 @@ class PreParser(Copyable):
|
|
|
59
59
|
self.expandsabbr = expandsabbr
|
|
60
60
|
self.expectsabbr = expectsabbr
|
|
61
61
|
self.expectsposix = expectsposix
|
|
62
|
-
self.
|
|
62
|
+
self.optDict = optDict
|
|
63
63
|
self.prog = prog
|
|
64
64
|
self.reconcilesorders = reconcilesorders
|
|
65
65
|
self.special = special
|
|
@@ -106,15 +106,15 @@ class PreParser(Copyable):
|
|
|
106
106
|
return bool(value)
|
|
107
107
|
|
|
108
108
|
@dataprop
|
|
109
|
-
def
|
|
109
|
+
def optDict(self: Self, value: Any) -> OptDict:
|
|
110
110
|
"This property gives a dictionary of options."
|
|
111
|
-
dataA:
|
|
112
|
-
if "
|
|
113
|
-
self._data["
|
|
114
|
-
dataA =
|
|
115
|
-
self._data["
|
|
116
|
-
self._data["
|
|
117
|
-
return self._data["
|
|
111
|
+
dataA: OptDict
|
|
112
|
+
if "optDict" not in self._data.keys():
|
|
113
|
+
self._data["optDict"] = OptDict()
|
|
114
|
+
dataA = OptDict(value)
|
|
115
|
+
self._data["optDict"].clear()
|
|
116
|
+
self._data["optDict"].update(dataA)
|
|
117
|
+
return self._data["optDict"]
|
|
118
118
|
|
|
119
119
|
def parse_args(
|
|
120
120
|
self: Self,
|
|
@@ -137,11 +137,11 @@ class PreParser(Copyable):
|
|
|
137
137
|
|
|
138
138
|
def reflectClickCommand(self: Self, cmd: cl.Command) -> None:
|
|
139
139
|
"This method causes the current instance to reflect a click.Command object."
|
|
140
|
-
|
|
140
|
+
optDict: dict[str, Nargs]
|
|
141
141
|
nargs: Nargs
|
|
142
142
|
opt: Any
|
|
143
143
|
param: Any
|
|
144
|
-
|
|
144
|
+
optDict = dict()
|
|
145
145
|
for param in cmd.params:
|
|
146
146
|
if not isinstance(param, cl.Option):
|
|
147
147
|
continue
|
|
@@ -152,9 +152,9 @@ class PreParser(Copyable):
|
|
|
152
152
|
else:
|
|
153
153
|
nargs = Nargs.OPTIONAL_ARGUMENT
|
|
154
154
|
for opt in param.opts:
|
|
155
|
-
|
|
156
|
-
self.
|
|
157
|
-
self.
|
|
155
|
+
optDict[str(opt)] = nargs
|
|
156
|
+
self.optDict.clear()
|
|
157
|
+
self.optDict.update(optDict)
|
|
158
158
|
|
|
159
159
|
def reflectClickContext(self: Self, ctx: cl.Context) -> None:
|
|
160
160
|
"This method causes the current instance to reflect a click.Context object."
|