|
215 | 215 | }
|
216 | 216 |
|
217 | 217 | # internal runtime to protobuf field name mapping
|
218 |
| -RUNTIME_MAPPING = { |
| 218 | +RUNTIME_CFG_MAP_TO_FIELD = { |
219 | 219 | 'completion': 'completion',
|
220 | 220 | 'directives': 'directives',
|
221 | 221 | 'environment': 'environment',
|
|
244 | 244 | }
|
245 | 245 | RUNTIME_JSON_DUMPS = {'directives', 'environment', 'outputs'}
|
246 | 246 | RUNTIME_STRINGIFYS = {'execution time limit'}
|
247 |
| -RUNTIME_TRY_ITEMS = {'platform': 'name'} |
248 | 247 |
|
249 | 248 |
|
250 | 249 | def setbuff(obj, key, value):
|
@@ -353,41 +352,35 @@ def runtime_from_config(rtconfig):
|
353 | 352 | def runtime_from_partial(rtconfig, runtimeold=None):
|
354 | 353 | """Populate runtime object from partial/full config.
|
355 | 354 |
|
356 |
| - Potentially slower with all the setattr calls, but no expected fields. |
| 355 | + Potentially slower than the non-partial one, due to tha the setattr calls, |
| 356 | + but does not have expected fields. |
357 | 357 | """
|
358 | 358 | runtime = PbRuntime()
|
359 | 359 | if runtimeold is not None:
|
360 | 360 | runtime.CopyFrom(runtimeold)
|
361 | 361 | for key, val in rtconfig.items():
|
362 |
| - if val is None or key not in RUNTIME_MAPPING: |
| 362 | + if val is None or key not in RUNTIME_CFG_MAP_TO_FIELD: |
363 | 363 | continue
|
364 | 364 | elif key in RUNTIME_LIST_JOINS:
|
365 |
| - setattr(runtime, RUNTIME_MAPPING[key], listjoin(val)) |
| 365 | + setattr(runtime, RUNTIME_CFG_MAP_TO_FIELD[key], listjoin(val)) |
366 | 366 | elif key in RUNTIME_JSON_DUMPS:
|
367 | 367 | setattr(
|
368 | 368 | runtime,
|
369 |
| - RUNTIME_MAPPING[key], |
| 369 | + RUNTIME_CFG_MAP_TO_FIELD[key], |
370 | 370 | json.dumps(
|
371 | 371 | [
|
372 | 372 | {'key': k, 'value': v}
|
373 | 373 | for k, v in val.items()
|
374 | 374 | ]
|
375 | 375 | )
|
376 | 376 | )
|
377 |
| - elif key in RUNTIME_TRY_ITEMS: |
378 |
| - try: |
379 |
| - setattr( |
380 |
| - runtime, |
381 |
| - RUNTIME_MAPPING[key], |
382 |
| - val[RUNTIME_TRY_ITEMS[key]] |
383 |
| - ) |
384 |
| - except (KeyError, TypeError): |
385 |
| - with suppress(KeyError, TypeError): |
386 |
| - setattr(runtime, RUNTIME_MAPPING[key], val) |
| 377 | + elif key == 'platform' and isinstance(val, dict): |
| 378 | + with suppress(KeyError, TypeError): |
| 379 | + setattr(runtime, RUNTIME_CFG_MAP_TO_FIELD[key], val['name']) |
387 | 380 | elif key in RUNTIME_STRINGIFYS:
|
388 |
| - setattr(runtime, RUNTIME_MAPPING[key], str(val or '')) |
| 381 | + setattr(runtime, RUNTIME_CFG_MAP_TO_FIELD[key], str(val or '')) |
389 | 382 | else:
|
390 |
| - setattr(runtime, RUNTIME_MAPPING[key], val) |
| 383 | + setattr(runtime, RUNTIME_CFG_MAP_TO_FIELD[key], val) |
391 | 384 | return runtime
|
392 | 385 |
|
393 | 386 |
|
|
0 commit comments