typedparser 0.20.2__tar.gz → 0.21.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typedparser
3
- Version: 0.20.2
3
+ Version: 0.21.2
4
4
  Summary: Extension for python argparse with typehints and typechecks.
5
5
  Author: simon-ging
6
6
  License: Apache-2.0
@@ -11,7 +11,6 @@ Classifier: Development Status :: 3 - Alpha
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Natural Language :: English
14
- Classifier: Programming Language :: Python :: 3.7
15
14
  Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
@@ -19,21 +18,16 @@ Classifier: Programming Language :: Python :: 3.11
19
18
  Classifier: Programming Language :: Python :: 3.12
20
19
  Classifier: Operating System :: OS Independent
21
20
  Classifier: Topic :: Software Development :: Version Control :: Git
22
- Requires-Python: >=3.7
21
+ Requires-Python: >=3.8
23
22
  Description-Content-Type: text/markdown
24
23
  License-File: LICENSE
25
24
  Requires-Dist: attrs
26
- Requires-Dist: importlib_metadata; python_version < "3.8"
27
- Requires-Dist: typing_extensions; python_version < "3.8"
28
25
  Provides-Extra: full
29
26
  Requires-Dist: numpy; extra == "full"
30
27
 
31
28
  # typedparser
32
29
 
33
30
  <p align="center">
34
- <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py37.yml">
35
- <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py37.yml?branch=main&label=python%203.7" />
36
- </a>
37
31
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py38.yml">
38
32
  <img alt="build 3.8 status" title="build 3.8 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py38.yml?branch=main&label=python%203.8" />
39
33
  </a>
@@ -49,9 +43,6 @@ Requires-Dist: numpy; extra == "full"
49
43
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py312.yml">
50
44
  <img alt="build 3.12 status" title="build 3.12 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py312.yml?branch=main&label=python%203.12" />
51
45
  </a>
52
- <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py37-full.yml">
53
- <img alt="build 3.7 full status" title="build 3.7 full status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py37-full.yml?branch=main&label=python%203.7%20full" />
54
- </a>
55
46
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py312-full.yml">
56
47
  <img alt="build 3.12 full status" title="build 3.12 full status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py312-full.yml?branch=main&label=python%203.12%20full" />
57
48
  </a>
@@ -67,7 +58,7 @@ Includes typechecking and conversion utilities to parse a dictionary into an att
67
58
 
68
59
  ## Install
69
60
 
70
- Requires `python>=3.7`
61
+ Requires `python>=3.8`
71
62
 
72
63
  ```bash
73
64
  pip install typedparser
@@ -79,7 +70,7 @@ pip install typedparser
79
70
  2. Define and type the fields with `typedparser.add_argument` - the syntax extends [add_argument from argparse](https://docs.python.org/3/library/argparse.html#the-add-argument-method).
80
71
  3. Parse the args with `TypedParser` and enjoy args with type hints. Disable typechecking by setting `strict=False`.
81
72
 
82
- ~~~python
73
+ ```python
83
74
  from typing import Optional
84
75
  from attrs import define
85
76
  from typedparser import add_argument, TypedParser
@@ -108,8 +99,7 @@ def main():
108
99
  if __name__ == "__main__":
109
100
  main()
110
101
 
111
- ~~~
112
-
102
+ ```
113
103
 
114
104
  ## Features
115
105
 
@@ -139,7 +129,7 @@ use as `-x 1 -x 2` to get `[1, 2]` in the args instance.
139
129
  Define the class hierarchy and parse the input using `attrs_from_dict`.
140
130
  Use `@define(slots=False)` to allow multiple inheritance and setting attributes later.
141
131
 
142
- ~~~python
132
+ ```python
143
133
  from attrs import define
144
134
  from typing import Optional
145
135
  from typedparser import attrs_from_dict
@@ -159,8 +149,7 @@ class CfgNested:
159
149
 
160
150
  print(attrs_from_dict(CfgNested, {"sub_cfg": {"foo": 1, "bar": 2}}))
161
151
  # CfgNested(sub_cfg=Cfg(foo=1, bar=2))
