store config-file loading paths
This commit is contained in:
parent
3427df0653
commit
1435d26996
@ -86,7 +86,7 @@ def load_from_files(files: List[str], base_path: Path = None, level: int = 0) ->
|
|||||||
|
|
||||||
if not files:
|
if not files:
|
||||||
return deepcopy(MINIMAL_CONFIG)
|
return deepcopy(MINIMAL_CONFIG)
|
||||||
|
files_loaded = []
|
||||||
# We expect here a list of config filenames
|
# We expect here a list of config filenames
|
||||||
for filename in files:
|
for filename in files:
|
||||||
logger.info(f'Using config: {filename} ...')
|
logger.info(f'Using config: {filename} ...')
|
||||||
@ -101,11 +101,14 @@ def load_from_files(files: List[str], base_path: Path = None, level: int = 0) ->
|
|||||||
config_tmp = load_config_file(str(file))
|
config_tmp = load_config_file(str(file))
|
||||||
if 'files' in config_tmp:
|
if 'files' in config_tmp:
|
||||||
config_sub = load_from_files(config_tmp['files'], file.resolve().parent, level + 1)
|
config_sub = load_from_files(config_tmp['files'], file.resolve().parent, level + 1)
|
||||||
|
files_loaded.extend(config_sub.get('config_files', []))
|
||||||
deep_merge_dicts(config_sub, config_tmp)
|
deep_merge_dicts(config_sub, config_tmp)
|
||||||
|
|
||||||
|
files_loaded.insert(0, str(file))
|
||||||
|
|
||||||
# Merge config options, overwriting prior values
|
# Merge config options, overwriting prior values
|
||||||
config = deep_merge_dicts(config_tmp, config)
|
config = deep_merge_dicts(config_tmp, config)
|
||||||
|
|
||||||
config['config_files'] = files
|
config['config_files'] = files_loaded
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
@ -222,6 +222,12 @@ def test_from_recursive_files(testdatadir) -> None:
|
|||||||
# The other key comes from pricing2, which is imported by pricing.json
|
# The other key comes from pricing2, which is imported by pricing.json
|
||||||
assert conf['exit_pricing']['price_side'] == "other"
|
assert conf['exit_pricing']['price_side'] == "other"
|
||||||
|
|
||||||
|
assert len(conf['config_files']) == 4
|
||||||
|
assert 'testconfig.json' in conf['config_files'][0]
|
||||||
|
assert 'test_pricing_conf.json' in conf['config_files'][1]
|
||||||
|
assert 'test_base_config.json' in conf['config_files'][2]
|
||||||
|
assert 'test_pricing2_conf.json' in conf['config_files'][3]
|
||||||
|
|
||||||
files = testdatadir / "testconfigs/recursive.json"
|
files = testdatadir / "testconfigs/recursive.json"
|
||||||
with pytest.raises(OperationalException, match="Config loop detected."):
|
with pytest.raises(OperationalException, match="Config loop detected."):
|
||||||
load_from_files([files])
|
load_from_files([files])
|
||||||
|
@ -16,6 +16,6 @@
|
|||||||
"price_last_balance": 0.0
|
"price_last_balance": 0.0
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"pricing2.json"
|
"./test_pricing2_conf.json"
|
||||||
]
|
]
|
||||||
}
|
}
|
4
tests/testdata/testconfigs/testconfig.json
vendored
4
tests/testdata/testconfigs/testconfig.json
vendored
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"files": [
|
"files": [
|
||||||
"base_config.json",
|
"test_base_config.json",
|
||||||
"pricing.json"
|
"test_pricing_conf.json"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user