Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix research function to work without an algorithm file #498

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading