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

♻️ SonarCloud issues in director-v2 and dynamic-sidecar #4125

Merged
merged 6 commits into from
Apr 18, 2023
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
from collections import deque
from typing import Any, Optional, cast
from typing import Any, cast

from models_library.boot_options import BootOption, EnvVarKey
from models_library.service_settings_labels import (
Expand Down Expand Up @@ -78,8 +78,8 @@ def update_service_params_from_settings(
labels_service_settings: SimcoreServiceSettingsLabel,
create_service_params: dict[str, Any],
) -> None:
param: SimcoreServiceSettingLabelEntry
for param in labels_service_settings:
param: SimcoreServiceSettingLabelEntry = param
# NOTE: the below capitalize addresses a bug in a lot of already in use services
# where Resources was written in lower case
if param.setting_type.capitalize() == "Resources":
Expand Down Expand Up @@ -123,13 +123,11 @@ def update_service_params_from_settings(

# placement constraints
elif param.name == "constraints": # python-API compatible

create_service_params["task_template"]["Placement"][
"Constraints"
] += param.value

elif param.setting_type == "Constraints": # REST-API compatible

create_service_params["task_template"]["Placement"][
"Constraints"
] += param.value
Expand Down Expand Up @@ -198,7 +196,7 @@ def remap_to_compose_spec_key() -> dict[str, str]:
# remaps from image_name as key to compose_spec key
return {reverse_mapping[k]: v for k, v in docker_image_name_by_services.items()}

compose_spec: Optional[ComposeSpecLabel] = cast(
compose_spec: ComposeSpecLabel | None = cast(
GitHK marked this conversation as resolved.
Show resolved Hide resolved
ComposeSpecLabel, service_labels.compose_spec
)
if compose_spec is None:
Expand Down Expand Up @@ -274,8 +272,8 @@ def _merge_resources_in_settings(

result: deque[SimcoreServiceSettingLabelEntry] = deque()

entry: SimcoreServiceSettingLabelEntry
for entry in settings:
entry: SimcoreServiceSettingLabelEntry = entry
if entry.name == "Resources" and entry.setting_type == "Resources":
# skipping resources
continue
Expand Down Expand Up @@ -354,8 +352,8 @@ def _format_env_var(env_var: str, destination_container: list[str]) -> str:
)
return f"{var_name}={json_encoded}"

entry: SimcoreServiceSettingLabelEntry
for entry in settings:
entry: SimcoreServiceSettingLabelEntry = entry
if entry.name == "env" and entry.setting_type == "string":
# process entry
list_of_env_vars = entry.value if entry.value else []
Expand All @@ -375,7 +373,7 @@ def _format_env_var(env_var: str, destination_container: list[str]) -> str:

def _get_boot_options(
service_labels: SimcoreServiceLabels,
) -> Optional[dict[EnvVarKey, BootOption]]:
) -> dict[EnvVarKey, BootOption] | None:
as_dict = service_labels.dict()
boot_options_encoded = as_dict.get("io.simcore.boot-options", None)
if boot_options_encoded is None:
Expand All @@ -390,7 +388,6 @@ def _assemble_env_vars_for_boot_options(
boot_options: dict[EnvVarKey, BootOption],
service_user_selection_boot_options: dict[EnvVarKey, str],
) -> SimcoreServiceSettingsLabel:

env_vars: deque[str] = deque()
for env_var_key, boot_option in boot_options.items():
# fetch value selected by the user or use default if not present
Expand Down Expand Up @@ -451,7 +448,7 @@ async def merge_settings_before_use(

settings: deque[SimcoreServiceSettingLabelEntry] = deque() # TODO: fix typing here

boot_options_settings_env_vars: Optional[SimcoreServiceSettingsLabel] = None
boot_options_settings_env_vars: SimcoreServiceSettingsLabel | None = None
# search for boot options first and inject to all containers
for compose_spec_key, service_labels in labels_for_involved_services.items():
labels_boot_options = _get_boot_options(service_labels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,11 @@ def all_disk_paths(self) -> Iterator[Path]:

def _ensure_directories(self) -> None:
"""
Creates the directories on its file system,
these will be mounted elsewere.
Creates directories on its file system, these will be mounted by the user services.
"""
_ensure_path(self._dy_volumes)
self.disk_inputs_path # pylint:disable= pointless-statement
self.disk_outputs_path # pylint:disable= pointless-statement
set(self.disk_state_paths())
for path in self.all_disk_paths():
_ensure_path(path)

@staticmethod
async def _get_bind_path_from_label(label: str, run_id: RunID) -> Path:
Expand Down