gridparse 1.5.1__tar.gz → 1.5.3__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
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: gridparse
3
- Version: 1.5.1
3
+ Version: 1.5.3
4
4
  Summary: Grid search directly from argparse
5
5
  Home-page: https://github.com/gchochla/gridparse
6
6
  Author: Georgios Chochlakis
@@ -49,10 +49,13 @@ Requires-Dist: black; extra == "dev"
49
49
  Requires-Dist: pytest; extra == "dev"
50
50
  Dynamic: author
51
51
  Dynamic: home-page
52
+ Dynamic: license-file
52
53
 
53
- # GridParse
54
+ ![Logo](./media/logo.svg)
54
55
 
55
- A lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` --- aka `GridArgumentParser` --- that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) as also support through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
56
+ ***
57
+
58
+ `gridparse` is a lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` - aka `GridArgumentParser` - that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) are also supported through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
56
59
 
57
60
  ## Overview
58
61
 
@@ -70,7 +73,27 @@ So, for single arguments, it extends them similar to nargs="+". For multiple arg
70
73
 
71
74
  ## Examples
72
75
 
73
- Example without subspaces:
76
+ Example with subspaces:
77
+
78
+ ```python
79
+ parser = GridArgumentParser()
80
+ parser.add_argument("--hparam1", type=int, searchable=True)
81
+ parser.add_argument("--hparam2", type=int, searchable=True)
82
+ parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
83
+ parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
84
+ parser.add_argument("--normal", required=True, type=str)
85
+
86
+ args = parser.parse_args(
87
+ (
88
+ "--hparam1 1 2 "
89
+ "{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
90
+ "{--hparam2 4 5 6 --normal not-normal}"
91
+ ).split()
92
+ )
93
+ assert len(args) == 2 * ((3 * (3 + 4)) + 3)
94
+ ```
95
+
96
+ Example without subspaces but with lists for grid-search:
74
97
 
75
98
  ```python
76
99
  parser = GridArgumentParser()
@@ -81,23 +104,23 @@ parser.add_argument(
81
104
  "--lists",
82
105
  required=True,
83
106
  nargs="+",
84
- type=list_as_dashed_str(str),
107
+ type=list_as_delim_str(int),
85
108
  searchable=True,
86
109
  )
87
110
  parser.add_argument(
88
111
  "--normal_lists",
89
112
  required=True,
90
113
  nargs="+",
91
- type=list_as_dashed_str(str),
114
+ type=list_as_delim_str(str),
92
115
  )
93
116
  args = parser.parse_args(
94
117
  (
95
- "--hparam1 1~~2~~3 --hparam2 4~~3 5~~4 6~~5 "
96
- "--normal efrgthytfgn --lists 1-2-3 3-4-5~~6-7 "
97
- "--normal_lists 1-2-3 4-5-6"
118
+ "--hparam1 1 2 3 --hparam2 4|3 5|4 6|5 "
119
+ "--normal efrgthytfgn --lists 1,-2,3 3,4,5|6,7 "
120
+ "--normal_lists a,b,c d,e,f"
98
121
  ).split()
99
122
  )
100
- assert len(args) == 1 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
123
+ assert len(args) == 3 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
101
124
 
102
125
  pprint(args)
103
126
  ```
@@ -122,25 +145,10 @@ Namespace(hparam1=[1, 2, 3], hparam2=[6, 5], lists=[['3', '4', '5'], ['6', '7']]
122
145
  ]
123
146
  ```
124
147
 
125
- Example with subspaces:
126
-
127
- ```python
128
- parser = GridArgumentParser()
129
- parser.add_argument("--hparam1", type=int, searchable=True)
130
- parser.add_argument("--hparam2", type=int, searchable=True)
131
- parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
132
- parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
133
- parser.add_argument("--normal", required=True, type=str)
148
+ Searchable argument always use space to designate a different configuration. Namely, notice that for:
149
+ - `nargs` and `searchable=True`, `nargs` is delimited by `|` and `searchable` uses the spaces.
150
+ - `nargs` and `searchable=True` and `list_as_delim_str`, `nargs` uses `|` within each configuration, and `list_as_delim_str` uses `,` within each list of the same configuration, and space is still used by `searchable` to split configurations.
134
151
 
