Skip to content

Commit

Permalink
fix: revert changes reverted from master by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Apr 5, 2024
1 parent 6391f9f commit 3794236
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions lean/components/docker/lean_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ def get_basic_docker_config(self,
# Create a C# project used to resolve the dependencies of the modules
run_options["commands"].append("mkdir /ModulesProject")
run_options["commands"].append("dotnet new sln -o /ModulesProject")
run_options["commands"].append("dotnet new classlib -o /ModulesProject -f net6.0 --no-restore")

framework_ver = self._docker_manager.get_image_label(image, 'target_framework',
DEFAULT_LEAN_DOTNET_FRAMEWORK)
run_options["commands"].append(f"dotnet new classlib -o /ModulesProject -f {framework_ver} --no-restore")
run_options["commands"].append("rm /ModulesProject/Class1.cs")

# Add all modules to the project, automatically resolving all dependencies
Expand All @@ -335,9 +338,10 @@ def get_basic_docker_config(self,
run_options["commands"].append(
"python /copy_csharp_dependencies.py /Compile/obj/ModulesProject/project.assets.json")

# Set up language-specific run options
# Set up language-specific run options
self.setup_language_specific_run_options(run_options, project_dir, algorithm_file,
set_up_common_csharp_options_called, release)
set_up_common_csharp_options_called, release,
image)

# Save the final Lean config to a temporary file so we can mount it into the container
config_path = self._temp_manager.create_temporary_directory() / "config.json"
Expand Down Expand Up @@ -371,11 +375,12 @@ def get_basic_docker_config(self,

return run_options

def set_up_python_options(self, project_dir: Path, run_options: Dict[str, Any]) -> None:
def set_up_python_options(self, project_dir: Path, run_options: Dict[str, Any], image: DockerImage) -> None:
"""Sets up Docker run options specific to Python projects.
:param project_dir: the path to the project directory
:param run_options: the dictionary to append run options to
:param image: the docker image that will be used
"""

from docker.types import Mount
Expand Down Expand Up @@ -422,10 +427,14 @@ def set_up_python_options(self, project_dir: Path, run_options: Dict[str, Any])
"mode": "rw"
}

python_version = self._docker_manager.get_image_label(image, 'python_version',
DEFAULT_LEAN_PYTHON_VERSION)
site_packages_path = DOCKER_PYTHON_SITE_PACKAGES_PATH.replace('{LEAN_PYTHON_VERSION}', python_version)

# Mount a volume to the user packages directory so we don't install packages every time
site_packages_volume = self._docker_manager.create_site_packages_volume(requirements_txt)
run_options["volumes"][site_packages_volume] = {
"bind": f"{DOCKER_PYTHON_SITE_PACKAGES_PATH}",
"bind": f"{site_packages_path}",
"mode": "rw"
}

Expand All @@ -436,7 +445,7 @@ def set_up_python_options(self, project_dir: Path, run_options: Dict[str, Any])
# We only need to do this if it hasn't already been done before for this site packages volume
# To keep track of this we create a special file in the site packages directory after installation
# If this file already exists we can skip pip install completely
marker_file = f"{DOCKER_PYTHON_SITE_PACKAGES_PATH}/pip-install-done"
marker_file = f"{site_packages_path}/pip-install-done"
run_options["commands"].extend([
f"! test -f {marker_file} && pip install --user --progress-bar off -r /requirements.txt",
f"touch {marker_file}"
Expand Down Expand Up @@ -464,12 +473,14 @@ def _concat_python_requirements(self, requirements_files: List[Path]) -> str:
requirements = sorted(set(requirements))
return "\n".join(requirements)

def set_up_csharp_options(self, project_dir: Path, run_options: Dict[str, Any], release: bool) -> None:
def set_up_csharp_options(self, project_dir: Path, run_options: Dict[str, Any], release: bool,
image: DockerImage) -> None:
"""Sets up Docker run options specific to C# projects.
:param project_dir: the path to the project directory
:param run_options: the dictionary to append run options to
:param release: whether C# projects should be compiled in release configuration instead of debug
:param image: the docker image that will be used
"""
compile_root = self._get_csharp_compile_root(project_dir)

Expand All @@ -486,11 +497,13 @@ def set_up_csharp_options(self, project_dir: Path, run_options: Dict[str, Any],
for path in compile_root.rglob("*.csproj"):
self._ensure_csproj_uses_correct_lean(compile_root, path, csproj_temp_dir, run_options)

framework_ver = self._docker_manager.get_image_label(image, 'target_framework',
DEFAULT_LEAN_DOTNET_FRAMEWORK)
# Set up the MSBuild properties
msbuild_properties = {
"Configuration": "Release" if release else "Debug",
"Platform": "AnyCPU",
"TargetFramework": "net6.0",
"TargetFramework": framework_ver,
"OutputPath": "/Compile/bin",
"GenerateAssemblyInfo": "false",
"GenerateTargetFrameworkAttribute": "false",
Expand Down Expand Up @@ -734,14 +747,14 @@ def _force_disk_provider_if_necessary(self,
lean_config[config_key] = disk_provider

def setup_language_specific_run_options(self, run_options, project_dir, algorithm_file,
set_up_common_csharp_options_called, release) -> None:
set_up_common_csharp_options_called, release, image: DockerImage) -> None:
# Set up language-specific run options
if algorithm_file.name.endswith(".py"):
self.set_up_python_options(project_dir, run_options)
self.set_up_python_options(project_dir, run_options, image)
else:
if not set_up_common_csharp_options_called:
self.set_up_common_csharp_options(run_options)
self.set_up_csharp_options(project_dir, run_options, release)
self.set_up_csharp_options(project_dir, run_options, release, image)

def format_error_before_logging(self, chunk: str):
from lean.components.util import compiler
Expand Down

0 comments on commit 3794236

Please sign in to comment.