Update sequence of process_deprecated_setting parameters
This commit is contained in:
parent
0235868c66
commit
b7f01a08f3
@ -12,16 +12,17 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
def check_conflicting_settings(config: Dict[str, Any],
|
def check_conflicting_settings(config: Dict[str, Any],
|
||||||
section1: str, name1: str,
|
section_old: str, name_old: str,
|
||||||
section2: str, name2: str) -> None:
|
section_new: str, name_new: str) -> None:
|
||||||
section1_config = config.get(section1, {})
|
section_new_config = config.get(section_new, {}) if section_new else config
|
||||||
section2_config = config.get(section2, {})
|
section_old_config = config.get(section_old, {})
|
||||||
if name1 in section1_config and name2 in section2_config:
|
if name_new in section_new_config and name_old in section_old_config:
|
||||||
|
new_name = f"{section_new}.{name_new}" if section_new else f"{name_new}"
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f"Conflicting settings `{section1}.{name1}` and `{section2}.{name2}` "
|
f"Conflicting settings `{new_name}` and `{section_old}.{name_old}` "
|
||||||
"(DEPRECATED) detected in the configuration file. "
|
"(DEPRECATED) detected in the configuration file. "
|
||||||
"This deprecated setting will be removed in the next versions of Freqtrade. "
|
"This deprecated setting will be removed in the next versions of Freqtrade. "
|
||||||
f"Please delete it from your configuration and use the `{section1}.{name1}` "
|
f"Please delete it from your configuration and use the `{new_name}` "
|
||||||
"setting instead."
|
"setting instead."
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,27 +38,32 @@ def process_removed_setting(config: Dict[str, Any],
|
|||||||
"""
|
"""
|
||||||
section1_config = config.get(section1, {})
|
section1_config = config.get(section1, {})
|
||||||
if name1 in section1_config:
|
if name1 in section1_config:
|
||||||
|
section_2 = f"{section2}.{name2}" if section2 else f"{name2}"
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f"Setting `{section1}.{name1}` has been moved to `{section2}.{name2}. "
|
f"Setting `{section1}.{name1}` has been moved to `{section_2}. "
|
||||||
f"Please delete it from your configuration and use the `{section2}.{name2}` "
|
f"Please delete it from your configuration and use the `{section_2}` "
|
||||||
"setting instead."
|
"setting instead."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def process_deprecated_setting(config: Dict[str, Any],
|
def process_deprecated_setting(config: Dict[str, Any],
|
||||||
section1: str, name1: str,
|
section_old: str, name_old: str,
|
||||||
section2: str, name2: str) -> None:
|
section_new: str, name_new: str
|
||||||
section2_config = config.get(section2, {})
|
) -> None:
|
||||||
|
check_conflicting_settings(config, section_old, name_old, section_new, name_new)
|
||||||
|
section_old_config = config.get(section_old, {})
|
||||||
|
|
||||||
if name2 in section2_config:
|
if name_old in section_old_config:
|
||||||
|
section_2 = f"{section_new}.{name_new}" if section_new else f"{name_new}"
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"DEPRECATED: "
|
"DEPRECATED: "
|
||||||
f"The `{section2}.{name2}` setting is deprecated and "
|
f"The `{section_old}.{name_old}` setting is deprecated and "
|
||||||
"will be removed in the next versions of Freqtrade. "
|
"will be removed in the next versions of Freqtrade. "
|
||||||
f"Please use the `{section1}.{name1}` setting in your configuration instead."
|
f"Please use the `{section_2}` setting in your configuration instead."
|
||||||
)
|
)
|
||||||
section1_config = config.get(section1, {})
|
|
||||||
section1_config[name1] = section2_config[name2]
|
section_new_config = config.get(section_new, {}) if section_new else config
|
||||||
|
section_new_config[name_new] = section_old_config[name_old]
|
||||||
|
|
||||||
|
|
||||||
def process_temporary_deprecated_settings(config: Dict[str, Any]) -> None:
|
def process_temporary_deprecated_settings(config: Dict[str, Any]) -> None:
|
||||||
@ -65,15 +71,24 @@ def process_temporary_deprecated_settings(config: Dict[str, Any]) -> None:
|
|||||||
# Kept for future deprecated / moved settings
|
# Kept for future deprecated / moved settings
|
||||||
# check_conflicting_settings(config, 'ask_strategy', 'use_sell_signal',
|
# check_conflicting_settings(config, 'ask_strategy', 'use_sell_signal',
|
||||||
# 'experimental', 'use_sell_signal')
|
# 'experimental', 'use_sell_signal')
|
||||||
# process_deprecated_setting(config, 'ask_strategy', 'use_sell_signal',
|
process_deprecated_setting(config, 'ask_strategy', 'use_sell_signal',
|
||||||
# 'experimental', 'use_sell_signal')
|
None, 'use_sell_signal')
|
||||||
|
process_deprecated_setting(config, 'ask_strategy', 'sell_profit_only',
|
||||||
|
None, 'sell_profit_only')
|
||||||
|
process_deprecated_setting(config, 'ask_strategy', 'sell_profit_offset',
|
||||||
|
None, 'sell_profit_offset')
|
||||||
|
process_deprecated_setting(config, 'ask_strategy', 'ignore_roi_if_buy_signal',
|
||||||
|
None, 'ignore_roi_if_buy_signal')
|
||||||
|
process_deprecated_setting(config, 'ask_strategy', 'ignore_buying_expired_candle_after',
|
||||||
|
None, 'ignore_buying_expired_candle_after')
|
||||||
|
|
||||||
|
# Legacy way - having them in experimental ...
|
||||||
process_removed_setting(config, 'experimental', 'use_sell_signal',
|
process_removed_setting(config, 'experimental', 'use_sell_signal',
|
||||||
'ask_strategy', 'use_sell_signal')
|
None, 'use_sell_signal')
|
||||||
process_removed_setting(config, 'experimental', 'sell_profit_only',
|
process_removed_setting(config, 'experimental', 'sell_profit_only',
|
||||||
'ask_strategy', 'sell_profit_only')
|
None, 'sell_profit_only')
|
||||||
process_removed_setting(config, 'experimental', 'ignore_roi_if_buy_signal',
|
process_removed_setting(config, 'experimental', 'ignore_roi_if_buy_signal',
|
||||||
'ask_strategy', 'ignore_roi_if_buy_signal')
|
None, 'ignore_roi_if_buy_signal')
|
||||||
|
|
||||||
if (config.get('edge', {}).get('enabled', False)
|
if (config.get('edge', {}).get('enabled', False)
|
||||||
and 'capital_available_percentage' in config.get('edge', {})):
|
and 'capital_available_percentage' in config.get('edge', {})):
|
||||||
|
@ -1249,8 +1249,8 @@ def test_process_deprecated_setting(mocker, default_conf, caplog):
|
|||||||
|
|
||||||
# Both new and deprecated settings exists
|
# Both new and deprecated settings exists
|
||||||
process_deprecated_setting(default_conf,
|
process_deprecated_setting(default_conf,
|
||||||
'sectionA', 'new_setting',
|
'sectionB', 'deprecated_setting',
|
||||||
'sectionB', 'deprecated_setting')
|
'sectionA', 'new_setting')
|
||||||
assert log_has_re('DEPRECATED', caplog)
|
assert log_has_re('DEPRECATED', caplog)
|
||||||
# The value of the new setting shall have been set to the
|
# The value of the new setting shall have been set to the
|
||||||
# value of the deprecated one
|
# value of the deprecated one
|
||||||
@ -1261,8 +1261,8 @@ def test_process_deprecated_setting(mocker, default_conf, caplog):
|
|||||||
# Delete new setting (deprecated exists)
|
# Delete new setting (deprecated exists)
|
||||||
del default_conf['sectionA']['new_setting']
|
del default_conf['sectionA']['new_setting']
|
||||||
process_deprecated_setting(default_conf,
|
process_deprecated_setting(default_conf,
|
||||||
'sectionA', 'new_setting',
|
'sectionB', 'deprecated_setting',
|
||||||
'sectionB', 'deprecated_setting')
|
'sectionA', 'new_setting')
|
||||||
assert log_has_re('DEPRECATED', caplog)
|
assert log_has_re('DEPRECATED', caplog)
|
||||||
# The value of the new setting shall have been set to the
|
# The value of the new setting shall have been set to the
|
||||||
# value of the deprecated one
|
# value of the deprecated one
|
||||||
@ -1275,11 +1275,21 @@ def test_process_deprecated_setting(mocker, default_conf, caplog):
|
|||||||
# Delete deprecated setting
|
# Delete deprecated setting
|
||||||
del default_conf['sectionB']['deprecated_setting']
|
del default_conf['sectionB']['deprecated_setting']
|
||||||
process_deprecated_setting(default_conf,
|
process_deprecated_setting(default_conf,
|
||||||
'sectionA', 'new_setting',
|
'sectionB', 'deprecated_setting',
|
||||||
'sectionB', 'deprecated_setting')
|
'sectionA', 'new_setting')
|
||||||
assert not log_has_re('DEPRECATED', caplog)
|
assert not log_has_re('DEPRECATED', caplog)
|
||||||
assert default_conf['sectionA']['new_setting'] == 'valA'
|
assert default_conf['sectionA']['new_setting'] == 'valA'
|
||||||
|
|
||||||
|
caplog.clear()
|
||||||
|
# Test moving to root
|
||||||
|
default_conf['sectionB']['deprecated_setting2'] = "DeadBeef"
|
||||||
|
process_deprecated_setting(default_conf,
|
||||||
|
'sectionB', 'deprecated_setting2',
|
||||||
|
None, 'new_setting')
|
||||||
|
|
||||||
|
assert log_has_re('DEPRECATED', caplog)
|
||||||
|
assert default_conf['new_setting']
|
||||||
|
|
||||||
|
|
||||||
def test_process_removed_setting(mocker, default_conf, caplog):
|
def test_process_removed_setting(mocker, default_conf, caplog):
|
||||||
patched_configuration_load_config_file(mocker, default_conf)
|
patched_configuration_load_config_file(mocker, default_conf)
|
||||||
|
Loading…
Reference in New Issue
Block a user