preparse 1.1.2__tar.gz → 1.1.4__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.1.2 → preparse-1.1.4}/PKG-INFO +3 -3
- {preparse-1.1.2 → preparse-1.1.4}/docs/v1.1.rst +43 -33
- {preparse-1.1.2 → preparse-1.1.4}/pyproject.toml +3 -12
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_processing/__init__.py +3 -2
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_processing/parsing.py +6 -5
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_processing/pulling.py +4 -3
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/core/Optdict.py +8 -4
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/core/PreParser.py +12 -10
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/tests/test_data_toml.py +11 -7
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/tests/test_enums.py +1 -1
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/tests/test_expit_toml.py +6 -6
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/tests/test_optdict.py +1 -1
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/tests/test_preparser.py +2 -2
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse.egg-info/PKG-INFO +3 -3
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse.egg-info/requires.txt +2 -2
- {preparse-1.1.2 → preparse-1.1.4}/LICENSE.txt +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/MANIFEST.in +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/README.rst +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/docs/v1.0.rst +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/setup.cfg +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/__init__.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_items/Bundle.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_items/Item.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_items/Long.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_items/Option.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_items/Positional.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_items/Special.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_items/__init__.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_processing/deparsing.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_processing/digesting.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_tests/__init__.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_tests/expit.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_utils/__init__.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/_utils/dataprop.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/core/Click.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/core/__init__.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/core/enums.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/core/warnings.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/py.typed +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/tests/__init__.py +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/tests/data.toml +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse/tests/expit.toml +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse.egg-info/SOURCES.txt +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/src/preparse.egg-info/dependency_links.txt +0 -0
- {preparse-1.1.2 → preparse-1.1.4}/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: 1.1.
|
|
3
|
+
Version: 1.1.4
|
|
4
4
|
Summary: This project preparses args for further parsing later on.
|
|
5
5
|
Author-email: Johannes <johannes.programming@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -21,10 +21,10 @@ License-File: LICENSE.txt
|
|
|
21
21
|
Requires-Dist: click<9,>=8.2
|
|
22
22
|
Requires-Dist: cmp3<2,>=1.0
|
|
23
23
|
Requires-Dist: copyable<2,>=1.1
|
|
24
|
-
Requires-Dist: datahold<4,>=3.0
|
|
24
|
+
Requires-Dist: datahold<4,>=3.0.34.dev1
|
|
25
25
|
Requires-Dist: datarepr<2,>=1.2
|
|
26
26
|
Requires-Dist: frozendict<3,>=2.4.7
|
|
27
|
-
Requires-Dist: setdoc<2,>=1.
|
|
27
|
+
Requires-Dist: setdoc<2,>=1.3
|
|
28
28
|
Requires-Dist: tofunc<2,>=1.1
|
|
29
29
|
Dynamic: license-file
|
|
30
30
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
Overview
|
|
2
2
|
--------
|
|
3
3
|
|
|
4
|
-
The preparse project allows to preparse arguments before the main parsing.
|
|
4
|
+
The ``preparse`` project allows to preparse arguments before the main parsing.
|
|
5
5
|
Its ability to deabbreviate options is especially useful for use with ``click``.
|
|
6
6
|
|
|
7
7
|
Installation
|
|
8
8
|
------------
|
|
9
9
|
|
|
10
|
-
To install preparse
|
|
10
|
+
To install ``preparse``, you can use ``pip``.
|
|
11
|
+
Open your terminal and run:
|
|
11
12
|
|
|
12
13
|
.. code-block:: shell
|
|
13
14
|
|
|
@@ -25,11 +26,16 @@ The typing conforms (not strictly) to ``mypy``.
|
|
|
25
26
|
Introduction
|
|
26
27
|
------------
|
|
27
28
|
|
|
28
|
-
The preparse project allows for preprocessing a list of arguments
|
|
29
|
+
The ``preparse`` project allows for preprocessing a ``list`` of arguments
|
|
30
|
+
so that they can be parsed definitively in a later step.
|
|
31
|
+
This way, the functionality of another parsing system can be modified.
|
|
32
|
+
The project is especially adapted to work with the ``click`` project.
|
|
29
33
|
|
|
30
|
-
The project preparse is strongly inspired
|
|
34
|
+
The project ``preparse`` is strongly inspired
|
|
35
|
+
by the ``getopt`` and ``getopt_long`` libraries within ``C``.
|
|
31
36
|
|
|
32
|
-
Here is the implementation of the ``expit`` project (Version 1.0.13) to illustrate
|
|
37
|
+
Here is the implementation of the ``expit`` project (Version ``1.0.13``) to illustrate
|
|
38
|
+
how ``preparse`` can be used to modify ``click``.
|
|
33
39
|
|
|
34
40
|
.. code-block:: python
|
|
35
41
|
|
|
@@ -62,28 +68,29 @@ Here is the implementation of the ``expit`` project (Version 1.0.13) to illustra
|
|
|
62
68
|
Features
|
|
63
69
|
--------
|
|
64
70
|
|
|
65
|
-
The PreParser class
|
|
66
|
-
|
|
71
|
+
The ``PreParser`` class
|
|
72
|
+
~~~~~~~~~~~~~~~~~~~~~~~
|
|
67
73
|
|
|
68
74
|
``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)``
|
|
69
75
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
70
76
|
|
|
71
|
-
This class is the centerpiece of the preparse
|
|
77
|
+
This ``class`` is the centerpiece of the ``preparse``.
|
|
78
|
+
Its behaviour follows the principles of ``getopt`` from ``C``.
|
|
72
79
|
|
|
73
80
|
``allowslong: bool``
|
|
74
81
|
""""""""""""""""""""
|
|
75
82
|
|
|
76
|
-
This boolean property determines whether long options are allowed.
|
|
83
|
+
This boolean ``property`` determines whether long options are allowed.
|
|
77
84
|
|
|
78
85
|
``allowsshort: bool``
|
|
79
86
|
"""""""""""""""""""""
|
|
80
87
|
|
|
81
|
-
This boolean property determines whether short options are allowed.
|
|
88
|
+
This boolean ``property`` determines whether short options are allowed.
|
|
82
89
|
|
|
83
90
|
``bundling: preparse.Tuning``
|
|
84
91
|
"""""""""""""""""""""""""""""
|
|
85
92
|
|
|
86
|
-
This ``
|
|
93
|
+
This ``property`` determines the approach to bundling of short option.
|
|
87
94
|
|
|
88
95
|
``click(cmd: Any = True, ctx: Any = True) -> preparse.Click``
|
|
89
96
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
@@ -98,22 +105,24 @@ This method returns a copy of the current instance.
|
|
|
98
105
|
``expandsabbr: bool``
|
|
99
106
|
"""""""""""""""""""""
|
|
100
107
|
|
|
101
|
-
This boolean property determines whether recognized abbreviations of long options
|
|
108
|
+
This boolean ``property`` determines whether recognized abbreviations of long options
|
|
109
|
+
are to be expanded to their full length.
|
|
102
110
|
|
|
103
111
|
``expectsabbr: bool``
|
|
104
112
|
"""""""""""""""""""""
|
|
105
113
|
|
|
106
|
-
This boolean property determines whether abbreviations of long options are expected.
|
|
114
|
+
This boolean ``property`` determines whether abbreviations of long options are expected.
|
|
107
115
|
|
|
108
116
|
``expectsposix: bool``
|
|
109
117
|
""""""""""""""""""""""
|
|
110
118
|
|
|
111
|
-
This boolean property determines whether the order of arguments to conform to the POSIX standard,
|
|
119
|
+
This boolean ``property`` determines whether the order of arguments to conform to the POSIX standard,
|
|
120
|
+
i.e. all arguments after the first positional argument also being positonal.
|
|
112
121
|
|
|
113
122
|
``optdict: preparse.Optdict``
|
|
114
123
|
"""""""""""""""""""""""""""""
|
|
115
124
|
|
|
116
|
-
This property holds a dict-like object.
|
|
125
|
+
This ``property`` holds a dict-like object.
|
|
117
126
|
Its keys are the options.
|
|
118
127
|
Its values specify ``preparse.Nargs``.
|
|
119
128
|
Options not found within the dictionary
|
|
@@ -126,7 +135,8 @@ and are then assumed to have no arguments.
|
|
|
126
135
|
This method is at the core of the class.
|
|
127
136
|
It returns a preparsed list of arguments.
|
|
128
137
|
If ``None`` is passed as args then ``sys.argv[1:]`` is used.
|
|
129
|
-
If the method is applied repeatedly to a list
|
|
138
|
+
If the method is applied repeatedly to a ``list``
|
|
139
|
+
there will be no changes after the first run.
|
|
130
140
|
|
|
131
141
|
``prog: str``
|
|
132
142
|
"""""""""""""
|
|
@@ -137,30 +147,30 @@ If the value passed to the property is ``None`` then ``str(sys.argv[0])`` is sav
|
|
|
137
147
|
``reconcilesorders: bool``
|
|
138
148
|
""""""""""""""""""""""""""
|
|
139
149
|
|
|
140
|
-
This boolean property determines whether compatibility with both orders,
|
|
150
|
+
This boolean ``property`` determines whether compatibility with both orders,
|
|
141
151
|
POSIX and the interleaving of options with positonal arguments, should be enforced.
|
|
142
152
|
|
|
143
153
|
``reflectClickCommand(cmd: click.Command) -> None``
|
|
144
154
|
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
145
155
|
|
|
146
156
|
This method alters the current instance to reflect a ``click.Command`` object.
|
|
147
|
-
Concretely the optdict property is changed.
|
|
157
|
+
Concretely the ``optdict`` property is changed.
|
|
148
158
|
|
|
149
159
|
``reflectClickContext(ctx: click.Context) -> None``
|
|
150
160
|
"""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
151
161
|
|
|
152
162
|
This method alters the current instance to reflect a ``click.Context`` object.
|
|
153
|
-
Concretely the prog property is changed.
|
|
163
|
+
Concretely the ``prog`` property is changed.
|
|
154
164
|
|
|
155
165
|
``special: preparse.Tuning``
|
|
156
166
|
""""""""""""""""""""""""""""
|
|
157
167
|
|
|
158
|
-
This ``
|
|
168
|
+
This ``property`` determines the approach to the special argument ``'--'``.
|
|
159
169
|
|
|
160
|
-
``todict() -> dict``
|
|
161
|
-
""""""""""""""""""""
|
|
170
|
+
``todict() -> dict[str, Any]``
|
|
171
|
+
""""""""""""""""""""""""""""""
|
|
162
172
|
|
|
163
|
-
This method a dict representing the current instance.
|
|
173
|
+
This method a ``dict`` representing the current instance.
|
|
164
174
|
|
|
165
175
|
``warn: types.FunctionType``
|
|
166
176
|
""""""""""""""""""""""""""""
|
|
@@ -183,12 +193,12 @@ This dataclass provides decorators for embedding a ``PreParser`` object.
|
|
|
183
193
|
""""""""""""""""""""""""""""""""
|
|
184
194
|
|
|
185
195
|
This magic method implements ``self(target)``.
|
|
186
|
-
It works as a decorator that embeds its parser into a given target from the library click
|
|
196
|
+
It works as a decorator that embeds its parser into a given target from the library ``click``.
|
|
187
197
|
|
|
188
198
|
``cmd: Any``
|
|
189
199
|
""""""""""""
|
|
190
200
|
|
|
191
|
-
This property determines if the ``reflectClickCommand`` method of parser is to be called.
|
|
201
|
+
This ``property`` determines if the ``reflectClickCommand`` method of parser is to be called.
|
|
192
202
|
|
|
193
203
|
``copy() -> Self``
|
|
194
204
|
""""""""""""""""""
|
|
@@ -196,12 +206,12 @@ This property determines if the ``reflectClickCommand`` method of parser is to b
|
|
|
196
206
|
``ctx: Any``
|
|
197
207
|
""""""""""""
|
|
198
208
|
|
|
199
|
-
This property determines if the ``reflectClickContext`` method of parser is to be called.
|
|
209
|
+
This ``property`` determines if the ``reflectClickContext`` method of parser is to be called.
|
|
200
210
|
|
|
201
211
|
``parser: preparse.PreParser``
|
|
202
212
|
""""""""""""""""""""""""""""""
|
|
203
213
|
|
|
204
|
-
This property holds the parser to be embedded.
|
|
214
|
+
This ``property`` holds the parser to be embedded.
|
|
205
215
|
|
|
206
216
|
The Optdict class
|
|
207
217
|
~~~~~~~~~~~~~~~~~
|
|
@@ -253,27 +263,27 @@ These classes are subclasses of ``Warning`` that are specifically designed to co
|
|
|
253
263
|
``class preparse.PreparseWarning``
|
|
254
264
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
255
265
|
|
|
256
|
-
This abstract base class is the base for all other warning types.
|
|
266
|
+
This abstract base ``class`` is the base for all other warning types.
|
|
257
267
|
|
|
258
268
|
``class preparse.PreparseAmbiguousOptionWarning(prog: Any, option: Any, possibilities: Any)``
|
|
259
269
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
260
270
|
|
|
261
|
-
This class warns about ambiguous options. This can only happen for long options.
|
|
271
|
+
This ``class`` warns about ambiguous options. This can only happen for long options.
|
|
262
272
|
|
|
263
273
|
``class preparse.PreparseInvalidOptionWarning(prog: Any, option: Any, islong: Any)``
|
|
264
274
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
265
275
|
|
|
266
|
-
This class warns about invalid options.
|
|
276
|
+
This ``class`` warns about invalid options.
|
|
267
277
|
|
|
268
278
|
``class preparse.PreparseRequiredArgumentWarning(prog: Any, option: Any, islong: Any)``
|
|
269
279
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
270
280
|
|
|
271
|
-
This class warns about missing required arguments.
|
|
281
|
+
This ``class`` warns about missing required arguments.
|
|
272
282
|
|
|
273
283
|
``class preparse.PreparseUnallowedArgumentWarning(prog: Any, option: Any)``
|
|
274
284
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
275
285
|
|
|
276
|
-
This class warns about unallowed arguments. This can only happen for long options.
|
|
286
|
+
This ``class`` warns about unallowed arguments. This can only happen for long options.
|
|
277
287
|
|
|
278
288
|
The Tests
|
|
279
289
|
~~~~~~~~~
|
|
@@ -281,7 +291,7 @@ The Tests
|
|
|
281
291
|
``preparse.tests.test() -> unittest.TextTestResult``
|
|
282
292
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
283
293
|
|
|
284
|
-
This project can be tested through its test function.
|
|
294
|
+
This project can be tested through its ``test`` function.
|
|
285
295
|
|
|
286
296
|
.. code-block:: python
|
|
287
297
|
|
|
@@ -21,10 +21,10 @@ dependencies = [
|
|
|
21
21
|
"click>=8.2,<9",
|
|
22
22
|
"cmp3>=1.0,<2",
|
|
23
23
|
"copyable>=1.1,<2",
|
|
24
|
-
"datahold>=3.0,<4",
|
|
24
|
+
"datahold>=3.0.34.dev1,<4",
|
|
25
25
|
"datarepr>=1.2,<2",
|
|
26
26
|
"frozendict>=2.4.7,<3",
|
|
27
|
-
"setdoc>=1.
|
|
27
|
+
"setdoc>=1.3,<2",
|
|
28
28
|
"tofunc>=1.1,<2",
|
|
29
29
|
]
|
|
30
30
|
description = "This project preparses args for further parsing later on."
|
|
@@ -36,7 +36,7 @@ license-files = [
|
|
|
36
36
|
name = "preparse"
|
|
37
37
|
readme = "README.rst"
|
|
38
38
|
requires-python = ">=3.11"
|
|
39
|
-
version = "1.1.
|
|
39
|
+
version = "1.1.4"
|
|
40
40
|
|
|
41
41
|
[project.urls]
|
|
42
42
|
Download = "https://pypi.org/project/preparse/#files"
|
|
@@ -50,12 +50,3 @@ files = [
|
|
|
50
50
|
]
|
|
51
51
|
python_version = "3.11"
|
|
52
52
|
strict = false
|
|
53
|
-
|
|
54
|
-
[[tool.mypy.overrides]]
|
|
55
|
-
module = [
|
|
56
|
-
"cmp3",
|
|
57
|
-
"cmp3.*",
|
|
58
|
-
"datahold",
|
|
59
|
-
"datahold.*",
|
|
60
|
-
]
|
|
61
|
-
ignore_missing_imports = true
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
1
2
|
from types import FunctionType
|
|
2
|
-
from typing import
|
|
3
|
+
from typing import Optional
|
|
3
4
|
|
|
4
5
|
from preparse._items import *
|
|
5
6
|
from preparse._processing.deparsing import *
|
|
@@ -13,7 +14,7 @@ __all__ = ["process"]
|
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
def process(
|
|
16
|
-
args: Optional[Iterable] = None,
|
|
17
|
+
args: Optional[Iterable[object]] = None,
|
|
17
18
|
*,
|
|
18
19
|
allowslong: bool,
|
|
19
20
|
allowsshort: bool,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
1
2
|
from types import FunctionType
|
|
2
|
-
from typing import
|
|
3
|
+
from typing import Any, Generator
|
|
3
4
|
|
|
4
5
|
from preparse._items.Bundle import Bundle
|
|
5
6
|
from preparse._items.Item import Item
|
|
@@ -26,7 +27,7 @@ def parse_bundling(
|
|
|
26
27
|
arg: str,
|
|
27
28
|
*,
|
|
28
29
|
cause: FunctionType,
|
|
29
|
-
optdict: dict,
|
|
30
|
+
optdict: dict[Any, Any],
|
|
30
31
|
) -> Bundle:
|
|
31
32
|
ans: Bundle
|
|
32
33
|
x: int
|
|
@@ -67,7 +68,7 @@ def parse_generator(
|
|
|
67
68
|
allowsshort: bool,
|
|
68
69
|
expectsabbr: bool,
|
|
69
70
|
expectsposix: bool,
|
|
70
|
-
optdict: dict,
|
|
71
|
+
optdict: dict[Any, Any],
|
|
71
72
|
prog: str,
|
|
72
73
|
warn: FunctionType,
|
|
73
74
|
) -> Generator[Any, Any, Any]:
|
|
@@ -137,7 +138,7 @@ def parse_long(
|
|
|
137
138
|
*,
|
|
138
139
|
cause: FunctionType,
|
|
139
140
|
expectsabbr: bool,
|
|
140
|
-
optdict: dict,
|
|
141
|
+
optdict: dict[Any, Any],
|
|
141
142
|
) -> Long:
|
|
142
143
|
ans: Long
|
|
143
144
|
parts: list[str]
|
|
@@ -187,7 +188,7 @@ def parse_option(
|
|
|
187
188
|
*,
|
|
188
189
|
cause: FunctionType,
|
|
189
190
|
expectsabbr: bool,
|
|
190
|
-
optdict: dict,
|
|
191
|
+
optdict: dict[Any, Any],
|
|
191
192
|
**kwargs: Any,
|
|
192
193
|
) -> Option:
|
|
193
194
|
if parse_islong(arg, **kwargs):
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import sys
|
|
2
|
-
from
|
|
2
|
+
from collections.abc import Iterable
|
|
3
|
+
from typing import Optional
|
|
3
4
|
|
|
4
5
|
from preparse._items.Item import Item
|
|
5
6
|
from preparse._items.Positional import Positional
|
|
@@ -7,9 +8,9 @@ from preparse._items.Positional import Positional
|
|
|
7
8
|
__all__ = ["pull"]
|
|
8
9
|
|
|
9
10
|
|
|
10
|
-
def pull(args: Optional[Iterable] = None) -> list[Item]:
|
|
11
|
+
def pull(args: Optional[Iterable[object]] = None) -> list[Item]:
|
|
11
12
|
"This method acquires args."
|
|
12
|
-
argiter: Iterable
|
|
13
|
+
argiter: Iterable[object]
|
|
13
14
|
if args is None:
|
|
14
15
|
argiter = sys.argv[1:]
|
|
15
16
|
else:
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from typing import
|
|
1
|
+
from typing import Any, Optional, Self
|
|
2
2
|
|
|
3
3
|
import cmp3 # type: ignore
|
|
4
4
|
import datahold
|
|
5
5
|
import setdoc
|
|
6
|
-
from datarepr import datarepr
|
|
6
|
+
from datarepr import datarepr # type: ignore
|
|
7
7
|
from frozendict import frozendict
|
|
8
8
|
|
|
9
9
|
from preparse.core.enums import *
|
|
@@ -26,6 +26,10 @@ class Optdict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
|
|
|
26
26
|
|
|
27
27
|
__format__ = object.__format__
|
|
28
28
|
|
|
29
|
+
@setdoc.basic
|
|
30
|
+
def __init__(self: Self, data: Any = (), /) -> None:
|
|
31
|
+
datahold.HoldDict[str, Nargs].__init__(self, data)
|
|
32
|
+
|
|
29
33
|
@setdoc.basic
|
|
30
34
|
def __repr__(self: Self, /) -> str:
|
|
31
35
|
return datarepr(type(self).__name__, dict(self._data))
|
|
@@ -38,10 +42,10 @@ class Optdict(cmp3.CmpABC, datahold.HoldDict[str, Nargs]):
|
|
|
38
42
|
|
|
39
43
|
@data.setter
|
|
40
44
|
def data(self: Self, value: Any) -> None:
|
|
41
|
-
a: frozendict
|
|
45
|
+
a: frozendict[Any, Any]
|
|
42
46
|
x: map
|
|
43
47
|
y: map
|
|
44
48
|
a = frozendict(value)
|
|
45
49
|
x = map(str, a.keys())
|
|
46
50
|
y = map(Nargs, a.values())
|
|
47
|
-
self._data = frozendict
|
|
51
|
+
self._data = frozendict(zip(x, y, strict=True))
|
|
@@ -3,19 +3,20 @@ from __future__ import annotations
|
|
|
3
3
|
import os
|
|
4
4
|
import sys
|
|
5
5
|
import types
|
|
6
|
-
from
|
|
6
|
+
from collections.abc import Iterable
|
|
7
|
+
from typing import Any, Callable, Optional, Self, cast
|
|
7
8
|
|
|
8
9
|
import click as cl
|
|
9
10
|
import setdoc
|
|
10
11
|
from copyable import Copyable
|
|
11
|
-
from datarepr import datarepr
|
|
12
|
-
from tofunc import tofunc
|
|
12
|
+
from datarepr import datarepr # type: ignore[attr-defined]
|
|
13
|
+
from tofunc import tofunc # type: ignore[attr-defined]
|
|
13
14
|
|
|
14
15
|
from preparse._processing import *
|
|
15
16
|
from preparse._utils.dataprop import dataprop
|
|
16
17
|
from preparse.core.Click import Click
|
|
17
18
|
from preparse.core.enums import *
|
|
18
|
-
from preparse.core.Optdict import
|
|
19
|
+
from preparse.core.Optdict import Optdict
|
|
19
20
|
from preparse.core.warnings import *
|
|
20
21
|
|
|
21
22
|
__all__ = ["PreParser"]
|
|
@@ -39,9 +40,10 @@ class PreParser(Copyable):
|
|
|
39
40
|
prog: Any = None,
|
|
40
41
|
reconcilesorders: Any = True,
|
|
41
42
|
special: Any = Tuning.MAINTAIN,
|
|
42
|
-
warn: Callable = str,
|
|
43
|
+
warn: Callable = str, # type: ignore[type-arg]
|
|
43
44
|
) -> None:
|
|
44
|
-
self._data: dict[str, Any]
|
|
45
|
+
self._data: dict[str, Any]
|
|
46
|
+
self._data = dict()
|
|
45
47
|
self.allowslong = allowslong
|
|
46
48
|
self.allowsshort = allowsshort
|
|
47
49
|
self.bundling = bundling
|
|
@@ -103,11 +105,11 @@ class PreParser(Copyable):
|
|
|
103
105
|
dataA = Optdict(value)
|
|
104
106
|
self._data["optdict"].clear()
|
|
105
107
|
self._data["optdict"].update(dataA)
|
|
106
|
-
return self._data["optdict"]
|
|
108
|
+
return cast(Optdict, self._data["optdict"])
|
|
107
109
|
|
|
108
110
|
def parse_args(
|
|
109
111
|
self: Self,
|
|
110
|
-
args: Optional[Iterable] = None,
|
|
112
|
+
args: Optional[Iterable[object]] = None,
|
|
111
113
|
) -> list[str]:
|
|
112
114
|
"This method parses args."
|
|
113
115
|
return process(args, **self.todict())
|
|
@@ -154,9 +156,9 @@ class PreParser(Copyable):
|
|
|
154
156
|
"This Tuning property determines the approach towards the special argument."
|
|
155
157
|
return Tuning(value)
|
|
156
158
|
|
|
157
|
-
def todict(self: Self) -> dict:
|
|
159
|
+
def todict(self: Self) -> dict[str, Any]:
|
|
158
160
|
"This method returns a dict representing the current instance."
|
|
159
|
-
ans: dict
|
|
161
|
+
ans: dict[str, Any]
|
|
160
162
|
try:
|
|
161
163
|
ans = self._data
|
|
162
164
|
except AttributeError:
|
|
@@ -35,7 +35,7 @@ class TestDataToml(unittest.TestCase):
|
|
|
35
35
|
def test_0(self: Self) -> None:
|
|
36
36
|
data: dict[str, Any]
|
|
37
37
|
name: str
|
|
38
|
-
kwargs: dict
|
|
38
|
+
kwargs: dict[str, Any]
|
|
39
39
|
data = Utils.utils.get_data()
|
|
40
40
|
for name, kwargs in data.items():
|
|
41
41
|
with self.subTest(msg=name, **kwargs):
|
|
@@ -49,12 +49,12 @@ class TestDataToml(unittest.TestCase):
|
|
|
49
49
|
warnings: Any,
|
|
50
50
|
**kwargs: Any,
|
|
51
51
|
) -> None:
|
|
52
|
-
answer: list
|
|
53
|
-
capture: list
|
|
54
|
-
data: dict
|
|
55
|
-
erranswer: list
|
|
52
|
+
answer: list[Any]
|
|
53
|
+
capture: list[Any]
|
|
54
|
+
data: dict[str, Any]
|
|
55
|
+
erranswer: list[Any]
|
|
56
56
|
msg: str
|
|
57
|
-
superanswer: list
|
|
57
|
+
superanswer: list[Any]
|
|
58
58
|
parser: PreParser
|
|
59
59
|
capture = list()
|
|
60
60
|
|
|
@@ -77,7 +77,11 @@ class TestDataToml(unittest.TestCase):
|
|
|
77
77
|
superanswer,
|
|
78
78
|
)
|
|
79
79
|
self.assertEqual(answer, superanswer, msg=msg)
|
|
80
|
-
msg = "\n\ndata=%s,\nanswer=%s,\nsolution=%s,\n\n" % (
|
|
80
|
+
msg = "\n\ndata=%s,\nanswer=%s,\nsolution=%s,\n\n" % (
|
|
81
|
+
data,
|
|
82
|
+
answer,
|
|
83
|
+
solution,
|
|
84
|
+
)
|
|
81
85
|
self.assertEqual(answer, solution, msg=msg)
|
|
82
86
|
if not Utils.utils.istestable(warnings):
|
|
83
87
|
return
|
|
@@ -3,7 +3,7 @@ import math
|
|
|
3
3
|
import tomllib
|
|
4
4
|
import unittest
|
|
5
5
|
from importlib import resources
|
|
6
|
-
from typing import
|
|
6
|
+
from typing import Any, Self
|
|
7
7
|
|
|
8
8
|
from click.testing import CliRunner
|
|
9
9
|
|
|
@@ -17,8 +17,8 @@ class Utils(enum.Enum):
|
|
|
17
17
|
utils = None
|
|
18
18
|
|
|
19
19
|
@staticmethod
|
|
20
|
-
def get_data() -> dict:
|
|
21
|
-
data: dict
|
|
20
|
+
def get_data() -> dict[Any, Any]:
|
|
21
|
+
data: dict[Any, Any]
|
|
22
22
|
text: str
|
|
23
23
|
text = resources.read_text("preparse.tests", "expit.toml")
|
|
24
24
|
data = tomllib.loads(text)
|
|
@@ -45,7 +45,7 @@ class TestMainFunction(unittest.TestCase):
|
|
|
45
45
|
stdout: Any,
|
|
46
46
|
stderr: Any,
|
|
47
47
|
) -> None:
|
|
48
|
-
extra: dict
|
|
48
|
+
extra: dict[Any, Any]
|
|
49
49
|
result: Any
|
|
50
50
|
runner: CliRunner
|
|
51
51
|
runner = CliRunner()
|
|
@@ -65,8 +65,8 @@ class TestMainFunction(unittest.TestCase):
|
|
|
65
65
|
self.assertEqual(stderr, result.stderr)
|
|
66
66
|
|
|
67
67
|
def test_0(self: Self) -> None:
|
|
68
|
-
data: dict
|
|
69
|
-
kwargs: dict
|
|
68
|
+
data: dict[Any, Any]
|
|
69
|
+
kwargs: dict[Any, Any]
|
|
70
70
|
name: str
|
|
71
71
|
data = Utils.utils.get_data()
|
|
72
72
|
for name, kwargs in data.items():
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import unittest
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import Any, Self
|
|
3
3
|
|
|
4
4
|
from preparse.core.Click import Click
|
|
5
5
|
from preparse.core.enums import *
|
|
@@ -29,7 +29,7 @@ class TestPreParser(unittest.TestCase):
|
|
|
29
29
|
self.assertEqual(parser.optdict, parser_copy.optdict)
|
|
30
30
|
|
|
31
31
|
def test_preparser_todict(self: Self) -> None:
|
|
32
|
-
expected_keys: list
|
|
32
|
+
expected_keys: list[Any]
|
|
33
33
|
parser: PreParser
|
|
34
34
|
result: Any
|
|
35
35
|
parser = PreParser()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: preparse
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.4
|
|
4
4
|
Summary: This project preparses args for further parsing later on.
|
|
5
5
|
Author-email: Johannes <johannes.programming@gmail.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -21,10 +21,10 @@ License-File: LICENSE.txt
|
|
|
21
21
|
Requires-Dist: click<9,>=8.2
|
|
22
22
|
Requires-Dist: cmp3<2,>=1.0
|
|
23
23
|
Requires-Dist: copyable<2,>=1.1
|
|
24
|
-
Requires-Dist: datahold<4,>=3.0
|
|
24
|
+
Requires-Dist: datahold<4,>=3.0.34.dev1
|
|
25
25
|
Requires-Dist: datarepr<2,>=1.2
|
|
26
26
|
Requires-Dist: frozendict<3,>=2.4.7
|
|
27
|
-
Requires-Dist: setdoc<2,>=1.
|
|
27
|
+
Requires-Dist: setdoc<2,>=1.3
|
|
28
28
|
Requires-Dist: tofunc<2,>=1.1
|
|
29
29
|
Dynamic: license-file
|
|
30
30
|
|
|
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
|
|
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
|