From 1435d269962f74180df2fbd22e96de751094ddde Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 8 Apr 2022 17:26:51 +0200 Subject: [PATCH] store config-file loading paths --- freqtrade/configuration/load_config.py | 7 +++++-- tests/test_configuration.py | 6 ++++++ .../{base_config.json => test_base_config.json} | 0 .../testconfigs/{pricing2.json => test_pricing2_conf.json} | 0 .../testconfigs/{pricing.json => test_pricing_conf.json} | 2 +- tests/testdata/testconfigs/testconfig.json | 4 ++-- 6 files changed, 14 insertions(+), 5 deletions(-) rename tests/testdata/testconfigs/{base_config.json => test_base_config.json} (100%) rename tests/testdata/testconfigs/{pricing2.json => test_pricing2_conf.json} (100%) rename tests/testdata/testconfigs/{pricing.json => test_pricing_conf.json} (92%) diff --git a/freqtrade/configuration/load_config.py b/freqtrade/configuration/load_config.py index 8718e9fd6..5a86ab24a 100644 --- a/freqtrade/configuration/load_config.py +++ b/freqtrade/configuration/load_config.py @@ -86,7 +86,7 @@ def load_from_files(files: List[str], base_path: Path = None, level: int = 0) -> if not files: return deepcopy(MINIMAL_CONFIG) - + files_loaded = [] # We expect here a list of config filenames for filename in files: 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)) if 'files' in config_tmp: 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) + files_loaded.insert(0, str(file)) + # Merge config options, overwriting prior values config = deep_merge_dicts(config_tmp, config) - config['config_files'] = files + config['config_files'] = files_loaded return config diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 39e56f075..957468b86 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -222,6 +222,12 @@ def test_from_recursive_files(testdatadir) -> None: # The other key comes from pricing2, which is imported by pricing.json 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" with pytest.raises(OperationalException, match="Config loop detected."): load_from_files([files]) diff --git a/tests/testdata/testconfigs/base_config.json b/tests/testdata/testconfigs/test_base_config.json similarity index 100% rename from tests/testdata/testconfigs/base_config.json rename to tests/testdata/testconfigs/test_base_config.json diff --git a/tests/testdata/testconfigs/pricing2.json b/tests/testdata/testconfigs/test_pricing2_conf.json similarity index 100% rename from tests/testdata/testconfigs/pricing2.json rename to tests/testdata/testconfigs/test_pricing2_conf.json diff --git a/tests/testdata/testconfigs/pricing.json b/tests/testdata/testconfigs/test_pricing_conf.json similarity index 92% rename from tests/testdata/testconfigs/pricing.json rename to tests/testdata/testconfigs/test_pricing_conf.json index d8868443f..fbdaede74 100644 --- a/tests/testdata/testconfigs/pricing.json +++ b/tests/testdata/testconfigs/test_pricing_conf.json @@ -16,6 +16,6 @@ "price_last_balance": 0.0 }, "files": [ - "pricing2.json" + "./test_pricing2_conf.json" ] } diff --git a/tests/testdata/testconfigs/testconfig.json b/tests/testdata/testconfigs/testconfig.json index 557926097..96b3b6db8 100644 --- a/tests/testdata/testconfigs/testconfig.json +++ b/tests/testdata/testconfigs/testconfig.json @@ -1,6 +1,6 @@ { "files": [ - "base_config.json", - "pricing.json" + "test_base_config.json", + "test_pricing_conf.json" ] }