From f97c44f46a37378bf0a3c1d82fcb242a354239ac Mon Sep 17 00:00:00 2001 From: Ronit Jain Date: Wed, 16 Nov 2022 02:50:08 +0530 Subject: [PATCH 1/2] mount source code to docker --- lean/components/docker/lean_runner.py | 32 +++++++++++++++------------ lean/components/util/compiler.py | 2 +- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lean/components/docker/lean_runner.py b/lean/components/docker/lean_runner.py index e1a895ba..fcf9287a 100644 --- a/lean/components/docker/lean_runner.py +++ b/lean/components/docker/lean_runner.py @@ -225,20 +225,8 @@ def get_basic_docker_config(self, "ports": docker_project_config.get("ports", {}) } - # Mount the project directory - run_options["volumes"][str(project_dir)] = { - "bind": "/LeanCLI", - "mode": "rw" - } - - # Check if the user has library projects and mount the Library directory - library_dir = self._lean_config_manager.get_cli_root_directory() / "Library" - if library_dir.is_dir(): - # Mount the library projects - run_options["volumes"][str(library_dir)] = { - "bind": "/Library", - "mode": "rw" - } + # mount the project and library directories + self.mount_project_and_library_directories(project_dir, run_options) # Mount the data directory run_options["volumes"][str(data_dir)] = { @@ -729,3 +717,19 @@ def format_error_before_logging(self, chunk: str): for error in errors: self._logger.info(error) + + def mount_project_and_library_directories(self, project_dir: Path, run_options: Dict[str, Any]) -> None: + # Mount the project directory + run_options["volumes"][str(project_dir)] = { + "bind": "/LeanCLI", + "mode": "rw" + } + + # Check if the user has library projects and mount the Library directory + library_dir = self._lean_config_manager.get_cli_root_directory() / "Library" + if library_dir.is_dir(): + # Mount the library projects + run_options["volumes"][str(library_dir)] = { + "bind": "/Library", + "mode": "rw" + } diff --git a/lean/components/util/compiler.py b/lean/components/util/compiler.py index 964ffc27..7d0dcaa7 100644 --- a/lean/components/util/compiler.py +++ b/lean/components/util/compiler.py @@ -108,7 +108,7 @@ def _compile() -> Dict[str, Any]: "mounts": [], "volumes": {} } - + lean_runner.mount_project_and_library_directories(project_dir, run_options) lean_runner.setup_language_specific_run_options(run_options, project_dir, algorithm_file, False, False) project_config = project_config_manager.get_project_config(project_dir) From f8885bdfaa654a371b479a6aae3d5ee0f3880c8d Mon Sep 17 00:00:00 2001 From: Ronit Jain Date: Wed, 16 Nov 2022 02:55:20 +0530 Subject: [PATCH 2/2] take project directory as input --- lean/components/util/compiler.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lean/components/util/compiler.py b/lean/components/util/compiler.py index 7d0dcaa7..585c1a4d 100644 --- a/lean/components/util/compiler.py +++ b/lean/components/util/compiler.py @@ -14,6 +14,7 @@ from json import dumps from typing import Dict, Any from lean.container import container +from pathlib import Path docker_manager = container.docker_manager project_manager = container.project_manager @@ -95,8 +96,10 @@ def _compile() -> Dict[str, Any]: "algorithmType": "", } - project_id = int(argv[-1]) - project_dir = project_manager.get_project_by_id(project_id) + project_dir = Path(argv[-1]) + if not project_dir.exists(): + raise(f"Project directory {project_dir} does not exist") + algorithm_file = project_manager.find_algorithm_file(project_dir) message["algorithmType"] = "python" if algorithm_file.name.endswith(".py") else "csharp"