135
- args = parser.parse_args(
136
- (
137
- "--hparam1 1 2 "
138
- "{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
139
- "{--hparam2 4 5 6 --normal not-normal}"
140
- ).split()
141
- )
142
- assert len(args) == 2 * ((3 * (3 + 4)) + 3)
143
- ```
144
152
 
145
153
  ## Additional capabilities
146
154
 
@@ -1,6 +1,8 @@
1
- # GridParse
1
+ ![Logo](./media/logo.svg)
2
2
 
3
- A lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` --- aka `GridArgumentParser` --- that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) as also support through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
3
+ ***
4
+
5
+ `gridparse` is a lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` - aka `GridArgumentParser` - that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) are also supported through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
4
6
 
5
7
  ## Overview
6
8
 
@@ -18,7 +20,27 @@ So, for single arguments, it extends them similar to nargs="+". For multiple arg
18
20
 
19
21
  ## Examples
20
22
 
21
- Example without subspaces:
23
+ Example with subspaces:
24
+
25
+ ```python
26
+ parser = GridArgumentParser()
27
+ parser.add_argument("--hparam1", type=int, searchable=True)
28
+ parser.add_argument("--hparam2", type=int, searchable=True)
29
+ parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
30
+ parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
31
+ parser.add_argument("--normal", required=True, type=str)
32
+
33
+ args = parser.parse_args(
34
+ (
35
+ "--hparam1 1 2 "
36
+ "{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
37
+ "{--hparam2 4 5 6 --normal not-normal}"
38
+ ).split()
39
+ )
40
+ assert len(args) == 2 * ((3 * (3 + 4)) + 3)
41
+ ```
42
+
43
+ Example without subspaces but with lists for grid-search:
22
44
 
23
45
  ```python
24
46
  parser = GridArgumentParser()
@@ -29,23 +51,23 @@ parser.add_argument(
29
51
  "--lists",
30
52
  required=True,
31
53
  nargs="+",
32
- type=list_as_dashed_str(str),
54
+ type=list_as_delim_str(int),
33
55
  searchable=True,
34
56
  )
35
57
  parser.add_argument(
36
58
  "--normal_lists",
37
59
  required=True,
38
60
  nargs="+",
39
- type=list_as_dashed_str(str),
61
+ type=list_as_delim_str(str),
40
62
  )
41
63
  args = parser.parse_args(
42
64
  (
43
- "--hparam1 1~~2~~3 --hparam2 4~~3 5~~4 6~~5 "
44
- "--normal efrgthytfgn --lists 1-2-3 3-4-5~~6-7 "
45
- "--normal_lists 1-2-3 4-5-6"
65
+ "--hparam1 1 2 3 --hparam2 4|3 5|4 6|5 "
66
+ "--normal efrgthytfgn --lists 1,-2,3 3,4,5|6,7 "
67
+ "--normal_lists a,b,c d,e,f"
46
68
  ).split()
47
69
  )
48
- assert len(args) == 1 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
70
+ assert len(args) == 3 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
49
71
 
50
72
  pprint(args)
51
73
  ```
@@ -70,25 +92,10 @@ Namespace(hparam1=[1, 2, 3], hparam2=[6, 5], lists=[['3', '4', '5'], ['6', '7']]
70
92
  ]
71
93
  ```
72
94
 
73
- Example with subspaces:
74
-
75
- ```python
76
- parser = GridArgumentParser()
77
- parser.add_argument("--hparam1", type=int, searchable=True)
78
- parser.add_argument("--hparam2", type=int, searchable=True)
79
- parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
80
- parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
81
- parser.add_argument("--normal", required=True, type=str)
95
+ Searchable argument always use space to designate a different configuration. Namely, notice that for:
96
+ - `nargs` and `searchable=True`, `nargs` is delimited by `|` and `searchable` uses the spaces.
97
+ - `nargs` and `searchable=True` and `list_as_delim_str`, `nargs` uses `|` within each configuration, and `list_as_delim_str` uses `,` within each list of the same configuration, and space is still used by `searchable` to split configurations.
82
98
 
83
- args = parser.parse_args(
84
- (
85
- "--hparam1 1 2 "
86
- "{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
87
- "{--hparam2 4 5 6 --normal not-normal}"
88
- ).split()
89
- )
90
- assert len(args) == 2 * ((3 * (3 + 4)) + 3)
91
- ```
92
99
 
