Skip to content

Commit

Permalink
Fix research function to work without an algorithm file (#498)
Browse files Browse the repository at this point in the history
* First draft of the solution

* Add more comments
  • Loading branch information
Marinovsky authored Sep 5, 2024
1 parent 2a477a3 commit 99fbdcf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lean/commands/research.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion lean/components/util/project_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand Down

0 comments on commit 99fbdcf

Please sign in to comment.