preparse 1.0.18__tar.gz → 1.1.0__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.
Files changed (47) hide show
  1. {preparse-1.0.18 → preparse-1.1.0}/PKG-INFO +3 -3
  2. {preparse-1.0.18 → preparse-1.1.0}/docs/v1.0.rst +12 -12
  3. preparse-1.1.0/docs/v1.1.rst +312 -0
  4. {preparse-1.0.18 → preparse-1.1.0}/pyproject.toml +19 -3
  5. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_items/Bundle.py +27 -13
  6. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_items/Item.py +14 -9
  7. preparse-1.1.0/src/preparse/_items/Long.py +75 -0
  8. preparse-1.1.0/src/preparse/_items/Option.py +50 -0
  9. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_items/Positional.py +12 -7
  10. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_items/Special.py +10 -0
  11. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_processing/digesting.py +3 -3
  12. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_processing/parsing.py +6 -7
  13. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_processing/pulling.py +2 -1
  14. preparse-1.1.0/src/preparse/_tests/__init__.py +0 -0
  15. preparse-1.1.0/src/preparse/_tests/expit.py +27 -0
  16. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_utils/dataprop.py +2 -2
  17. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/core/Click.py +6 -11
  18. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/core/Optdict.py +1 -1
  19. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/core/PreParser.py +1 -12
  20. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/core/enums.py +3 -1
  21. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/core/warnings.py +30 -35
  22. preparse-1.1.0/src/preparse/py.typed +0 -0
  23. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/tests/data.toml +26 -0
  24. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/tests/test_data_toml.py +8 -3
  25. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/tests/test_expit_toml.py +12 -27
  26. {preparse-1.0.18 → preparse-1.1.0}/src/preparse.egg-info/PKG-INFO +3 -3
  27. {preparse-1.0.18 → preparse-1.1.0}/src/preparse.egg-info/SOURCES.txt +4 -0
  28. {preparse-1.0.18 → preparse-1.1.0}/src/preparse.egg-info/requires.txt +1 -2
  29. preparse-1.0.18/src/preparse/_items/Long.py +0 -57
  30. preparse-1.0.18/src/preparse/_items/Option.py +0 -37
  31. {preparse-1.0.18 → preparse-1.1.0}/LICENSE.txt +0 -0
  32. {preparse-1.0.18 → preparse-1.1.0}/MANIFEST.in +0 -0
  33. {preparse-1.0.18 → preparse-1.1.0}/README.rst +0 -0
  34. {preparse-1.0.18 → preparse-1.1.0}/setup.cfg +0 -0
  35. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/__init__.py +0 -0
  36. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_items/__init__.py +0 -0
  37. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_processing/__init__.py +0 -0
  38. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_processing/deparsing.py +0 -0
  39. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/_utils/__init__.py +0 -0
  40. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/core/__init__.py +0 -0
  41. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/tests/__init__.py +0 -0
  42. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/tests/expit.toml +0 -0
  43. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/tests/test_enums.py +0 -0
  44. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/tests/test_optdict.py +0 -0
  45. {preparse-1.0.18 → preparse-1.1.0}/src/preparse/tests/test_preparser.py +0 -0
  46. {preparse-1.0.18 → preparse-1.1.0}/src/preparse.egg-info/dependency_links.txt +0 -0
  47. {preparse-1.0.18 → preparse-1.1.0}/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.0.18
3
+ Version: 1.1.0
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
@@ -14,6 +14,7 @@ Classifier: Operating System :: OS Independent
14
14
  Classifier: Programming Language :: Python
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Typing :: Typed
17
18
  Requires-Python: >=3.11
18
19
  Description-Content-Type: text/x-rst
19
20
  License-File: LICENSE.txt
@@ -23,8 +24,7 @@ Requires-Dist: copyable<2,>=1.0
23
24
  Requires-Dist: datahold<4,>=3.0
24
25
  Requires-Dist: datarepr<2,>=1.1
