Skip to content

Commit

Permalink
Update new docker extra config option documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonabreul committed Sep 19, 2023
1 parent 7ed3383 commit 5b1b415
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
9 changes: 6 additions & 3 deletions lean/commands/backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 <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))
Expand Down Expand Up @@ -413,4 +416,4 @@ def backtest(project: Path,
debugging_method,
release,
detach,
json.loads(extra_docker_config))
loads(extra_docker_config))
8 changes: 5 additions & 3 deletions lean/commands/live/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
7 changes: 4 additions & 3 deletions lean/commands/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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")

Expand Down
8 changes: 5 additions & 3 deletions lean/commands/research.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lean/components/docker/lean_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]]

0 comments on commit 5b1b415

Please sign in to comment.