162
- ~~~
163
-
152
+ ```
164
153
 
165
154
  ### Strict mode (default)
166
155
 
@@ -198,7 +187,7 @@ The following behaviour stems from the `attrs` package:
198
187
  Clone repository and cd into. Setup python 3.7 or higher.
199
188
  Note: Some tests are skipped for python 3.7.
200
189
 
201
- ~~~bash
190
+ ```bash
202
191
  pip install -e .
203
192
  pip install pytest pytest-cov pylint
204
193
  pylint typedparser
@@ -206,4 +195,4 @@ pylint typedparser
206
195
  # run tests
207
196
  python -m pytest --cov
208
197
  pylint tests
209
- ~~~
198
+ ```
@@ -1,9 +1,6 @@
1
1
  # typedparser
2
2
 
3
3
  <p align="center">
4
- <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py37.yml">
5
- <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py37.yml?branch=main&label=python%203.7" />
6
- </a>
7
4
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py38.yml">
8
5
  <img alt="build 3.8 status" title="build 3.8 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py38.yml?branch=main&label=python%203.8" />
9
6
  </a>
@@ -19,9 +16,6 @@
19
16
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py312.yml">
20
17
  <img alt="build 3.12 status" title="build 3.12 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py312.yml?branch=main&label=python%203.12" />
21
18
  </a>
22
- <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py37-full.yml">
23
- <img alt="build 3.7 full status" title="build 3.7 full status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py37-full.yml?branch=main&label=python%203.7%20full" />
24
- </a>
25
19
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py312-full.yml">
26
20
  <img alt="build 3.12 full status" title="build 3.12 full status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py312-full.yml?branch=main&label=python%203.12%20full" />
27
21
  </a>
@@ -37,7 +31,7 @@ Includes typechecking and conversion utilities to parse a dictionary into an att
37
31
 
38
32
  ## Install
39
33
 
40
- Requires `python>=3.7`
34
+ Requires `python>=3.8`
41
35
 
42
36
  ```bash
43
37
  pip install typedparser
