oceanprotocol-job-details 0.2.5__tar.gz → 0.2.7__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 (17) hide show
  1. oceanprotocol_job_details-0.2.7/PKG-INFO +125 -0
  2. oceanprotocol_job_details-0.2.7/README.md +101 -0
  3. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/di.py +1 -0
  4. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/loaders/impl/ddo.py +1 -1
  5. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/loaders/impl/files.py +15 -5
  6. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/ocean.py +13 -19
  7. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/paths.py +2 -2
  8. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/pyproject.toml +2 -1
  9. oceanprotocol_job_details-0.2.5/PKG-INFO +0 -76
  10. oceanprotocol_job_details-0.2.5/README.md +0 -52
  11. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/.gitignore +0 -0
  12. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/LICENSE +0 -0
  13. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/__init__.py +0 -0
  14. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/loaders/__init__.py +0 -0
  15. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/loaders/impl/__init__.py +0 -0
  16. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/loaders/impl/job_details.py +0 -0
  17. {oceanprotocol_job_details-0.2.5 → oceanprotocol_job_details-0.2.7}/oceanprotocol_job_details/loaders/loader.py +0 -0
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.4
2
+ Name: oceanprotocol-job-details
3
+ Version: 0.2.7
4
+ Summary: A Python package to get details from OceanProtocol jobs
5
+ Project-URL: Homepage, https://github.com/AgrospAI/oceanprotocol-job-details
6
+ Project-URL: Issues, https://github.com/AgrospAI/oceanprotocol-job-details/issues
7
+ Author-email: Agrospai <agrospai@udl.cat>, Christian López García <christian.lopez@udl.cat>
8
+ License: Copyright 2025 Agrospai
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ License-File: LICENSE
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: dataclasses-json>=0.6.7
21
+ Requires-Dist: dependency-injector>=4.48.2
22
+ Requires-Dist: orjson>=3.11.3
23
+ Description-Content-Type: text/markdown
24
+
25
+ A Python package to get details from OceanProtocol jobs
26
+
27
+ ---
28
+
29
+ ## Installation
30
+
31
+ ```
32
+ pip install oceanprotocol-job-details
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ As a simple library, we only need to import `JobDetails` and load it, it will:
38
+
39
+ 1. Fetch the needed parameters to populate the `JobDetails` instance from the environment variables or use the passed values to the `load()` method.
40
+ 1. Look for the files corresponding to the passed DIDs in the filesystem according to the [Ocean Protocol Structure](#oceanprotocol-structure) and load them into the `JobDetails` instance.
41
+
42
+
43
+ ### Minimal Example
44
+
45
+ ```python
46
+ from oceanprotocol_job_details import JobDetails
47
+
48
+ job_details = JobDetails.load()
49
+ ```
50
+
51
+ ### Custom Input Parameters
52
+
53
+ If our algorithm has custom input parameters and we want to load them into our algorithm, we can do it as follows:
54
+
55
+ ```python
56
+ from dataclasses import dataclass
57
+ from oceanprotocol_job_details import JobDetails
58
+
59
+
60
+ @dataclass
61
+ class InputParameters:
62
+ foobar: str
63
+
64
+
65
+ job_details = JobDetails[InputParameters].load(InputParameters)
66
+
67
+ # Usage
68
+ job_details.input_parameters.foobar
69
+ ```
70
+
71
+ ```python
72
+ from dataclasses import dataclass
73
+ from oceanprotocol_job_details import JobDetails
74
+
75
+
76
+ @dataclass
77
+ class Foo:
78
+ bar: str
79
+
80
+
81
+ @dataclass
82
+ class InputParameters:
83
+ # Allows for nested types
84
+ foo: Foo
85
+
86
+
87
+ job_details = JobDetails[InputParameters].load(InputParameters)
88
+
89
+ # Usage
90
+ job_details.input_parameters.foo.bar
91
+ ```
92
+
93
+ The values to fill the custom `InputParameters` will be parsed from the `algoCustomData.json` located next to the input data directories.
94
+
95
+ ### Iterating Input Files the clean way
96
+
97
+ ```python
98
+ from oceanprotocol_job_details import JobDetails
99
+
100
+
101
+ job_details = JobDetails.load()
102
+
103
+ for idx, file_path in job_details.next_file():
104
+ ...
105
+
106
+ # Or if you just want one file path
107
+ _, file_path = job_details.next_file()
108
+ ```
109
+
110
+ ## OceanProtocol Structure
111
+
112
+ ```bash
113
+ data # Root /data directory
114
+ ├── ddos # Contains the loaded dataset's DDO
115
+ │ ├── 17feb...e42 # DDO file
116
+ │ └── ... # One DDO per loaded dataset
117
+ ├── inputs # Datasets dir
118
+ │ ├── 17feb...e42 # Dir holding the data of its name DID, contains files named 0..X
119
+ │ │ └── 0 # Data file
120
+ │ └── algoCustomData.json # Custom algorithm input data
121
+ ├── logs # Algorithm output logs dir
122
+ └── outputs # Algorithm output files dir
123
+ ```
124
+
125
+ > **_Note:_** Even though it's possible that the algorithm is passed multiple datasets, right now the implementation only allows to use **one dataset** per algorithm execution, so **normally** the executing job will only have **one ddo**, **one dir** inside inputs, and **one data file** named `0`.
@@ -0,0 +1,101 @@
1
+ A Python package to get details from OceanProtocol jobs
2
+
3
+ ---
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ pip install oceanprotocol-job-details
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ As a simple library, we only need to import `JobDetails` and load it, it will:
14
+
15
+ 1. Fetch the needed parameters to populate the `JobDetails` instance from the environment variables or use the passed values to the `load()` method.
16
+ 1. Look for the files corresponding to the passed DIDs in the filesystem according to the [Ocean Protocol Structure](#oceanprotocol-structure) and load them into the `JobDetails` instance.
17
+
18
+
19
+ ### Minimal Example
20
+
21
+ ```python
22
+ from oceanprotocol_job_details import JobDetails
23
+
24
+ job_details = JobDetails.load()
25
+ ```
26
+
27
+ ### Custom Input Parameters
28
+
29
+ If our algorithm has custom input parameters and we want to load them into our algorithm, we can do it as follows:
30
+
31
+ ```python
32
+ from dataclasses import dataclass
33
+ from oceanprotocol_job_details import JobDetails
34
+
35
+
36
+ @dataclass
37
+ class InputParameters:
38
+ foobar: str
39
+
40
+
41
+ job_details = JobDetails[InputParameters].load(InputParameters)
42
+
43
+ # Usage
44
+ job_details.input_parameters.foobar
45
+ ```
46
+
47
+ ```python
48
+ from dataclasses import dataclass
49
+ from oceanprotocol_job_details import JobDetails
50
+
51
+
52
+ @dataclass
53
+ class Foo:
54
+ bar: str
55
+
56
+
57
+ @dataclass
58
+ class InputParameters:
59
+ # Allows for nested types
60
+ foo: Foo
61
+
62
+
63
+ job_details = JobDetails[InputParameters].load(InputParameters)
64
+
65
+ # Usage
66
+ job_details.input_parameters.foo.bar
67
+ ```
68
+
69
+ The values to fill the custom `InputParameters` will be parsed from the `algoCustomData.json` located next to the input data directories.
70
+
71
+ ### Iterating Input Files the clean way
72
+
73
+ ```python
74
+ from oceanprotocol_job_details import JobDetails
75
+
76
+
77
+ job_details = JobDetails.load()
78
+
79
+ for idx, file_path in job_details.next_file():
80
+ ...
81
+
82
+ # Or if you just want one file path
83
+ _, file_path = job_details.next_file()
84
+ ```
85
+
86
+ ## OceanProtocol Structure
87
+
88
+ ```bash
89
+ data # Root /data directory
90
+ ├── ddos # Contains the loaded dataset's DDO
91
+ │ ├── 17feb...e42 # DDO file
92
+ │ └── ... # One DDO per loaded dataset
93
+ ├── inputs # Datasets dir
94
+ │ ├── 17feb...e42 # Dir holding the data of its name DID, contains files named 0..X
95
+ │ │ └── 0 # Data file
96
+ │ └── algoCustomData.json # Custom algorithm input data
97
+ ├── logs # Algorithm output logs dir
98
+ └── outputs # Algorithm output files dir
99
+ ```
100
+
101
+ > **_Note:_** Even though it's possible that the algorithm is passed multiple datasets, right now the implementation only allows to use **one dataset** per algorithm execution, so **normally** the executing job will only have **one ddo**, **one dir** inside inputs, and **one data file** named `0`.
@@ -20,6 +20,7 @@ class Container(containers.DeclarativeContainer):
20
20
  dids=config.dids,
21
21
  transformation_did=config.transformation_did,
22
22
  paths=paths,
23
+ logger=config.logger,
23
24
  )
24
25
 
25
26
  files = providers.Factory(
@@ -28,5 +28,5 @@ class DDOLoader:
28
28
  ddos = []
29
29
  for path in self._ddo_paths:
30
30
  with open(path, "r") as f:
31
- ddos.append(DDO.from_json(f.read())) # type: ignore
31
+ ddos.append(DDO.from_json(f.read()))
32
32
  return ddos
@@ -2,7 +2,8 @@ from __future__ import annotations
2
2
 
3
3
  import json
4
4
  from dataclasses import InitVar, dataclass, field
5
- from typing import TYPE_CHECKING, Sequence, final
5
+ from logging import Logger
6
+ from typing import TYPE_CHECKING, final
6
7
 
7
8
  from oceanprotocol_job_details.paths import Paths
8
9
 
@@ -23,7 +24,10 @@ class FilesLoader:
23
24
  paths: Paths
24
25
  """Path configurations of the project"""
25
26
 
26
- _dids: Sequence[str] = field(init=False)
27
+ logger: Logger
28
+ """Logger to use"""
29
+
30
+ _dids: str = field(init=False)
27
31
  _transformation_did: str = field(init=False)
28
32
 
29
33
  def __post_init__(
@@ -31,11 +35,17 @@ class FilesLoader:
31
35
  dids: str | None,
32
36
  transformation_did: str | None,
33
37
  ) -> None:
34
- assert dids, "Missing DIDs"
35
- assert transformation_did, "Missing transformation DID"
38
+ def _load_dids(dids, logger):
39
+ if dids:
40
+ return json.loads(dids)
41
+
42
+ logger.info("Missing DIDS, Inferring DIDS from input DDOs")
43
+ return [f.parts[-1] for f in self.paths.ddos.iterdir()]
36
44
 
37
- object.__setattr__(self, "_dids", json.loads(dids))
38
45
  object.__setattr__(self, "_transformation_did", transformation_did)
46
+ object.__setattr__(self, "_dids", _load_dids(dids, self.logger))
47
+
48
+ assert self._dids, "Missing input DIDs"
39
49
 
40
50
  def load(self) -> Files:
41
51
  from oceanprotocol_job_details.ocean import DIDPaths, Files
@@ -1,9 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
- import logging
4
3
  import os
5
4
  from dataclasses import dataclass, field
6
5
  from functools import cached_property
6
+ from logging import Logger, getLogger
7
7
  from pathlib import Path
8
8
  from typing import (
9
9
  Any,
@@ -24,14 +24,7 @@ from dataclasses_json import dataclass_json
24
24
  from oceanprotocol_job_details.di import Container
25
25
  from oceanprotocol_job_details.paths import Paths
26
26
 
27
- T = TypeVar("T")
28
-
29
- logging.basicConfig(
30
- level=logging.INFO,
31
- format="%(asctime)s [%(threadName)s] [%(levelname)s] %(message)s",
32
- handlers=[logging.StreamHandler()],
33
- )
34
- logger = logging.getLogger(__name__)
27
+ InputParemetersT = TypeVar("InputParemetersT")
35
28
 
36
29
 
37
30
  @dataclass_json
@@ -234,7 +227,7 @@ class _EmptyJobDetails: ...
234
227
  @final
235
228
  @dataclass_json
236
229
  @dataclass(frozen=True)
237
- class JobDetails(Generic[T]):
230
+ class JobDetails(Generic[InputParemetersT]):
238
231
  files: Files
239
232
  """The input filepaths"""
240
233
 
@@ -245,7 +238,7 @@ class JobDetails(Generic[T]):
245
238
  """Configuration paths"""
246
239
 
247
240
  # Store the type explicitly to avoid issues
248
- _type: Type[T] = field(repr=False)
241
+ _type: Type[InputParemetersT] = field(repr=False)
249
242
 
250
243
  secret: str | None = None
251
244
  """Shh it's a secret"""
@@ -260,8 +253,8 @@ class JobDetails(Generic[T]):
260
253
  yield (idx, file)
261
254
 
262
255
  @cached_property
263
- def input_parameters(self) -> T:
264
- """Read the input parameters and return them in an instance of the dataclass T"""
256
+ def input_parameters(self) -> InputParemetersT:
257
+ """Read the input parameters and return them in an instance of the dataclass InputParemetersT"""
265
258
 
266
259
  with open(self.paths.algorithm_custom_parameters, "r") as f:
267
260
  raw = f.read().strip()
@@ -281,13 +274,14 @@ class JobDetails(Generic[T]):
281
274
  @classmethod
282
275
  def load(
283
276
  cls,
284
- _type: Type[T] | None = None,
277
+ _type: Type[InputParemetersT] | None = None,
285
278
  *,
286
279
  base_dir: str | None = None,
287
280
  dids: str | None = None,
288
281
  transformation_did: str | None = None,
289
282
  secret: str | None = None,
290
- ) -> JobDetails[T]:
283
+ logger: Logger | None = None,
284
+ ) -> JobDetails[InputParemetersT]:
291
285
  """Load a JobDetails instance that holds the runtime details.
292
286
 
293
287
  Loading it will check the following:
@@ -299,7 +293,6 @@ class JobDetails(Generic[T]):
299
293
  - DIDS: The DIDs of the inputs
300
294
  - TRANSFORMATION_DID: The DID of the transformation algorithm
301
295
  - SECRET (optional): A really secret secret
302
-
303
296
  """
304
297
 
305
298
  if _type is None:
@@ -309,10 +302,11 @@ class JobDetails(Generic[T]):
309
302
  container.config.from_dict(
310
303
  {
311
304
  "base_dir": base_dir or os.environ.get("BASE_DIR", None),
312
- "dids": dids or os.environ.get("DIDS"),
305
+ "dids": dids or os.environ.get("DIDS", None),
313
306
  "transformation_did": transformation_did
314
- or os.environ.get("TRANSFORMATION_DID"),
315
- "secret": secret or os.environ.get("SECRET"),
307
+ or os.environ.get("TRANSFORMATION_DID", None),
308
+ "secret": secret or os.environ.get("SECRET", None),
309
+ "logger": logger or getLogger(__name__),
316
310
  }
317
311
  )
318
312
 
@@ -10,8 +10,8 @@ class Paths:
10
10
 
11
11
  _base: Path = field(init=False)
12
12
 
13
- def __post_init__(self, base_dir: Path | None) -> None:
14
- self._base = base_dir or Path("/data")
13
+ def __post_init__(self, base_dir: str | Path | None) -> None:
14
+ self._base = Path(base_dir) if base_dir else Path("/data")
15
15
 
16
16
  @property
17
17
  def data(self) -> Path:
@@ -1,8 +1,9 @@
1
1
  [project]
2
2
  name = "oceanprotocol-job-details"
3
- version = "0.2.5"
3
+ version = "0.2.7"
4
4
  description = "A Python package to get details from OceanProtocol jobs"
5
5
  authors = [
6
+ { name = "Agrospai", email = "agrospai@udl.cat" },
6
7
  { name = "Christian López García", email = "christian.lopez@udl.cat" },
7
8
  ]
8
9
  requires-python = ">=3.10"
@@ -1,76 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: oceanprotocol-job-details
3
- Version: 0.2.5
4
- Summary: A Python package to get details from OceanProtocol jobs
5
- Project-URL: Homepage, https://github.com/AgrospAI/oceanprotocol-job-details
6
- Project-URL: Issues, https://github.com/AgrospAI/oceanprotocol-job-details/issues
7
- Author-email: Christian López García <christian.lopez@udl.cat>
8
- License: Copyright 2025 Agrospai
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
- License-File: LICENSE
16
- Classifier: License :: OSI Approved :: MIT License
17
- Classifier: Operating System :: OS Independent
18
- Classifier: Programming Language :: Python :: 3
19
- Requires-Python: >=3.10
20
- Requires-Dist: dataclasses-json>=0.6.7
21
- Requires-Dist: dependency-injector>=4.48.2
22
- Requires-Dist: orjson>=3.11.3
23
- Description-Content-Type: text/markdown
24
-
25
- A Python package to get details from OceanProtocol jobs
26
-
27
- ---
28
-
29
- ## Installation
30
-
31
- ```
32
- pip install oceanprotocol-job-details
33
- ```
34
-
35
- ## Usage
36
-
37
- As a simple library, we only need to import the main object and use it once:
38
-
39
- ```Python
40
- from oceanprotocol_job_details import JobDetails
41
-
42
- # Having no algorithm input parameters
43
- job_details = JobDetails.load()
44
-
45
- ```
46
-
47
- If our algorithm has custom input parameters and we want to load them into our algorithm, we can do it as follows:
48
-
49
- ```Python
50
-
51
- from dataclasses import dataclass
52
- from oceanprotocol_job_details import JobDetails
53
-
54
-
55
- @dataclass
56
- class InputParameters:
57
- name: str
58
- age: int
59
-
60
-
61
- job_details: JobDetails[InputParameters] = JobDetails.load(InputParameters)
62
-
63
- # Usage (is type hinted)
64
- job_details.input_parameters.name
65
- job_details.input_parameters.age
66
-
67
- ```
68
-
69
- Assumes the directory structure of OceanProtocol algorithms.
70
-
71
- ### Core functionalities
72
-
73
- Given the Ocean Protocol job details structure, parses the passed algorithm parameters into an object to use in your algorithms.
74
-
75
- 1. Input parameter JSON parsing and validation
76
- 1. Metadata and service extraction from the directory structure.
@@ -1,52 +0,0 @@
1
- A Python package to get details from OceanProtocol jobs
2
-
3
- ---
4
-
5
- ## Installation
6
-
7
- ```
8
- pip install oceanprotocol-job-details
9
- ```
10
-
11
- ## Usage
12
-
13
- As a simple library, we only need to import the main object and use it once:
14
-
15
- ```Python
16
- from oceanprotocol_job_details import JobDetails
17
-
18
- # Having no algorithm input parameters
19
- job_details = JobDetails.load()
20
-
21
- ```
22
-
23
- If our algorithm has custom input parameters and we want to load them into our algorithm, we can do it as follows:
24
-
25
- ```Python
26
-
27
- from dataclasses import dataclass
28
- from oceanprotocol_job_details import JobDetails
29
-
30
-
31
- @dataclass
32
- class InputParameters:
33
- name: str
34
- age: int
35
-
36
-
37
- job_details: JobDetails[InputParameters] = JobDetails.load(InputParameters)
38
-
39
- # Usage (is type hinted)
40
- job_details.input_parameters.name
41
- job_details.input_parameters.age
42
-
43
- ```
44
-
45
- Assumes the directory structure of OceanProtocol algorithms.
46
-
47
- ### Core functionalities
48
-
49
- Given the Ocean Protocol job details structure, parses the passed algorithm parameters into an object to use in your algorithms.
50
-
51
- 1. Input parameter JSON parsing and validation
52
- 1. Metadata and service extraction from the directory structure.