[config] add 'conf' argument to 'config.load()' (#8084)
to allow using an alternative config dict
This commit is contained in:
@@ -185,13 +185,13 @@ def remap_categories():
|
|||||||
opts[new] = opts[old]
|
opts[new] = opts[old]
|
||||||
|
|
||||||
|
|
||||||
def load(files=None, strict=False, loads=util.json_loads):
|
def load(files=None, strict=False, loads=util.json_loads, conf=_config):
|
||||||
"""Load JSON configuration files"""
|
"""Load JSON configuration files"""
|
||||||
for pathfmt in files or _default_configs:
|
for pathfmt in files or _default_configs:
|
||||||
path = util.expand_path(pathfmt)
|
path = util.expand_path(pathfmt)
|
||||||
try:
|
try:
|
||||||
with open(path, encoding="utf-8") as fp:
|
with open(path, encoding="utf-8") as fp:
|
||||||
conf = loads(fp.read())
|
config = loads(fp.read())
|
||||||
except OSError as exc:
|
except OSError as exc:
|
||||||
if strict:
|
if strict:
|
||||||
log.error(exc)
|
log.error(exc)
|
||||||
@@ -202,17 +202,17 @@ def load(files=None, strict=False, loads=util.json_loads):
|
|||||||
if strict:
|
if strict:
|
||||||
raise SystemExit(2)
|
raise SystemExit(2)
|
||||||
else:
|
else:
|
||||||
if not _config:
|
if not conf:
|
||||||
_config.update(conf)
|
conf.update(config)
|
||||||
else:
|
else:
|
||||||
util.combine_dict(_config, conf)
|
util.combine_dict(conf, config)
|
||||||
_files.append(pathfmt)
|
_files.append(pathfmt)
|
||||||
|
|
||||||
if "subconfigs" in conf:
|
if "subconfigs" in config:
|
||||||
if subconfigs := conf["subconfigs"]:
|
if subconfigs := config["subconfigs"]:
|
||||||
if isinstance(subconfigs, str):
|
if isinstance(subconfigs, str):
|
||||||
subconfigs = (subconfigs,)
|
subconfigs = (subconfigs,)
|
||||||
load(subconfigs, strict, loads)
|
load(subconfigs, strict, loads, conf)
|
||||||
|
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
|
|||||||
Reference in New Issue
Block a user