oceanprotocol-job-details 0.1.2__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (16) hide show
  1. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/PKG-INFO +1 -1
  2. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/config.py +11 -10
  3. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/ocean.py +29 -1
  4. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/pyproject.toml +1 -1
  5. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/.gitignore +0 -0
  6. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/LICENSE +0 -0
  7. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/README.md +0 -0
  8. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/__init__.py +0 -0
  9. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/job_details.py +0 -0
  10. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/loaders/__init__.py +0 -0
  11. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/loaders/impl/__init__.py +0 -0
  12. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/loaders/impl/ddo.py +0 -0
  13. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/loaders/impl/files.py +0 -0
  14. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/loaders/impl/job_details.py +0 -0
  15. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/loaders/loader.py +0 -0
  16. {oceanprotocol_job_details-0.1.2 → oceanprotocol_job_details-0.1.4}/oceanprotocol_job_details/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oceanprotocol-job-details
3
- Version: 0.1.2
3
+ Version: 0.1.4
4
4
  Summary: A Python package to get details from OceanProtocol jobs
5
5
  Project-URL: Homepage, https://github.com/AgrospAI/oceanprotocol-job-details
6
6
  Project-URL: Issues, https://github.com/AgrospAI/oceanprotocol-job-details/issues
@@ -9,22 +9,22 @@ logger = getLogger(__name__)
9
9
  class Config:
10
10
  """Configuration class for the Ocean Protocol Job Details"""
11
11
 
12
- path_data: str = "/data"
12
+ path_data: Path = Path("/data")
13
13
  """The path to the data directory"""
14
14
 
15
- path_inputs: str = path_data + "/inputs"
15
+ path_inputs: Path = path_data / "inputs"
16
16
  """The path to the inputs directory"""
17
17
 
18
- path_ddos: str = path_data + "/ddos"
18
+ path_ddos: Path = path_data / "ddos"
19
19
  """The path to the DDOs directory"""
20
20
 
21
- path_outputs: str = path_data + "/outputs"
21
+ path_outputs: Path = path_data / "outputs"
22
22
  """The path to the outputs directory"""
23
23
 
24
- path_logs: str = path_data + "/logs"
24
+ path_logs: Path = path_data / "logs"
25
25
  """The path to the logs directory"""
26
26
 
27
- path_algorithm_custom_parameters: str = path_inputs + "/algoCustomData.json"
27
+ path_algorithm_custom_parameters: Path = path_inputs / "algoCustomData.json"
28
28
  """The path to the algorithm's custom parameters file"""
29
29
 
30
30
 
@@ -43,11 +43,12 @@ def update_config_from(base: Path) -> None:
43
43
  base.mkdir(parents=True, exist_ok=True)
44
44
 
45
45
  for field in fields(config):
46
- default_value = field.default
47
- if default_value is None or not isinstance(default_value, Path):
48
- raise ValueError(f"Field {field.name} has no default value")
46
+ current_value = getattr(config, field.name)
47
+ if not isinstance(current_value, Path):
48
+ raise ValueError(f"Field {field.name} is n|ot a Path")
49
49
 
50
- object.__setattr__(config, field.name, str(base / default_value))
50
+ rel_path = Path(current_value).relative_to("/data")
51
+ object.__setattr__(config, field.name, base / rel_path)
51
52
 
52
53
 
53
54
  __all__ = ["config"]
@@ -2,6 +2,8 @@ from dataclasses import dataclass, field
2
2
  from functools import cached_property
3
3
  from typing import Any, Generic, Optional, Type, TypeVar, final
4
4
 
5
+ import orjson
6
+
5
7
  from dataclasses_json import config as dc_config
6
8
  from dataclasses_json import dataclass_json
7
9
 
@@ -155,6 +157,20 @@ class DDO:
155
157
  purgatory: Purgatory
156
158
 
157
159
 
160
+ def _normalize_json(value):
161
+ if isinstance(value, str):
162
+ try:
163
+ decoded = orjson.loads(value)
164
+ return _normalize_json(decoded) # recurse if nested again
165
+ except orjson.JSONDecodeError:
166
+ return value
167
+ elif isinstance(value, dict):
168
+ return {k: _normalize_json(v) for k, v in value.items()}
169
+ elif isinstance(value, list):
170
+ return [_normalize_json(v) for v in value]
171
+ return value
172
+
173
+
158
174
  @final
159
175
  @dataclass_json
160
176
  @dataclass(frozen=True)
@@ -180,4 +196,16 @@ class JobDetails(Generic[T]):
180
196
  """Read the input parameters and return them in an instance of the dataclass T"""
181
197
 
182
198
  with open(config.path_algorithm_custom_parameters, "r") as f:
183
- return dataclass_json(self._type).from_json(f.read()) # type: ignore
199
+ raw = f.read().strip()
200
+ if not raw:
201
+ raise ValueError(
202
+ f"Custom parameters file {config.path_algorithm_custom_parameters} is empty"
203
+ )
204
+ try:
205
+ parsed = _normalize_json(orjson.loads(raw))
206
+ return dataclass_json(self._type).from_dict(parsed) # type: ignore
207
+ except Exception as e:
208
+ raise ValueError(
209
+ f"Failed to parse input paramers into {self._type.__name__}: {e}\n"
210
+ f"Raw content: {raw}"
211
+ ) from e
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "oceanprotocol-job-details"
3
- version = "0.1.2"
3
+ version = "0.1.4"
4
4
  description = "A Python package to get details from OceanProtocol jobs"
5
5
  authors = [
6
6
  { name = "Christian López García", email = "christian.lopez@udl.cat" },