mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 08:33:07 +00:00
Merge pull request #12461 from freqtrade/feat/stringread_strategyload
improve strategy loading with huge strategy libraries
This commit is contained in:
@@ -148,6 +148,9 @@ class IResolver:
|
|||||||
logger.debug("Ignoring broken symlink %s", entry)
|
logger.debug("Ignoring broken symlink %s", entry)
|
||||||
continue
|
continue
|
||||||
module_path = entry.resolve()
|
module_path = entry.resolve()
|
||||||
|
if entry.read_text().find(f"class {object_name}(") == -1:
|
||||||
|
logger.debug(f"Skipping {module_path} as it does not contain class {object_name}.")
|
||||||
|
continue
|
||||||
|
|
||||||
if obj := next(cls._get_valid_object(module_path, object_name), None):
|
if obj := next(cls._get_valid_object(module_path, object_name), None):
|
||||||
obj[0].__file__ = str(entry)
|
obj[0].__file__ = str(entry)
|
||||||
|
|||||||
@@ -96,6 +96,16 @@ def test_load_strategy_invalid_directory(caplog, default_conf, tmp_path):
|
|||||||
assert log_has_re(r"Path .*" + r"some.*path.*" + r".* does not exist", caplog)
|
assert log_has_re(r"Path .*" + r"some.*path.*" + r".* does not exist", caplog)
|
||||||
|
|
||||||
|
|
||||||
|
def test_load_strategy_skip_other_files(caplog, default_conf, tmp_path):
|
||||||
|
default_conf["user_data_dir"] = tmp_path
|
||||||
|
caplog.set_level(logging.DEBUG)
|
||||||
|
|
||||||
|
s = StrategyResolver._load_strategy("StrategyTestV3", config=default_conf)
|
||||||
|
assert isinstance(s, IStrategy)
|
||||||
|
|
||||||
|
assert log_has_re(r"Skipping .* as it does not contain class StrategyTestV3\.", caplog)
|
||||||
|
|
||||||
|
|
||||||
def test_load_not_found_strategy(default_conf, tmp_path):
|
def test_load_not_found_strategy(default_conf, tmp_path):
|
||||||
default_conf["user_data_dir"] = tmp_path
|
default_conf["user_data_dir"] = tmp_path
|
||||||
default_conf["strategy"] = "NotFoundStrategy"
|
default_conf["strategy"] = "NotFoundStrategy"
|
||||||
|
|||||||
Reference in New Issue
Block a user