93
100
  ## Additional capabilities
94
101
 
@@ -1,4 +1,4 @@
1
1
  from argparse import *
2
2
 
3
3
  from .grid_argument_parser import GridArgumentParser
4
- from .utils import list_as_dashed_str, strbool
4
+ from .utils import list_as_delim_str, strbool
@@ -5,7 +5,7 @@ from typing import Any, Tuple, List, Optional, Union, Sequence
5
5
  from copy import deepcopy
6
6
  from omegaconf import OmegaConf
7
7
 
8
- from gridparse.utils import list_as_dashed_str, strbool
8
+ from gridparse.utils import list_as_delim_str, strbool
9
9
 
10
10
 
11
11
  class AuxArgumentParser(argparse.ArgumentParser):
@@ -14,7 +14,7 @@ class AuxArgumentParser(argparse.ArgumentParser):
14
14
 
15
15
  def parse_known_args(
16
16
  self, args=None, namespace=None
17
- ) -> Tuple[argparse.Namespace, List[str], Set[str]]:
17
+ ) -> Tuple[argparse.Namespace, List[str]]:
18
18
  """Overwritten to collect the argument names that
19
19
  are specified in the command line."""
20
20
  if args is None:
@@ -61,7 +61,7 @@ class AuxArgumentParser(argparse.ArgumentParser):
61
61
 
62
62
  def _parse_known_args(
63
63
  self, arg_strings, namespace
64
- ) -> Tuple[List[argparse.Namespace], List[str], Set[str]]:
64
+ ) -> Tuple[List[argparse.Namespace], List[str]]:
65
65
  """Overwritten to collect the argument names that
66
66
  are specified in the command line."""
67
67
 
@@ -710,7 +710,7 @@ class GridArgumentParser(_GridActionsContainer, AuxArgumentParser):
710
710
  type = kwargs.get("type", None)
711
711
 
712
712
  if nargs == "+":
713
- type = list_as_dashed_str(type, delimiter="~~")
713
+ type = list_as_delim_str(type, delimiter="|")
714
714
  else:
715
715
  nargs = "+"
716
716
 
@@ -2,12 +2,12 @@ import argparse
2
2
  from typing import Callable
3
3
 
4
4
 
