Merge pull request #12461 from freqtrade/feat/stringread_strategyload

improve strategy loading with huge strategy libraries
This commit is contained in:
Matthias
2025-11-04 06:37:28 +01:00
committed by GitHub
2 changed files with 13 additions and 0 deletions

View File

@@ -148,6 +148,9 @@ class IResolver:
logger.debug("Ignoring broken symlink %s", entry)
continue
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):
obj[0].__file__ = str(entry)

View File

@@ -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)
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):
default_conf["user_data_dir"] = tmp_path
default_conf["strategy"] = "NotFoundStrategy"