25
26
  Requires-Dist: frozendict<3,>=2.4.7
26
- Requires-Dist: overloadable<2,>=1.1
27
- Requires-Dist: setdoc<2,>=1.2.10
27
+ Requires-Dist: setdoc<2,>=1.2.20
28
28
  Requires-Dist: tofunc<2,>=1.0
29
29
  Dynamic: license-file
30
30
 
@@ -4,14 +4,6 @@ Overview
4
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
- Links
8
- -----
9
-
10
- - Download: https://pypi.org/project/preparse/#files
11
- - Index: https://pypi.org/project/preparse/
12
- - Source: https://github.com/johannes-programming/preparse/
13
- - Website: https://preparse.johannes-programming.online/
14
-
15
7
  Installation
16
8
  ------------
17
9
 
@@ -277,21 +269,29 @@ This class warns about unallowed arguments. This can only happen for long option
277
269
  The Tests
278
270
  ~~~~~~~~~
279
271
 
280
- ``preparse.test() -> unittest.TextTestResult``
281
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
272
+ ``preparse.tests.test() -> unittest.TextTestResult``
273
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
282
274
 
283
275
  This project can be tested through its test function.
284
276
 
285
277
  .. code-block:: python
286
278
 
287
- import preparse
288
- preparse.test()
279
+ import preparse.tests
280
+ preparse.tests.test()
289
281
 
290
282
  License
291
283
  -------
292
284
 
293
285
  This project is licensed under the MIT License.
294
286
 
287
+ Links
288
+ -----
289
+
290
+ - Download: https://pypi.org/project/preparse/#files
291
+ - Index: https://pypi.org/project/preparse/
292
+ - Source: https://github.com/johannes-programming/preparse/
293
+ - Website: https://preparse.johannes-programming.online/
294
+
295
295
  Impressum
296
296
  ---------
297
297
 
@@ -0,0 +1,312 @@
1
+ Overview
2
+ --------
3
+
4
+ The preparse project allows to preparse arguments before the main parsing.
5
+ Its ability to deabbreviate options is especially useful for use with ``click``.
6
+
7
+ Installation
8
+ ------------
9
+
10
+ To install preparse, you can use pip. Open your terminal and run:
11
+
12
+ .. code-block:: shell
13
+
14
+ pip install preparse
15
+
16
+ Typing
17
+ ------
18
+
19
+ The typing conforms (not strictly) to ``mypy``.
20
+
21
+ .. container:: versionadded
22
+
23
+ **Added in version 1.1.**
24
+
25
+ Introduction
26
+ ------------
27
+
28
+ The preparse project allows for preprocessing a list of arguments so that they can be parsed definitively in a later step. This way, the functionality of another parsing system can be modified. The project is especially adapted to work with the click project.
29
+
30
+ The project preparse is strongly inspired by the getopt and getopt_long libraries within C.
31
+
32
+ Here is the implementation of the ``expit`` project (Version 1.0.13) to illustrate how preparse can be used to modify click.
33
+
34
+ .. code-block:: python
35
+
36
+ import math
37
+
38
+ import click
39
+ import preparse
40
+
41
+ __all__ = ["function", "main"]
42
+
43
+
44
+ def function(x: float) -> float:
45
+ "This function is the logistical sigmoid, i.e. the expit function."
46
+ try:
47
+ p = math.exp(-x)
48
+ except OverflowError:
49
+ p = float("+inf")
50
+ return 1 / (1 + p)
51
+
52
+
53
+ @preparse.PreParser().click()
54
+ @click.command(add_help_option=False)
55
+ @click.help_option("-h", "--help")
56
+ @click.version_option(None, "-V", "--version")
57
+ @click.argument("x", type=float)
58
+ def main(x: float) -> None:
59
+ "This command applies the expit function to x."
60
+ click.echo(function(x))
61
+
62
+ Features
63
+ --------
64
+
65
+ The PreParser class
66
+ ~~~~~~~~~~~~~~~~~~~
67
+
68
+ ``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
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70
+
71
+ This class is the centerpiece of the preparse. Its behaviour follows the principles of getopt from C.
72
+
73
+ ``allowslong: bool``
74
+ """"""""""""""""""""
75
+
76
+ This boolean property determines whether long options are allowed.
77
+
78
+ ``allowsshort: bool``
79
+ """""""""""""""""""""
80
+
81
+ This boolean property determines whether short options are allowed.
82
+
83
+ ``bundling: preparse.Tuning``
84
+ """""""""""""""""""""""""""""
85
+
86
+ This ``preparse.Tuning`` property determines the approach to bundling of short option.
87
+
88
+ ``click(cmd: Any = True, ctx: Any = True) -> preparse.Click``
89
+ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
90
+
91
+ This method returns a decorator that infuses the current instance into ``parse_args``.
92
+
93
+ ``copy() -> Self``
94
+ """"""""""""""""""
95
+
96
+ This method returns a copy of the current instance.
97
+
98
+ ``expandsabbr: bool``
99
+ """""""""""""""""""""
100
+
101
+ This boolean property determines whether recognized abbreviations of long options are to be expanded to their full length.
102
+
103
+ ``expectsabbr: bool``
104
+ """""""""""""""""""""
105
+
106
+ This boolean property determines whether abbreviations of long options are expected.
107
+
108
+ ``expectsposix: bool``
109
+ """"""""""""""""""""""
110
+
111
+ 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.
112
+
113
+ ``optdict: preparse.Optdict``
114
+ """""""""""""""""""""""""""""
115
+
116
+ This property holds a dict-like object.
117
+ Its keys are the options.
118
+ Its values specify ``preparse.Nargs``.
119
+ Options not found within the dictionary
120
+ cause a ``preparse.PreparseInvalidOptionWarning``
121
+ and are then assumed to have no arguments.
122
+
123
+ ``parse_args(args: Optional[Iterable] = None) -> list[str]``
124
+ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
125
+
126
+ This method is at the core of the class.
127
+ It returns a preparsed list of arguments.
128
+ If ``None`` is passed as args then ``sys.argv[1:]`` is used.
129
+ If the method is applied repeatedly to a list there will be no changes after the first run.
130
+
131
+ ``prog: str``
132
+ """""""""""""
133
+
134
+ This ``str`` property represents the name of the program.
135
+ If the value passed to the property is ``None`` then ``str(sys.argv[0])`` is saved.
136
+
137
+ ``reconcilesorders: bool``
138
+ """"""""""""""""""""""""""
139
+
140
+ This boolean property determines whether compatibility with both orders,
141
+ POSIX and the interleaving of options with positonal arguments, should be enforced.
142
+
143
+ ``reflectClickCommand(cmd: click.Command) -> None``
144
+ """""""""""""""""""""""""""""""""""""""""""""""""""
145
+
146
+ This method alters the current instance to reflect a ``click.Command`` object.
147
+ Concretely the optdict property is changed.
148
+
149
+ ``reflectClickContext(ctx: click.Context) -> None``
150
+ """""""""""""""""""""""""""""""""""""""""""""""""""
151
+
152
+ This method alters the current instance to reflect a ``click.Context`` object.
153
+ Concretely the prog property is changed.
154
+
155
+ ``special: preparse.Tuning``
156
+ """"""""""""""""""""""""""""
157
+
158
+ This ``preparse.Tuning`` property determines the approach to the special argument ``'--'``.
159
+
160
+ ``todict() -> dict``
161
+ """"""""""""""""""""
162
+
163
+ This method a dict representing the current instance.
164
+
165
+ ``warn: types.FunctionType``
166
+ """"""""""""""""""""""""""""
167
+
168
+ This property holds a function that is called whenever ``parse_args`` encounters a warning.
169
+ The warning is given as the only positional arguments.
170
+ No keyword arguments are given.
171
+ Its return value is discarded.
172
+ Therefore, ``str`` is used to discard the warnings.
173
+
174
+ The Click class
175
+ ~~~~~~~~~~~~~~~
176
+
177
+ ``class preparse.Click(parser: preparse.PreParser, cmd: Any = True, ctx: Any = True)``
178
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
179
+
180
+ This dataclass provides decorators for embedding a ``PreParser`` object.
181
+
182
+ ``__call__(target: Any) -> Any``
183
+ """"""""""""""""""""""""""""""""
184
+
185
+ This magic method implements ``self(target)``.
186
+ It works as a decorator that embeds its parser into a given target from the library click.
187
+
188
+ ``cmd: Any``
189
+ """"""""""""
190
+
191
+ This property determines if the ``reflectClickCommand`` method of parser is to be called.
192
+
193
+ ``copy() -> Self``
194
+ """"""""""""""""""
195
+
196
+ ``ctx: Any``
197
+ """"""""""""
198
+
199
+ This property determines if the ``reflectClickContext`` method of parser is to be called.
200
+
201
+ ``parser: preparse.PreParser``
202
+ """"""""""""""""""""""""""""""
203
+
204
+ This property holds the parser to be embedded.
205
+
206
+ The Optdict class
207
+ ~~~~~~~~~~~~~~~~~
208
+
209
+ ``class preparse.Optdict``
210
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
211
+
212
+ This class is a subclass of ``datahold.HoldDict[str, preparse.Nargs]``
213
+ with strings as keys and with ``preparse.Nargs`` as values.
214
+ It is designed for ``preparse.PreParser.optdict``.
215
+
216
+ The Enums
217
+ ~~~~~~~~~
218
+
219
+ These classes are subclasses of ``enum.IntEnum``.
220
+ Any value different from ``0`` (meaning no) and ``1`` (meaning yes) is interpreted as ``2`` (meaning intermediate).
221
+
222
+ ``class preparse.Tuning``
223
+ ^^^^^^^^^^^^^^^^^^^^^^^^^
224
+
225
+ +--------------+-------+-----------------------------------------------------------------------------+
226
+ | Name | Value | Explanation |
227
+ +==============+=======+=============================================================================+
228
+ | ``MINIMIZE`` | ``0`` | The PreParser minimizes the aspect in question. |
229
+ +--------------+-------+-----------------------------------------------------------------------------+
230
+ | ``MAXIMIZE`` | ``1`` | The PreParser maximizes the aspect in question. |
231
+ +--------------+-------+-----------------------------------------------------------------------------+
232
+ | ``MAINTAIN`` | ``2`` | The PreParser does not make any unforced changes to the aspect in question. |
233
+ +--------------+-------+-----------------------------------------------------------------------------+
234
+
235
+ ``class preparse.Nargs``
236
+ ^^^^^^^^^^^^^^^^^^^^^^^^
237
+
238
+ +-------------------+-------+----------------------------------------------+
239
+ | Name | Value | Explanation |
240
+ +===================+=======+==============================================+
241
+ | NO_ARGUMENT | ``0`` | The option does not take an argument. |
242
+ +-------------------+-------+----------------------------------------------+
243
+ | REQUIRED_ARGUMENT | ``1`` | The option requires an argument. |
244
+ +-------------------+-------+----------------------------------------------+
245
+ | OPTIONAL_ARGUMENT | ``2`` | The option may take an argument. |
246
+ +-------------------+-------+----------------------------------------------+
247
+
248
+ The Warnings
249
+ ~~~~~~~~~~~~
250
+
251
+ These classes are subclasses of ``Warning`` that are specifically designed to communicate issues with parsing.
252
+
253
+ ``class preparse.PreparseWarning``
254
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
255
+
256
+ This abstract base class is the base for all other warning types.
257
+
258
+ ``class preparse.PreparseAmbiguousOptionWarning(prog: Any, option: Any, possibilities: Any)``
259
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
260
+
261
+ This class warns about ambiguous options. This can only happen for long options.
262
+
263
+ ``class preparse.PreparseInvalidOptionWarning(prog: Any, option: Any, islong: Any)``
264
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
265
+
266
+ This class warns about invalid options.
267
+
268
+ ``class preparse.PreparseRequiredArgumentWarning(prog: Any, option: Any, islong: Any)``
269
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
270
+
271
+ This class warns about missing required arguments.
272
+
273
+ ``class preparse.PreparseUnallowedArgumentWarning(prog: Any, option: Any)``
274
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
275
+
276
+ This class warns about unallowed arguments. This can only happen for long options.
277
+
278
+ The Tests
279
+ ~~~~~~~~~
280
+
281
+ ``preparse.tests.test() -> unittest.TextTestResult``
282
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
283
+
284
+ This project can be tested through its test function.
285
+
286
+ .. code-block:: python
287
+
288
+ import preparse.tests
289
+ preparse.tests.test()
290
+
291
+ License
292
+ -------
293
+
294
+ This project is licensed under the MIT License.
295
+
296
+ Links
297
+ -----
298
+
299
+ - Download: https://pypi.org/project/preparse/#files
300
+ - Index: https://pypi.org/project/preparse/
301
+ - Source: https://github.com/johannes-programming/preparse/
302
+ - Website: https://preparse.johannes-programming.online/
303
+
304
+ Impressum
305
+ ---------
306
+
307
+ **Johannes Programming**
308
+
309
+ - Name: Johannes
310
+ - Email: johannes.programming@gmail.com
311
+ - Homepage: https://www.johannes-programming.online/
312
+ - Gravatar: https://www.johannes-programming.fyi/
@@ -15,6 +15,7 @@ classifiers = [
15
15
  "Programming Language :: Python",
16
16
  "Programming Language :: Python :: 3",
17
17
  "Programming Language :: Python :: 3 :: Only",
18
+ "Typing :: Typed",
18
19
  ]
