Skip to content

Commit bc53255

Browse files
committed
✨ Refactor: Replace json.loads with json_loads for consistency across modules
1 parent ac9aa7c commit bc53255

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

packages/dask-task-models-library/src/dask_task_models_library/container_tasks/io.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
from typing import Annotated, Any, TypeAlias
55

6+
from common_library.json_serialization import json_loads
67
from models_library.basic_regex import MIME_TYPE_RE
78
from models_library.generics import DictModel
89
from models_library.services_types import ServicePortKey
@@ -160,7 +161,7 @@ def from_task_output(
160161
with suppress(json.JSONDecodeError):
161162
# NOTE: The suppression here is ok, since if the data is empty,
162163
# there will be a validation error anyway
163-
data = json.loads(output_data_file.read_text())
164+
data = json_loads(output_data_file.read_text())
164165

165166
for output_key, output_params in schema.items():
166167
if isinstance(output_params, FilePortSchema):

packages/models-library/src/models_library/function_services_catalog/_settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import json
22
import os
33

4+
from common_library.json_serialization import json_loads
45
from pydantic_settings import BaseSettings
56

67
# Expects env var: FUNCTION_SERVICES_AUTHORS='{"OM":{"name": ...}, "EN":{...} }'
78
try:
8-
AUTHORS = json.loads(os.environ.get("FUNCTION_SERVICES_AUTHORS", "{}"))
9+
AUTHORS = json_loads(os.environ.get("FUNCTION_SERVICES_AUTHORS", "{}"))
910
except json.decoder.JSONDecodeError:
1011
AUTHORS = {}
1112

packages/models-library/src/models_library/utils/labels_annotations.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
""" Image labels annotations
1+
"""Image labels annotations
22
33
osparc expects the service configuration (in short: config) attached to the service's image as label annotations.
44
This module defines how this config is serialized/deserialized to/from docker labels annotations
55
"""
66

7-
import json
87
from json.decoder import JSONDecodeError
98
from typing import Any, TypeAlias
109

11-
from common_library.json_serialization import json_dumps
10+
from common_library.json_serialization import json_dumps, json_loads
1211

1312
LabelsAnnotationsDict: TypeAlias = dict[str, str | float | bool | None]
1413

@@ -57,7 +56,7 @@ def from_labels(
5756
for key, label in labels.items():
5857
if key.startswith(f"{prefix_key}."):
5958
try:
60-
value = json.loads(label) # type: ignore
59+
value = json_loads(label) # type: ignore
6160
except JSONDecodeError:
6261
value = label
6362

packages/service-integration/src/service_integration/cli/_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import json
21
from pathlib import Path
32
from typing import Annotated, Final
43

54
import rich
65
import typer
76
import yaml
7+
from common_library.json_serialization import json_loads
88
from models_library.utils.labels_annotations import LabelsAnnotationsDict
99
from pydantic import BaseModel
1010

@@ -57,7 +57,7 @@ def _save(service_name: str, filename: Path, model: BaseModel):
5757
rich.print(f"Creating {output_path} ...", end="")
5858

5959
with output_path.open("wt") as fh:
60-
data = json.loads(
60+
data = json_loads(
6161
model.model_dump_json(by_alias=True, exclude_none=True)
6262
)
6363
yaml.safe_dump(data, fh, sort_keys=False)

packages/service-integration/src/service_integration/pytest_plugin/docker_integration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import jsonschema
1919
import pytest
2020
import yaml
21+
from common_library.json_serialization import json_loads
2122
from docker.errors import APIError
2223
from docker.models.containers import Container
2324

@@ -206,7 +207,7 @@ def convert_to_simcore_labels(image_labels: dict) -> dict:
206207
io_simcore_labels = {}
207208
for key, value in image_labels.items():
208209
if str(key).startswith("io.simcore."):
209-
simcore_label = json.loads(value)
210+
simcore_label = json_loads(value)
210211
simcore_keys = list(simcore_label.keys())
211212
assert len(simcore_keys) == 1
212213
simcore_key = simcore_keys[0]

0 commit comments

Comments
 (0)