5
- # TODO: has issues with negative numbers
6
- def list_as_dashed_str(actual_type: Callable, delimiter: str = "-"):
5
+ # NOTE: has issues with negative numbers if delim="-"
6
+ def list_as_delim_str(actual_type: Callable, delimiter: str = ","):
7
7
  """Creates a function that converts a string to a list of elements.
8
8
 
9
9
  Can be used as the `type` argument in `argparse` to convert
10
- a string to a list of elements, e.g.: `["1-2-3", "4-5-6"]` to
10
+ a string to a list of elements, e.g.: `["1,2,3", "4,5,6"]` to
11
11
  `[[1, 2, 3], [4, 5, 6]]` (note that this operates on a single
12
12
  `str` at a time, use `nargs` to pass multiple).
13
13
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: gridparse
3
- Version: 1.5.1
3
+ Version: 1.5.3
4
4
  Summary: Grid search directly from argparse
5
5
  Home-page: https://github.com/gchochla/gridparse
6
6
  Author: Georgios Chochlakis
@@ -49,10 +49,13 @@ Requires-Dist: black; extra == "dev"
49
49
  Requires-Dist: pytest; extra == "dev"
50
50
  Dynamic: author
51
51
  Dynamic: home-page
52
+ Dynamic: license-file
52
53
 
53
- # GridParse
54
+ ![Logo](./media/logo.svg)
54
55
 
55
- A lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` --- aka `GridArgumentParser` --- that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) as also support through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
56
+ ***
57
+
58
+ `gridparse` is a lightweight (only dependency is `omegaconf` which also downloads `yaml`) `ArgumentParser` - aka `GridArgumentParser` - that supports your *grid-search* needs. Supports top-level parser and subparsers. Configuration files of any type (using `omegaconf`) are also supported through the argument `--gridparse-config` (also available with underscore `_`), where multiple configuration files can be passed and parsed.
56
59
 
57
60
  ## Overview
58
61
 
@@ -70,7 +73,27 @@ So, for single arguments, it extends them similar to nargs="+". For multiple arg
70
73
 
71
74
  ## Examples
72
75
 
73
- Example without subspaces:
76
+ Example with subspaces:
77
+
78
+ ```python
79
+ parser = GridArgumentParser()
80
+ parser.add_argument("--hparam1", type=int, searchable=True)
81
+ parser.add_argument("--hparam2", type=int, searchable=True)
82
+ parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
83
+ parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
84
+ parser.add_argument("--normal", required=True, type=str)
85
+
86
+ args = parser.parse_args(
87
+ (
88
+ "--hparam1 1 2 "
89
+ "{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
90
+ "{--hparam2 4 5 6 --normal not-normal}"
91
+ ).split()
92
+ )
93
+ assert len(args) == 2 * ((3 * (3 + 4)) + 3)
94
+ ```
95
+
96
+ Example without subspaces but with lists for grid-search:
74
97
 
75
98
  ```python
76
99
  parser = GridArgumentParser()
@@ -81,23 +104,23 @@ parser.add_argument(
81
104
  "--lists",
82
105
  required=True,
83
106
  nargs="+",
84
- type=list_as_dashed_str(str),
107
+ type=list_as_delim_str(int),
85
108
  searchable=True,
86
109
  )
87
110
  parser.add_argument(
88
111
  "--normal_lists",
89
112
  required=True,
90
113
  nargs="+",
91
- type=list_as_dashed_str(str),
114
+ type=list_as_delim_str(str),
92
115
  )
93
116
  args = parser.parse_args(
94
117
  (
95
- "--hparam1 1~~2~~3 --hparam2 4~~3 5~~4 6~~5 "
96
- "--normal efrgthytfgn --lists 1-2-3 3-4-5~~6-7 "
97
- "--normal_lists 1-2-3 4-5-6"
118
+ "--hparam1 1 2 3 --hparam2 4|3 5|4 6|5 "
119
+ "--normal efrgthytfgn --lists 1,-2,3 3,4,5|6,7 "
120
+ "--normal_lists a,b,c d,e,f"
98
121
  ).split()
99
122
  )
100
- assert len(args) == 1 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
123
+ assert len(args) == 3 * 3 * 1 * 2 * 1 # corresponding number of different values in input CL arguments
101
124
 
102
125
  pprint(args)
103
126
  ```
@@ -122,25 +145,10 @@ Namespace(hparam1=[1, 2, 3], hparam2=[6, 5], lists=[['3', '4', '5'], ['6', '7']]
122
145
  ]
123
146
  ```
124
147
 
125
- Example with subspaces:
126
-
127
- ```python
128
- parser = GridArgumentParser()
129
- parser.add_argument("--hparam1", type=int, searchable=True)
130
- parser.add_argument("--hparam2", type=int, searchable=True)
131
- parser.add_argument("--hparam3", type=int, searchable=True, default=1000)
132
- parser.add_argument("--hparam4", type=int, searchable=True, default=2000)
133
- parser.add_argument("--normal", required=True, type=str)
148
+ Searchable argument always use space to designate a different configuration. Namely, notice that for:
149
+ - `nargs` and `searchable=True`, `nargs` is delimited by `|` and `searchable` uses the spaces.
150
+ - `nargs` and `searchable=True` and `list_as_delim_str`, `nargs` uses `|` within each configuration, and `list_as_delim_str` uses `,` within each list of the same configuration, and space is still used by `searchable` to split configurations.
134
151
 
135
- args = parser.parse_args(
136
- (
137
- "--hparam1 1 2 "
138
- "{--hparam2 1 2 3 {--normal normal --hparam4 100 101 102} {--normal maybe --hparam4 200 201 202 203}} "
139
- "{--hparam2 4 5 6 --normal not-normal}"
140
- ).split()
141
- )
142
- assert len(args) == 2 * ((3 * (3 + 4)) + 3)
143
- ```
144
152
 
145
153
  ## Additional capabilities
146
154
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "gridparse"
3
- version = "1.5.1"
3
+ version = "1.5.3"
4
4
  description = "Grid search directly from argparse"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.7"
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="gridparse",
8
- version="1.5.1",
8
+ version="1.5.3",
9
9
  description="Grid search directly from argparse",
10
10
  author="Georgios Chochlakis",
11
11
  author_email="georgioschochlakis@gmail.com",
File without changes
File without changes
File without changes