19
20
  dependencies = [
20
21
  "click>=8.2,<9",
@@ -23,8 +24,7 @@ dependencies = [
23
24
  "datahold>=3.0,<4",
24
25
  "datarepr>=1.1,<2",
25
26
  "frozendict>=2.4.7,<3",
26
- "overloadable>=1.1,<2",
27
- "setdoc>=1.2.10,<2",
27
+ "setdoc>=1.2.20,<2",
28
28
  "tofunc>=1.0,<2",
29
29
  ]
30
30
  description = "This project preparses args for further parsing later on."
@@ -36,10 +36,26 @@ license-files = [
36
36
  name = "preparse"
37
37
  readme = "README.rst"
38
38
  requires-python = ">=3.11"
39
- version = "1.0.18"
39
+ version = "1.1.0"
40
40
 
41
41
  [project.urls]
42
42
  Download = "https://pypi.org/project/preparse/#files"
43
43
  Index = "https://pypi.org/project/preparse/"
44
44
  Source = "https://github.com/johannes-programming/preparse/"
45
45
  Website = "https://preparse.johannes-programming.online/"
46
+
47
+ [tool.mypy]
48
+ files = [
49
+ ".",
50
+ ]
51
+ python_version = "3.11"
52
+ strict = false
53
+
54
+ [[tool.mypy.overrides]]
55
+ module = [
56
+ "cmp3",
57
+ "cmp3.*",
58
+ "datahold",
59
+ "datahold.*",
60
+ ]
61
+ ignore_missing_imports = true
@@ -4,7 +4,6 @@ import setdoc
4
4
 
5
5
  from preparse._items.Item import Item
6
6
  from preparse._items.Option import Option
7
- from preparse._utils.dataprop import dataprop
8
7
  from preparse.core.enums import *
9
8
 
10
9
  __all__ = ["Bundle"]
@@ -12,23 +11,25 @@ __all__ = ["Bundle"]
12
11
 
13
12
  class Bundle(Option):
14
13
 
15
- chars: str
16
- joined: bool
17
- nargs: Nargs
18
- right: Optional[str]
19
-
20
- __slots__ = ()
14
+ __slots__ = (
15
+ "_chars",
16
+ "_joined",
17
+ "_nargs",
18
+ "_right",
19
+ )
21
20
 
22
21
  @setdoc.basic
23
22
  def __init__(
24
23
  self: Self,
25
24
  *,
26
25
  chars: str,
26
+ nargs: Any,
27
27
  joined: bool = False,
28
28
  right: Optional[str] = None,
29
29
  ) -> None:
30
30
  self.chars = chars
31
31
  self.joined = joined
32
+ self.nargs = nargs
32
33
  self.right = right
33
34
 
34
35
  @classmethod
@@ -38,7 +39,7 @@ class Bundle(Option):
38
39
  ans = list()
39
40
  for x in chars:
40
41
  if x == "-":
41
- ans[-1].chars += "-"
42
+ ans[-1] += "-"
42
43
  else:
43
44
  ans.append(x)
44
45
  return ans
@@ -61,9 +62,13 @@ class Bundle(Option):
61
62
  x = x[:-1]
62
63
  return ans
63
64
 
64
- @dataprop
65
- def chars(self: Self, x: Any) -> str:
66
- return str(x)
65
+ @property
66
+ def chars(self: Self) -> str:
67
+ return self._chars
68
+
69
+ @chars.setter
70
+ def chars(self: Self, x: Any) -> None:
71
+ self._chars = str(x)
67
72
 
68
73
  def deparse(self: Self) -> list[str]:
69
74
  if self.right is None:
@@ -73,7 +78,16 @@ class Bundle(Option):
73
78
  else:
74
79
  return ["-" + self.chars, self.right]
75
80
 
76
- def split(self: Self, *, allowslong: bool) -> list[Item]:
81
+ @classmethod
82
+ def getslotnames(cls: type[Self]) -> tuple[str, ...]:
83
+ return (
84
+ "_chars",
85
+ "_joined",
86
+ "_nargs",
87
+ "_right",
88
+ )
89
+
90
+ def split(self: Self, *, allowslong: bool) -> list[Self]:
77
91
  ans: list[Self]
78
92
  parts: list[str]
79
93
  x: str
@@ -83,7 +97,7 @@ class Bundle(Option):
83
97
  parts = self._split_shortonly(self.chars)
84
98
  ans = list()
85
99
  for x in parts:
86
- ans.append(Bundle(chars=x))
100
+ ans.append(type(self)(chars=x, nargs=Nargs.NO_ARGUMENT))
87
101
  self.chars = ans[-1].chars
88
102
  ans[-1] = self
89
103
  return ans
@@ -10,7 +10,11 @@ __all__ = ["Item"]
10
10
 
11
11
 
12
12
  class Item(Copyable):
13
- __slots__ = ("_data",)
13
+ __slots__ = ()
14
+
15
+ @abc.abstractmethod
16
+ @setdoc.basic
17
+ def __init__(self: Self, *args: Any, **kwargs: Any) -> None: ...
14
18
 
15
19
  @setdoc.basic
16
20
  def copy(self: Self) -> Self:
@@ -19,18 +23,19 @@ class Item(Copyable):
19
23
  @abc.abstractmethod
20
24
  def deparse(self: Self) -> list[str]: ...
21
25
 
26
+ @classmethod
27
+ @abc.abstractmethod
28
+ def getslotnames(cls: type[Self]) -> tuple[str, ...]: ...
29
+
22
30
  @classmethod
23
31
  @abc.abstractmethod
24
32
  def sortkey(cls: type) -> int: ...
25
33
 
26
34
  def todict(self: Self) -> dict:
27
35
  "This method returns a dict representing the current instance."
28
- ans: dict
29
- try:
30
- ans = self._data
31
- except AttributeError:
32
- self._data = dict()
33
- ans = dict()
34
- else:
35
- ans = dict(ans)
36
+ ans: dict[str, Any]
37
+ x: str
38
+ ans = dict()
39
+ for x in self.getslotnames():
40
+ ans[x] = getattr(self, x)
36
41
  return ans
@@ -0,0 +1,75 @@
1
+ import operator
2
+ from typing import *
3
+
4
+ import setdoc
5
+
6
+ from preparse._items.Option import Option
7
+ from preparse.core.enums import *
8
+
9
+ __all__ = ["Long"]
10
+
11
+
12
+ class Long(Option):
13
+
14
+ __slots__ = (
15
+ "_nargs",
16
+ "_joined",
17
+ "_right",
18
+ "_abbrlen",
19
+ "_fullkey",
20
+ )
21
+
22
+ @setdoc.basic
23
+ def __init__(
24
+ self: Self,
25
+ *,
26
+ fullkey: str,
27
+ abbrlen: Optional[int] = None,
28
+ joined: bool = False,
29
+ right: Optional[str] = None,
30
+ ) -> None:
31
+ self.fullkey = fullkey
32
+ self.abbrlen = abbrlen
33
+ self.joined = joined
34
+ self.right = right
35
+
36
+ @property
37
+ def abbr(self: Self) -> str:
38
+ return self.fullkey[: self.abbrlen]
39
+
40
+ @property
41
+ def abbrlen(self: Self) -> Optional[int]:
42
+ return self._abbrlen
43
+
44
+ @abbrlen.setter
45
+ def abbrlen(self: Self, x: Optional[SupportsIndex]) -> None:
46
+ if x is None:
47
+ self._abbrlen = None
48
+ else:
49
+ self._abbrlen = operator.index(x)
50
+
51
+ def deparse(self: Self) -> list[str]:
52
+ if self.right is None:
53
+ return [self.abbr]
54
+ elif self.joined:
55
+ return [self.abbr + "=" + self.right]
56
+ else:
57
+ return [self.abbr, self.right]
58
+
59
+ @property
60
+ def fullkey(self: Self) -> str:
61
+ return self._fullkey
62
+
63
+ @fullkey.setter
64
+ def fullkey(self: Self, x: Any) -> None:
65
+ self._fullkey = str(x)
66
+
67
+ @classmethod
68
+ def getslotnames(cls: type[Self]) -> tuple[str, ...]:
69
+ return (
70
+ "_nargs",
71
+ "_joined",
72
+ "_right",
73
+ "_abbrlen",
74
+ "_fullkey",
75
+ )
@@ -0,0 +1,50 @@
1
+ import operator
2
+ from typing import *
3
+
4
+ from preparse._items.Item import Item
5
+ from preparse.core.enums import *
6
+
7
+ __all__ = ["Option"]
8
+
9
+
10
+ class Option(Item):
11
+
12
+ __slots__ = ()
13
+
14
+ _joined: Any
15
+ _nargs: Any
16
+ _right: Any
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._joined
24
+
25
+ @joined.setter
26
+ def joined(self: Self, x: SupportsIndex) -> None:
27
+ self._joined = bool(operator.index(x))
28
+
29
+ @property
30
+ def nargs(self: Self) -> Nargs:
31
+ return self._nargs
32
+
33
+ @nargs.setter
34
+ def nargs(self: Self, x: Any) -> None:
35
+ self._nargs = Nargs(x)
36
+
37
+ @property
38
+ def right(self: Self) -> Optional[str]:
39
+ return self._right
40
+
41
+ @right.setter
42
+ def right(self: Self, x: Any) -> None:
43
+ if x is None:
44
+ self._right = None
45
+ else:
46
+ self._right = str(x)
47
+
48
+ @classmethod
49
+ def sortkey(cls: type) -> int:
50
+ return 0