diff --git a/lean/commands/backtest.py b/lean/commands/backtest.py index d1c14f18..7abf80b5 100644 --- a/lean/commands/backtest.py +++ b/lean/commands/backtest.py @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json from pathlib import Path from typing import List, Optional, Tuple from click import command, option, argument, Choice @@ -292,7 +291,9 @@ def _select_organization() -> QCMinimalOrganization: @option("--extra-docker-config", type=str, default="{}", - hidden=True) + help="Extra docker configuration as a JSON string. Supported configurations can be found at " + "https://docker-py.readthedocs.io/en/stable/containers.html, althaugh not all of them might be " + "supported by the Lean CLI.") @option("--no-update", is_flag=True, default=False, @@ -329,6 +330,8 @@ def backtest(project: Path, Alternatively you can set the default engine image for all commands using `lean config set engine-image `. """ from datetime import datetime + from json import loads + logger = container.logger project_manager = container.project_manager algorithm_file = project_manager.find_algorithm_file(Path(project)) @@ -413,4 +416,4 @@ def backtest(project: Path, debugging_method, release, detach, - json.loads(extra_docker_config)) + loads(extra_docker_config)) diff --git a/lean/commands/live/deploy.py b/lean/commands/live/deploy.py index 314ef7ab..cb53f6d1 100644 --- a/lean/commands/live/deploy.py +++ b/lean/commands/live/deploy.py @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json from pathlib import Path from typing import Any, Dict, List, Optional, Tuple from click import option, argument, Choice @@ -259,7 +258,9 @@ def _get_default_value(key: str) -> Optional[Any]: @option("--extra-docker-config", type=str, default="{}", - hidden=True) + help="Extra docker configuration as a JSON string. Supported configurations can be found at " + "https://docker-py.readthedocs.io/en/stable/containers.html, althaugh not all of them might be " + "supported by the Lean CLI.") @option("--no-update", is_flag=True, default=False, @@ -305,6 +306,7 @@ def deploy(project: Path, """ from copy import copy from datetime import datetime + from json import loads # Reset globals so we reload everything in between tests global _cached_lean_config _cached_lean_config = None @@ -436,4 +438,4 @@ def deploy(project: Path, raise RuntimeError(f"InteractiveBrokers is currently not supported for ARM hosts") lean_runner = container.lean_runner - lean_runner.run_lean(lean_config, environment_name, algorithm_file, output, engine_image, None, release, detach, json.loads(extra_docker_config)) + lean_runner.run_lean(lean_config, environment_name, algorithm_file, output, engine_image, None, release, detach, loads(extra_docker_config)) diff --git a/lean/commands/optimize.py b/lean/commands/optimize.py index af8d69f7..40bf6c77 100644 --- a/lean/commands/optimize.py +++ b/lean/commands/optimize.py @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json from pathlib import Path from typing import Optional, List, Tuple from datetime import datetime, timedelta @@ -124,7 +123,9 @@ def get_filename_timestamp(path: Path) -> datetime: @option("--extra-docker-config", type=str, default="{}", - hidden=True) + help="Extra docker configuration as a JSON string. Supported configurations can be found at " + "https://docker-py.readthedocs.io/en/stable/containers.html, althaugh not all of them might be " + "supported by the Lean CLI.") @option("--no-update", is_flag=True, default=False, @@ -316,7 +317,7 @@ def optimize(project: Path, container.update_manager.pull_docker_image_if_necessary(engine_image, update, no_update) # Add known additional run options from the extra docker config - LeanRunner.parse_extra_docker_config(run_options, json.loads(extra_docker_config)) + LeanRunner.parse_extra_docker_config(run_options, loads(extra_docker_config)) project_manager.copy_code(algorithm_file.parent, output / "code") diff --git a/lean/commands/research.py b/lean/commands/research.py index 710c1f6e..a538bff6 100644 --- a/lean/commands/research.py +++ b/lean/commands/research.py @@ -11,7 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json from pathlib import Path from typing import Optional, Tuple from click import command, argument, option, Choice @@ -70,7 +69,9 @@ def _check_docker_output(chunk: str, port: int) -> None: @option("--extra-docker-config", type=str, default="{}", - hidden=True) + help="Extra docker configuration as a JSON string. Supported configurations can be found at " + "https://docker-py.readthedocs.io/en/stable/containers.html, althaugh not all of them might be " + "supported by the Lean CLI.") @option("--no-update", is_flag=True, default=False, @@ -96,6 +97,7 @@ def research(project: Path, """ from docker.types import Mount from docker.errors import APIError + from json import loads logger = container.logger @@ -168,7 +170,7 @@ def research(project: Path, run_options["commands"].append("./start.sh") # Add known additional run options from the extra docker config - LeanRunner.parse_extra_docker_config(run_options, json.loads(extra_docker_config)) + LeanRunner.parse_extra_docker_config(run_options, loads(extra_docker_config)) project_config_manager = container.project_config_manager cli_config_manager = container.cli_config_manager diff --git a/lean/components/docker/lean_runner.py b/lean/components/docker/lean_runner.py index 0abd5ffe..d4f0aa2d 100644 --- a/lean/components/docker/lean_runner.py +++ b/lean/components/docker/lean_runner.py @@ -13,7 +13,6 @@ from pathlib import Path from typing import Any, Dict, Optional, List -import docker.types from lean.components.cloud.module_manager import ModuleManager from lean.components.config.lean_config_manager import LeanConfigManager @@ -772,8 +771,9 @@ def mount_project_and_library_directories(self, project_dir: Path, run_options: @staticmethod def parse_extra_docker_config(run_options: Dict[str, Any], extra_docker_config: Optional[Dict[str, Any]]) -> None: + from docker.types import DeviceRequest # Add known additional run options from the extra docker config. # For now, only device_requests is supported if extra_docker_config is not None and "device_requests" in extra_docker_config: - run_options["device_requests"] = [docker.types.DeviceRequest(**device_request) + run_options["device_requests"] = [DeviceRequest(**device_request) for device_request in extra_docker_config["device_requests"]]