Skip to content

Commit

Permalink
First draft of the solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Marinovsky committed Sep 5, 2024
1 parent cdc59be commit 2c54652
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lean/commands/research.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ 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)
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 2c54652

Please sign in to comment.