libentry 1.24.3__py3-none-any.whl → 1.24.4__py3-none-any.whl
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.
- libentry/argparse.py +9 -85
- {libentry-1.24.3.dist-info → libentry-1.24.4.dist-info}/METADATA +1 -1
- {libentry-1.24.3.dist-info → libentry-1.24.4.dist-info}/RECORD +8 -8
- {libentry-1.24.3.dist-info → libentry-1.24.4.dist-info}/LICENSE +0 -0
- {libentry-1.24.3.dist-info → libentry-1.24.4.dist-info}/WHEEL +0 -0
- {libentry-1.24.3.dist-info → libentry-1.24.4.dist-info}/entry_points.txt +0 -0
- {libentry-1.24.3.dist-info → libentry-1.24.4.dist-info}/top_level.txt +0 -0
- {libentry-1.24.3.dist-info → libentry-1.24.4.dist-info}/zip-safe +0 -0
libentry/argparse.py
CHANGED
@@ -127,18 +127,22 @@ class ArgumentParser(argparse.ArgumentParser):
|
|
127
127
|
self._add_schema(name, schema)
|
128
128
|
|
129
129
|
def _add_schema(self, prefix: str, schema: Type[BaseModel]):
|
130
|
-
|
130
|
+
model_fields = schema.model_fields
|
131
|
+
assert isinstance(model_fields, dict)
|
132
|
+
for name, info in model_fields.items():
|
131
133
|
anno = info.annotation
|
132
134
|
nested = False
|
133
135
|
|
134
136
|
if isinstance(anno, type) and issubclass(anno, BaseModel):
|
135
137
|
nested = True
|
136
138
|
|
137
|
-
if get_origin(anno) is Union
|
138
|
-
|
139
|
-
|
139
|
+
if get_origin(anno) is Union:
|
140
|
+
# Here we just choose the first BaseModel.
|
141
|
+
# So you should avoid define a Union contains multiple BaseModel types.
|
142
|
+
for sub_anno in get_args(anno):
|
143
|
+
if isinstance(sub_anno, type) and issubclass(sub_anno, BaseModel):
|
144
|
+
anno = sub_anno
|
140
145
|
nested = True
|
141
|
-
anno = t
|
142
146
|
break
|
143
147
|
|
144
148
|
if nested:
|
@@ -228,83 +232,3 @@ def _list_field_names(obj):
|
|
228
232
|
return [*obj.model_fields]
|
229
233
|
else:
|
230
234
|
return [obj.__dict__]
|
231
|
-
|
232
|
-
# T = TypeVar('T')
|
233
|
-
#
|
234
|
-
#
|
235
|
-
# class ArgumentParser(argparse.ArgumentParser):
|
236
|
-
# PATTERN_ARG_NAME = re.compile(r"^--?[a-zA-Z][\w\-.]*$")
|
237
|
-
# PATTERN_ARG_PREFIX = re.compile(r"^--?")
|
238
|
-
# DATACLASS_OBJ_KEY = 'target'
|
239
|
-
#
|
240
|
-
# def __init__(self):
|
241
|
-
# super().__init__()
|
242
|
-
# self.obj_dict = {}
|
243
|
-
#
|
244
|
-
# def add_argument(self, *args, **kwargs):
|
245
|
-
# if self.DATACLASS_OBJ_KEY in kwargs:
|
246
|
-
# obj = kwargs[self.DATACLASS_OBJ_KEY]
|
247
|
-
# for prefix in args:
|
248
|
-
# self.obj_dict[prefix] = obj
|
249
|
-
# return obj
|
250
|
-
# elif len(args) >= 2 and is_dataclass(args[-1]) and all(isinstance(arg, str) for arg in args[:-1]):
|
251
|
-
# obj = args[-1]
|
252
|
-
# for prefix in args[:-1]:
|
253
|
-
# self.obj_dict[prefix] = obj
|
254
|
-
# return obj
|
255
|
-
# else:
|
256
|
-
# return super().add_argument(*args, **kwargs)
|
257
|
-
#
|
258
|
-
# def add_dataclass(self, prefix, d: Union[Type[T], T]) -> T:
|
259
|
-
# assert is_dataclass(d)
|
260
|
-
# if isinstance(d, type):
|
261
|
-
# d = d()
|
262
|
-
# self.obj_dict[prefix] = d
|
263
|
-
# return d
|
264
|
-
#
|
265
|
-
# def parse_args(self, args=None, namespace=None, parse_unknown=False):
|
266
|
-
# args, unknown_args = super().parse_known_args()
|
267
|
-
#
|
268
|
-
# d = {}
|
269
|
-
# name = None
|
270
|
-
# values = []
|
271
|
-
# for arg in unknown_args:
|
272
|
-
# if arg.startswith('-'):
|
273
|
-
# if self.PATTERN_ARG_NAME.match(arg):
|
274
|
-
# if name is not None:
|
275
|
-
# d[name] = values[0] if len(values) == 1 else values
|
276
|
-
# values = []
|
277
|
-
# name = self.PATTERN_ARG_PREFIX.sub("", arg).replace('-', '_')
|
278
|
-
# else:
|
279
|
-
# value = literal_eval(arg)
|
280
|
-
# if isinstance(value, str):
|
281
|
-
# logger.warning(f'The value "{arg}" may be incorrect.')
|
282
|
-
# if name is not None:
|
283
|
-
# values.append(value)
|
284
|
-
# else:
|
285
|
-
# values.append(literal_eval(arg))
|
286
|
-
# if name is not None:
|
287
|
-
# d[name] = values[0] if len(values) == 1 else values
|
288
|
-
#
|
289
|
-
# for name, value in d.items():
|
290
|
-
# sections = name.split('.')
|
291
|
-
# if len(sections) == 1:
|
292
|
-
# args.__dict__[name] = value
|
293
|
-
# else:
|
294
|
-
# prefix = sections[0]
|
295
|
-
# members = sections[1:-1]
|
296
|
-
# attr = sections[-1]
|
297
|
-
# if prefix not in self.obj_dict:
|
298
|
-
# raise RuntimeError(f'There is no {prefix} argument.')
|
299
|
-
# obj = self.obj_dict[prefix]
|
300
|
-
#
|
301
|
-
# for member in members:
|
302
|
-
# if not hasattr(obj, member):
|
303
|
-
# raise RuntimeError(f'There is no {prefix} argument {name}.')
|
304
|
-
# obj = getattr(obj, member)
|
305
|
-
#
|
306
|
-
# if not hasattr(obj, attr):
|
307
|
-
# raise RuntimeError(f'There is no {prefix} argument {name}.')
|
308
|
-
# setattr(obj, sections[-1], value)
|
309
|
-
#
|
310
|
-
# return args
|
@@ -1,6 +1,6 @@
|
|
1
1
|
libentry/__init__.py,sha256=ko2YBIIx5H3dD0tedBkialzJGEDczFaP_PZmT1cIlak,148
|
2
2
|
libentry/api.py,sha256=UkXdBv9oqQhaSESRReLWEPj8venBUoCBppIg-FAXqKA,24146
|
3
|
-
libentry/argparse.py,sha256=
|
3
|
+
libentry/argparse.py,sha256=IPe0nEII-HDB0aYAiYjrMULIN6v4n7VWSi5c8nh4UxU,7604
|
4
4
|
libentry/dataclasses.py,sha256=AQV2PuxplJCwGZ5HKX72U-z-POUhTdy3XtpEK9KNIGQ,4541
|
5
5
|
libentry/executor.py,sha256=cTV0WxJi0nU1TP-cOwmeodN8DD6L1691M2HIQsJtGrU,6582
|
6
6
|
libentry/experiment.py,sha256=ejgAHDXWIe9x4haUzIFuz1WasLY0_aD1z_vyEVGjTu8,4922
|
@@ -22,10 +22,10 @@ libentry/service/list.py,sha256=ElHWhTgShGOhaxMUEwVbMXos0NQKjHsODboiQ-3AMwE,1397
|
|
22
22
|
libentry/service/running.py,sha256=FrPJoJX6wYxcHIysoatAxhW3LajCCm0Gx6l7__6sULQ,5105
|
23
23
|
libentry/service/start.py,sha256=mZT7b9rVULvzy9GTZwxWnciCHgv9dbGN2JbxM60OMn4,1270
|
24
24
|
libentry/service/stop.py,sha256=wOpwZgrEJ7QirntfvibGq-XsTC6b3ELhzRW2zezh-0s,1187
|
25
|
-
libentry-1.24.
|
26
|
-
libentry-1.24.
|
27
|
-
libentry-1.24.
|
28
|
-
libentry-1.24.
|
29
|
-
libentry-1.24.
|
30
|
-
libentry-1.24.
|
31
|
-
libentry-1.24.
|
25
|
+
libentry-1.24.4.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
26
|
+
libentry-1.24.4.dist-info/METADATA,sha256=Ow5czGQ7Hsbo-4JjT7CudKXtbw06qcGkgaNKcH8I8sg,1135
|
27
|
+
libentry-1.24.4.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
28
|
+
libentry-1.24.4.dist-info/entry_points.txt,sha256=1v_nLVDsjvVJp9SWhl4ef2zZrsLTBtFWgrYFgqvQBgc,61
|
29
|
+
libentry-1.24.4.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
|
30
|
+
libentry-1.24.4.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
31
|
+
libentry-1.24.4.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|