@@ -49,7 +43,7 @@ pip install typedparser
49
43
  2. Define and type the fields with `typedparser.add_argument` - the syntax extends [add_argument from argparse](https://docs.python.org/3/library/argparse.html#the-add-argument-method).
50
44
  3. Parse the args with `TypedParser` and enjoy args with type hints. Disable typechecking by setting `strict=False`.
51
45
 
52
- ~~~python
46
+ ```python
53
47
  from typing import Optional
54
48
  from attrs import define
55
49
  from typedparser import add_argument, TypedParser
@@ -78,8 +72,7 @@ def main():
78
72
  if __name__ == "__main__":
79
73
  main()
80
74
 
81
- ~~~
82
-
75
+ ```
83
76
 
84
77
  ## Features
85
78
 
@@ -109,7 +102,7 @@ use as `-x 1 -x 2` to get `[1, 2]` in the args instance.
109
102
  Define the class hierarchy and parse the input using `attrs_from_dict`.
110
103
  Use `@define(slots=False)` to allow multiple inheritance and setting attributes later.
111
104
 
112
- ~~~python
105
+ ```python
113
106
  from attrs import define
114
107
  from typing import Optional
115
108
  from typedparser import attrs_from_dict
@@ -129,8 +122,7 @@ class CfgNested:
129
122
 
130
123
  print(attrs_from_dict(CfgNested, {"sub_cfg": {"foo": 1, "bar": 2}}))
131
124
  # CfgNested(sub_cfg=Cfg(foo=1, bar=2))
132
- ~~~
133
-
125
+ ```
134
126
 
135
127
  ### Strict mode (default)
136
128
 
@@ -168,7 +160,7 @@ The following behaviour stems from the `attrs` package:
168
160
  Clone repository and cd into. Setup python 3.7 or higher.
169
161
  Note: Some tests are skipped for python 3.7.
170
162
 
171
- ~~~bash
163
+ ```bash
172
164
  pip install -e .
173
165
  pip install pytest pytest-cov pylint
174
166
  pylint typedparser
@@ -176,4 +168,4 @@ pylint typedparser
176
168
  # run tests
177
169
  python -m pytest --cov
178
170
  pylint tests
179
- ~~~
171
+ ```
@@ -7,7 +7,7 @@ name = "typedparser"
7
7
  description = "Extension for python argparse with typehints and typechecks."
8
8
  readme = "README.md"
9
9
  authors = [{ "name" = "simon-ging" }]
10
- requires-python = ">=3.7"
10
+ requires-python = ">=3.8"
11
11
  license = { text = "Apache-2.0" }
12
12
  keywords = ["attrs", "typing", "dict", "attr"]
13
13
  classifiers = [
@@ -15,7 +15,6 @@ classifiers = [
15
15
  "Intended Audience :: Developers",
16
16
  "License :: OSI Approved :: Apache Software License",
17
17
  "Natural Language :: English",
18
- "Programming Language :: Python :: 3.7",
19
18
  "Programming Language :: Python :: 3.8",
20
19
  "Programming Language :: Python :: 3.9",
21
20
  "Programming Language :: Python :: 3.10",
@@ -75,6 +74,7 @@ disable = [
75
74
  'disallowed-name', 'redefined-outer-name', 'use-implicit-booleaness-not-comparison-to-zero',
76
75
  'eval-used', 'unknown-option-value', 'arguments-differ', 'subprocess-run-check',
77
76
  'use-implicit-booleaness-not-comparison-to-string', 'use-dict-literal',
77
+ 'useless-suppression', 'too-many-positional-arguments', 'use-symbolic-message-instead',
78
78
  ]
79
79
 
80
80
  [tool.pylint.format]
@@ -0,0 +1 @@
1
+ attrs
@@ -1,5 +1,12 @@
1
1
  from ._typedattr import definenumpy, attrs_from_dict, NamedTupleMixin
2
- from ._typedparser import add_argument, TypedParser, VerboseQuietArgs
2
+ from ._typedparser import (
3
+ add_argument,
4
+ TypedParser,
5
+ VerboseQuietArgs,
6
+ TaskSplitterArgs,
7
+ split_list_given_task_splitter_args,
8
+ split_list_for_processing,
9
+ )
3
10
  from .custom_format import CustomArgparseFmt
4
11
  from .objects import get_attr_names
5
12
 
@@ -12,6 +19,10 @@ __all__ = [
12
19
  "VerboseQuietArgs",
13
20
  "CustomArgparseFmt",
14
21
  "get_attr_names",
22
+ "TaskSplitterArgs",
23
+ "split_list_given_task_splitter_args",
24
+ "split_list_for_processing",
15
25
  ]
16
26
 
17
- __version__ = "0.20.2"
27
+
28
+ __version__ = "0.21.2"
@@ -31,13 +31,7 @@ try:
31
31
  except ImportError:
32
32
  UnionType = None
33
33
 
34
- try:
35
- # python>=3.8
36
- from typing import get_origin, get_args
37
- except ImportError:
38
- # python<3.8
39
- # note that attrs automatically installs this and importlib-metadata for old python versions
40
- from typing_extensions import get_origin, get_args
34
+ from typing import get_origin, get_args
41
35
 
42
36
  # default conversions allow to convert instead of raising errors in case of matching types
43
37
  # e.g. create Path given str, or create float given int
@@ -1,11 +1,10 @@
1
1
  # from __future__ import annotations # do not use here, it breaks everything
2
2
 
3
3
  import argparse
4
+ from attr import field, define
4
5
  from dataclasses import dataclass
5
6
  from typing import Optional, Type, Any
6
7
 
7
- from attr import field, define
8
-
9
8
  from ._typedattr import AttrsClass
10
9
  from .custom_format import CustomArgparseFmt
11
10
  from .funcs import parse_typed_args, add_typed_args
@@ -104,3 +103,30 @@ def add_argument(
104
103
  class VerboseQuietArgs:
105
104
  verbose: bool = add_argument(shortcut="-v", help="Increase verbosity", action="store_true")
106
105
  quiet: bool = add_argument(shortcut="-q", help="Reduce verbosity", action="store_true")
106
+
107
+
108
+ @define(slots=False) # slots false to allow multi inheritance
109
+ class TaskSplitterArgs:
110
+ start: int = add_argument(shortcut="-s", type=int, default=0, help="Where to start processing")
111
+ num: Optional[int] = add_argument(shortcut="-n", type=int, help="Number of tasks to process.")
112
+
113
+
114
+ def split_list_given_task_splitter_args(
115
+ in_list, task_splitter_args: TaskSplitterArgs, print_fn=None
116
+ ):
117
+ start, num = task_splitter_args.start, task_splitter_args.num
118
+ return split_list_for_processing(in_list, start, num, print_fn=print_fn)
119
+
120
+
121
+ def split_list_for_processing(in_list, start: int = 0, num: Optional[int] = None, print_fn=None):
122
+ len_in_list = len(in_list)
123
+ if start > 0:
124
+ in_list = in_list[start:]
125
+ if num is not None:
126
+ in_list = in_list[:num]
127
+ if print_fn is not None:
128
+ print_fn(
129
+ f"Split list for processing, input length {len_in_list}, starting at {start}, "
130
+ f"processing max {num} reduced to {len(in_list)}"
131
+ )
132
+ return in_list
@@ -2,7 +2,7 @@ import argparse
2
2
  from typing import Any, Dict
3
3
 
4
4
  from attr import AttrsInstance
5
- from attrs import has, fields_dict, asdict
5
+ from attrs import has, fields_dict
6
6
 
7
7
  from ._typedattr import attrs_from_dict
8
8
  from .objects import get_attr_names
@@ -1,16 +1,18 @@
1
1
  """
2
2
  Generic utilities for python objects
3
3
  """
4
+
4
5
  from __future__ import annotations
5
6
 
6
7
  from abc import ABCMeta, abstractmethod
7
- from attr import has, AttrsInstance
8
- from attrs import fields
9
8
  from collections.abc import Mapping, Iterable
10
9
  from copy import deepcopy
11
10
  from functools import partial
12
11
  from typing import Any, Callable, Type, List
13
12
 
13
+ from attr import has, AttrsInstance
14
+ from attrs import fields
15
+
14
16
  AttrsClass = Type[AttrsInstance]
15
17
 
16
18
  try:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typedparser
3
- Version: 0.20.2
3
+ Version: 0.21.2
4
4
  Summary: Extension for python argparse with typehints and typechecks.
5
5
  Author: simon-ging
6
6
  License: Apache-2.0
@@ -11,7 +11,6 @@ Classifier: Development Status :: 3 - Alpha
11
11
  Classifier: Intended Audience :: Developers
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Natural Language :: English
14
- Classifier: Programming Language :: Python :: 3.7
15
14
  Classifier: Programming Language :: Python :: 3.8
16
15
  Classifier: Programming Language :: Python :: 3.9
17
16
  Classifier: Programming Language :: Python :: 3.10
@@ -19,21 +18,16 @@ Classifier: Programming Language :: Python :: 3.11
19
18
  Classifier: Programming Language :: Python :: 3.12
20
19
  Classifier: Operating System :: OS Independent
21
20
  Classifier: Topic :: Software Development :: Version Control :: Git
22
- Requires-Python: >=3.7
21
+ Requires-Python: >=3.8
23
22
  Description-Content-Type: text/markdown
24
23
  License-File: LICENSE
25
24
  Requires-Dist: attrs
26
- Requires-Dist: importlib_metadata; python_version < "3.8"
27
- Requires-Dist: typing_extensions; python_version < "3.8"
28
25
  Provides-Extra: full
29
26
  Requires-Dist: numpy; extra == "full"
30
27
 
31
28
  # typedparser
32
29
 
33
30
  <p align="center">
34
- <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py37.yml">
35
- <img alt="build 3.7 status" title="build 3.7 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py37.yml?branch=main&label=python%203.7" />
36
- </a>
37
31
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py38.yml">
38
32
  <img alt="build 3.8 status" title="build 3.8 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py38.yml?branch=main&label=python%203.8" />
39
33
  </a>
@@ -49,9 +43,6 @@ Requires-Dist: numpy; extra == "full"
49
43
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py312.yml">
50
44
  <img alt="build 3.12 status" title="build 3.12 status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py312.yml?branch=main&label=python%203.12" />
51
45
  </a>
52
- <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py37-full.yml">
53
- <img alt="build 3.7 full status" title="build 3.7 full status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py37-full.yml?branch=main&label=python%203.7%20full" />
54
- </a>
55
46
  <a href="https://github.com/simon-ging/typedparser/actions/workflows/build-py312-full.yml">
56
47
  <img alt="build 3.12 full status" title="build 3.12 full status" src="https://img.shields.io/github/actions/workflow/status/simon-ging/typedparser/build-py312-full.yml?branch=main&label=python%203.12%20full" />
57
48
  </a>
@@ -67,7 +58,7 @@ Includes typechecking and conversion utilities to parse a dictionary into an att
67
58
 
68
59
  ## Install
69
60
 
70
- Requires `python>=3.7`
61
+ Requires `python>=3.8`
71
62
 
72
63
  ```bash
73
64
  pip install typedparser
@@ -79,7 +70,7 @@ pip install typedparser
79
70
  2. Define and type the fields with `typedparser.add_argument` - the syntax extends [add_argument from argparse](https://docs.python.org/3/library/argparse.html#the-add-argument-method).
80
71
  3. Parse the args with `TypedParser` and enjoy args with type hints. Disable typechecking by setting `strict=False`.
81
72
 
82
- ~~~python
73
+ ```python
83
74
  from typing import Optional
84
75
  from attrs import define
85
76
  from typedparser import add_argument, TypedParser
@@ -108,8 +99,7 @@ def main():
108
99
  if __name__ == "__main__":
109
100
  main()
110
101
 
111
- ~~~
112
-
102
+ ```
113
103
 
114
104
  ## Features
115
105
 
@@ -139,7 +129,7 @@ use as `-x 1 -x 2` to get `[1, 2]` in the args instance.
139
129
  Define the class hierarchy and parse the input using `attrs_from_dict`.
140
130
  Use `@define(slots=False)` to allow multiple inheritance and setting attributes later.
141
131
 
142
- ~~~python
132
+ ```python
143
133
  from attrs import define
144
134
  from typing import Optional
145
135
  from typedparser import attrs_from_dict
@@ -159,8 +149,7 @@ class CfgNested:
159
149
 
160
150
  print(attrs_from_dict(CfgNested, {"sub_cfg": {"foo": 1, "bar": 2}}))
161
151
  # CfgNested(sub_cfg=Cfg(foo=1, bar=2))
162
- ~~~
163
-
152
+ ```
164
153
 
165
154
  ### Strict mode (default)
166
155
 
@@ -198,7 +187,7 @@ The following behaviour stems from the `attrs` package:
198
187
  Clone repository and cd into. Setup python 3.7 or higher.
199
188
  Note: Some tests are skipped for python 3.7.
200
189
 
201
- ~~~bash
190
+ ```bash
202
191
  pip install -e .
203
192
  pip install pytest pytest-cov pylint
204
193
  pylint typedparser
@@ -206,4 +195,4 @@ pylint typedparser
206
195
  # run tests
207
196
  python -m pytest --cov
208
197
  pylint tests
209
- ~~~
198
+ ```
@@ -0,0 +1,4 @@
1
+ attrs
2
+
3
+ [full]
4
+ numpy
@@ -1,4 +0,0 @@
1
- attrs
2
- importlib_metadata;python_version<'3.8'
3
- typing_extensions;python_version<'3.8'
4
-
@@ -1,8 +0,0 @@
1
- attrs
2
-
3
- [:python_version < "3.8"]
4
- importlib_metadata
5
- typing_extensions
6
-
7
- [full]
8
- numpy
File without changes
File without changes