From 99fbdcfec42f1aa3912e0dbd426d04ba543b4212 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Andr=C3=A9s=20Marino=20Rojas?= <47573394+Marinovsky@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:22:39 -0500 Subject: [PATCH] Fix research function to work without an algorithm file (#498) * First draft of the solution * Add more comments --- lean/commands/research.py | 7 ++++++- lean/components/util/project_manager.py | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lean/commands/research.py b/lean/commands/research.py index 604c92a4..c126f62e 100644 --- a/lean/commands/research.py +++ b/lean/commands/research.py @@ -101,7 +101,12 @@ def research(project: Path, logger = container.logger project_manager = container.project_manager - algorithm_file = project_manager.find_algorithm_file(project) + algorithm_file = project_manager.find_algorithm_file(project, not_throw = True) + + # We just need the algorithm file name to create the configurations for lean and + # the docker container. We do not need an algorithm file to run a research project + if algorithm_file is None: + algorithm_file = project / 'main.py' algorithm_name = convert_to_class_name(project) environment_name = "backtesting" diff --git a/lean/components/util/project_manager.py b/lean/components/util/project_manager.py index 21d9518d..19fc62ed 100644 --- a/lean/components/util/project_manager.py +++ b/lean/components/util/project_manager.py @@ -58,12 +58,14 @@ def __init__(self, self._cli_config_manager = cli_config_manager self._docker_manager = docker_manager - def find_algorithm_file(self, input: Path) -> Path: + def find_algorithm_file(self, input: Path, not_throw: bool = False) -> Path: """Returns the path to the file containing the algorithm. Raises an error if the algorithm file cannot be found. :param input: the path to the algorithm or the path to the project + :param not_throw: a flag indicating whether this method should + raise an exception if the file is not found :return: the path to the file containing the algorithm """ if input.is_file(): @@ -74,6 +76,8 @@ def find_algorithm_file(self, input: Path) -> Path: if target_file.exists(): return target_file + if not_throw: + return None raise ValueError("The specified project does not contain a main.py or Main.cs file") def get_project_by_id(self, local_id: int) -> Path: