Get rid of the coerce_overrides() function.
Add the ParseOverrides argparse.Action to parse overrides.
Treat all extra settings values strictly as json values.
Test overrides.
Edit docs and cli help.
This commit is contained in:
Victor Skvortsov 2021-10-20 16:17:31 +05:00 committed by Justin Mayer
commit 5c178a1ccb
5 changed files with 42 additions and 60 deletions

View file

@ -1,7 +1,6 @@
import copy
import importlib.util
import inspect
import json
import locale
import logging
import os
@ -659,25 +658,3 @@ def configure_settings(settings):
continue # setting not specified, nothing to do
return settings
def coerce_overrides(overrides):
if overrides is None:
return {}
coerced = {}
types_to_cast = {int, str, bool}
for k, v in overrides.items():
if k not in DEFAULT_CONFIG:
logger.warning('Override for unknown setting %s, ignoring', k)
continue
setting_type = type(DEFAULT_CONFIG[k])
if setting_type not in types_to_cast:
coerced[k] = json.loads(v)
else:
try:
coerced[k] = setting_type(v)
except ValueError:
logger.debug('ValueError for %s override with %s, try to '
'load as json', k, v)
coerced[k] = json.loads(v)
return coerced