Skip to content

Commit 80ea476

Browse files
authored
Merge pull request freqtrade#12461 from freqtrade/feat/stringread_strategyload
improve strategy loading with huge strategy libraries
2 parents 8ddbf4b + db63d43 commit 80ea476

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

freqtrade/resolvers/iresolver.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def _search_object(
148148
logger.debug("Ignoring broken symlink %s", entry)
149149
continue
150150
module_path = entry.resolve()
151+
if entry.read_text().find(f"class {object_name}(") == -1:
152+
logger.debug(f"Skipping {module_path} as it does not contain class {object_name}.")
153+
continue
151154

152155
if obj := next(cls._get_valid_object(module_path, object_name), None):
153156
obj[0].__file__ = str(entry)

tests/strategy/test_strategy_loading.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,16 @@ def test_load_strategy_invalid_directory(caplog, default_conf, tmp_path):
9696
assert log_has_re(r"Path .*" + r"some.*path.*" + r".* does not exist", caplog)
9797

9898

99+
def test_load_strategy_skip_other_files(caplog, default_conf, tmp_path):
100+
default_conf["user_data_dir"] = tmp_path
101+
caplog.set_level(logging.DEBUG)
102+
103+
s = StrategyResolver._load_strategy("StrategyTestV3", config=default_conf)
104+
assert isinstance(s, IStrategy)
105+
106+
assert log_has_re(r"Skipping .* as it does not contain class StrategyTestV3\.", caplog)
107+
108+
99109
def test_load_not_found_strategy(default_conf, tmp_path):
100110
default_conf["user_data_dir"] = tmp_path
101111
default_conf["strategy"] = "NotFoundStrategy"

0 commit comments

Comments
 (0)