oceanprotocol-job-details 0.2.4__py3-none-any.whl → 0.2.6__py3-none-any.whl
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.
- oceanprotocol_job_details/ocean.py +16 -1
- oceanprotocol_job_details-0.2.6.dist-info/METADATA +125 -0
- {oceanprotocol_job_details-0.2.4.dist-info → oceanprotocol_job_details-0.2.6.dist-info}/RECORD +5 -5
- oceanprotocol_job_details-0.2.4.dist-info/METADATA +0 -76
- {oceanprotocol_job_details-0.2.4.dist-info → oceanprotocol_job_details-0.2.6.dist-info}/WHEEL +0 -0
- {oceanprotocol_job_details-0.2.4.dist-info → oceanprotocol_job_details-0.2.6.dist-info}/licenses/LICENSE +0 -0
|
@@ -5,7 +5,17 @@ import os
|
|
|
5
5
|
from dataclasses import dataclass, field
|
|
6
6
|
from functools import cached_property
|
|
7
7
|
from pathlib import Path
|
|
8
|
-
from typing import
|
|
8
|
+
from typing import (
|
|
9
|
+
Any,
|
|
10
|
+
Generator,
|
|
11
|
+
Generic,
|
|
12
|
+
Iterator,
|
|
13
|
+
Optional,
|
|
14
|
+
Sequence,
|
|
15
|
+
Type,
|
|
16
|
+
TypeVar,
|
|
17
|
+
final,
|
|
18
|
+
)
|
|
9
19
|
|
|
10
20
|
import orjson
|
|
11
21
|
from dataclasses_json import config as dc_config
|
|
@@ -244,6 +254,11 @@ class JobDetails(Generic[T]):
|
|
|
244
254
|
if not hasattr(self._type, "__dataclass_fields__"):
|
|
245
255
|
raise TypeError(f"{self._type} is not a dataclass type")
|
|
246
256
|
|
|
257
|
+
def next_path(self) -> Generator[tuple[int, Path], None, None]:
|
|
258
|
+
for idx, did_files in enumerate(self.files):
|
|
259
|
+
for file in did_files.input_files:
|
|
260
|
+
yield (idx, file)
|
|
261
|
+
|
|
247
262
|
@cached_property
|
|
248
263
|
def input_parameters(self) -> T:
|
|
249
264
|
"""Read the input parameters and return them in an instance of the dataclass T"""
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: oceanprotocol-job-details
|
|
3
|
+
Version: 0.2.6
|
|
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`.
|
{oceanprotocol_job_details-0.2.4.dist-info → oceanprotocol_job_details-0.2.6.dist-info}/RECORD
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
oceanprotocol_job_details/__init__.py,sha256=C67wv7fy5ZT5FtbGD-oQeSoLU-x6e2ts-820koFo034,55
|
|
2
2
|
oceanprotocol_job_details/di.py,sha256=j2BvpaGpiQwt9MSiViYPFup4MnzTHm44Zq12_TQ07kY,1180
|
|
3
|
-
oceanprotocol_job_details/ocean.py,sha256
|
|
3
|
+
oceanprotocol_job_details/ocean.py,sha256=uABP0JZdCpd3NrTmfXWGuG8XOEVx680-jjRDV0hHync,7373
|
|
4
4
|
oceanprotocol_job_details/paths.py,sha256=N90IF8OQCBELULGPaBv9yALApa-lC2dsVKXMWLdqa14,851
|
|
5
5
|
oceanprotocol_job_details/loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
oceanprotocol_job_details/loaders/loader.py,sha256=HIzsVKCuGP7ghfM7ppN3ANVybvsA64wr3h8I68mqS6A,195
|
|
@@ -8,7 +8,7 @@ oceanprotocol_job_details/loaders/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JC
|
|
|
8
8
|
oceanprotocol_job_details/loaders/impl/ddo.py,sha256=_xl0PozuvIm0n6jU--Znk6qfw1A6OLBq3SERbDGIF74,844
|
|
9
9
|
oceanprotocol_job_details/loaders/impl/files.py,sha256=oFkA_0Ma5NBgWvVEk_rhyDIDrAam_zjesh0-bxZaIU8,1443
|
|
10
10
|
oceanprotocol_job_details/loaders/impl/job_details.py,sha256=wf0xNAG4tESq57vqkdtMQ8BdiyS91j5f7FL8Gfwbjh4,770
|
|
11
|
-
oceanprotocol_job_details-0.2.
|
|
12
|
-
oceanprotocol_job_details-0.2.
|
|
13
|
-
oceanprotocol_job_details-0.2.
|
|
14
|
-
oceanprotocol_job_details-0.2.
|
|
11
|
+
oceanprotocol_job_details-0.2.6.dist-info/METADATA,sha256=jqQAuRh8p34G3ZIUC23-rfr8Odrw9ByyW5YP5FUyt9g,4507
|
|
12
|
+
oceanprotocol_job_details-0.2.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
13
|
+
oceanprotocol_job_details-0.2.6.dist-info/licenses/LICENSE,sha256=ni3ix7P_GxK1W3VGC4fJ3o6QoCngCEpSuTJwO4nkpbw,1055
|
|
14
|
+
oceanprotocol_job_details-0.2.6.dist-info/RECORD,,
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: oceanprotocol-job-details
|
|
3
|
-
Version: 0.2.4
|
|
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.
|
{oceanprotocol_job_details-0.2.4.dist-info → oceanprotocol_job_details-0.2.6.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|