oceanprotocol-job-details 0.0.1__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 (27) hide show
  1. oceanprotocol_job_details-0.0.1/LICENSE +7 -0
  2. oceanprotocol_job_details-0.0.1/PKG-INFO +31 -0
  3. oceanprotocol_job_details-0.0.1/README.md +9 -0
  4. oceanprotocol_job_details-0.0.1/pyproject.toml +31 -0
  5. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/__init__.py +0 -0
  6. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/__init__.py +0 -0
  7. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/__pycache__/__init__.cpython-313.pyc +0 -0
  8. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/__pycache__/__init__.cpython-39.pyc +0 -0
  9. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/__pycache__/constants.cpython-313.pyc +0 -0
  10. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/__pycache__/constants.cpython-39.pyc +0 -0
  11. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/__pycache__/job_details.cpython-313.pyc +0 -0
  12. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/__pycache__/job_details.cpython-39.pyc +0 -0
  13. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/constants.py +38 -0
  14. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/dataclasses/job_details.py +35 -0
  15. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/job_details.py +20 -0
  16. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/__init__.py +0 -0
  17. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/__pycache__/__init__.cpython-313.pyc +0 -0
  18. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
  19. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/__pycache__/loader.cpython-313.pyc +0 -0
  20. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/__pycache__/loader.cpython-39.pyc +0 -0
  21. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/impl/__init__.py +0 -0
  22. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/impl/__pycache__/__init__.cpython-313.pyc +0 -0
  23. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/impl/__pycache__/__init__.cpython-39.pyc +0 -0
  24. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/impl/__pycache__/environment.cpython-313.pyc +0 -0
  25. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/impl/__pycache__/environment.cpython-39.pyc +0 -0
  26. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/impl/environment.py +98 -0
  27. oceanprotocol_job_details-0.0.1/src/oceanprotocol_job_details/loaders/loader.py +15 -0
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Agrospai
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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.
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.3
2
+ Name: oceanprotocol-job-details
3
+ Version: 0.0.1
4
+ Summary: A Python package to get details from OceanProtocol jobs
5
+ License: Copyright 2025 Agrospai
6
+
7
+ 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:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+ 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.
12
+ Author: Christian López García
13
+ Author-email: christian.lopez@udl.cat
14
+ Requires-Python: >=3.9
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Requires-Dist: pytest (>=8.3.4,<9.0.0)
19
+ Project-URL: Homepage, https://github.com/AgrospAI/oceanprotocol-job-details
20
+ Project-URL: Issues, https://github.com/AgrospAI/oceanprotocol-job-details/issues
21
+ Description-Content-Type: text/markdown
22
+
23
+ A Python package to get details from OceanProtocol jobs
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ ```
30
+ pip install oceanprotocol-job-details
31
+ ```
@@ -0,0 +1,9 @@
1
+ A Python package to get details from OceanProtocol jobs
2
+
3
+ ---
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ pip install oceanprotocol-job-details
9
+ ```
@@ -0,0 +1,31 @@
1
+ [project]
2
+ license = { file = "LICENSE" }
3
+
4
+ name = "oceanprotocol-job-details"
5
+ version = "0.0.1"
6
+ authors = [
7
+ { name = "Christian López García", email = "christian.lopez@udl.cat" },
8
+ ]
9
+ description = "A Python package to get details from OceanProtocol jobs"
10
+ readme = "README.md"
11
+ requires-python = ">=3.9"
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "Operating System :: OS Independent",
15
+ "License :: OSI Approved :: MIT License",
16
+ ]
17
+
18
+ [project.urls]
19
+ Homepage = "https://github.com/AgrospAI/oceanprotocol-job-details"
20
+ Issues = "https://github.com/AgrospAI/oceanprotocol-job-details/issues"
21
+
22
+ [build-system]
23
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
24
+ build-backend = "poetry.core.masonry.api"
25
+
26
+ [tool.poetry]
27
+ packages = [{ include = "src/oceanprotocol_job_details" }]
28
+
29
+ [tool.poetry.dependencies]
30
+ python = ">3.9"
31
+ pytest = "^8.3.4"
@@ -0,0 +1,38 @@
1
+ from dataclasses import dataclass
2
+ from pathlib import Path
3
+
4
+
5
+ @dataclass(frozen=True)
6
+ class _DidKeys:
7
+ """Common keys inside the DIDs"""
8
+
9
+ SERVICE: str = "service"
10
+ SERVICE_TYPE: str = "type"
11
+ ATTRIBUTES: str = "attributes"
12
+ MAIN: str = "main"
13
+ FILES: str = "files"
14
+
15
+
16
+ @dataclass(frozen=True)
17
+ class _ServiceType:
18
+ """Service types inside the DIDs"""
19
+
20
+ METADATA: str = "metadata"
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class _Paths:
25
+ """Common paths used in the Ocean Protocol directories"""
26
+
27
+ DATA: Path = Path("data")
28
+ INPUTS: Path = DATA / "inputs"
29
+ DDOS: Path = DATA / "ddos"
30
+ OUTPUTS: Path = DATA / "outputs"
31
+ LOGS: Path = DATA / "logs"
32
+
33
+
34
+ DidKeys = _DidKeys()
35
+ ServiceType = _ServiceType()
36
+ Paths = _Paths()
37
+
38
+ del _DidKeys, _ServiceType, _Paths
@@ -0,0 +1,35 @@
1
+ from dataclasses import dataclass
2
+ from pathlib import Path
3
+ from typing import Any, Mapping, Optional, Sequence
4
+
5
+
6
+ @dataclass(frozen=True)
7
+ class Algorithm:
8
+ did: str
9
+ """The DID of the algorithm used to process the data"""
10
+
11
+ ddo: Path
12
+ """The DDO path of the algorithm used to process the data"""
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class JobDetails:
17
+ """Details of the current job, such as the used inputs and algorithm"""
18
+
19
+ root: Path
20
+ """The root folder of the Ocean Protocol directories"""
21
+
22
+ dids: Optional[Sequence[Path]]
23
+ """Identifiers for the inputs"""
24
+
25
+ metadata: Mapping[str, Any]
26
+ """TODO: To define"""
27
+
28
+ files: Mapping[str, Sequence[Path]]
29
+ """Paths to the input files"""
30
+
31
+ secret: Optional[str]
32
+ """The secret used to process the data"""
33
+
34
+ algorithm: Optional[Algorithm]
35
+ """Details of the used algorithm"""
@@ -0,0 +1,20 @@
1
+ from typing import Literal, Optional
2
+ from src.oceanprotocol_job_details.dataclasses.job_details import JobDetails
3
+ from src.oceanprotocol_job_details.loaders.loader import Loader
4
+ from src.oceanprotocol_job_details.loaders.impl.environment import EnvironmentLoader
5
+
6
+ _Implementations = Literal["env"]
7
+
8
+
9
+ class OceanProtocolJobDetails(Loader[JobDetails]):
10
+ """Decorator that loads the JobDetails from the given implementation"""
11
+
12
+ def __init__(self, implementation: Optional[_Implementations], *args, **kwargs):
13
+ # As there are not more implementations, we can use the EnvironmentLoader directly
14
+ self._loader = lambda: EnvironmentLoader(*args, **kwargs)
15
+
16
+ def load(self) -> JobDetails:
17
+ return self._loader().load()
18
+
19
+
20
+ del _Implementations
@@ -0,0 +1,98 @@
1
+ """Loads the current Job Details from the environment variables, could be abstracted to a more general 'mapper loader' but won't, since right now it fits our needs"""
2
+
3
+ import os
4
+ from collections.abc import Mapping, Sequence
5
+ from dataclasses import dataclass
6
+ from json import load, loads
7
+ from pathlib import Path
8
+ from typing import Optional, final
9
+
10
+ from src.oceanprotocol_job_details.dataclasses.constants import (
11
+ DidKeys,
12
+ Paths,
13
+ ServiceType,
14
+ )
15
+ from src.oceanprotocol_job_details.dataclasses.job_details import Algorithm, JobDetails
16
+ from src.oceanprotocol_job_details.loaders.loader import Loader
17
+
18
+
19
+ @dataclass(frozen=True)
20
+ class _Keys:
21
+ """Environment keys passed to the algorithm"""
22
+
23
+ ROOT: str = "ROOT_FOLDER"
24
+ SECRET: str = "secret"
25
+ ALGORITHM: str = "TRANSFORMATION_DID"
26
+ DIDS: str = "DIDS"
27
+
28
+
29
+ Keys = _Keys()
30
+ del _Keys
31
+
32
+
33
+ @final
34
+ class EnvironmentLoader(Loader[JobDetails]):
35
+ """Loads the current Job Details from the environment variables"""
36
+
37
+ def __init__(self, mapper: Mapping[str, str] = os.environ):
38
+ super().__init__()
39
+ self.mapper = mapper
40
+
41
+ def load(self, *args, **kwargs) -> JobDetails:
42
+ root, dids = self._root(), self._dids()
43
+
44
+ return JobDetails(
45
+ root=root,
46
+ dids=dids,
47
+ metadata=self._metadata(),
48
+ files=self._files(root, dids),
49
+ algorithm=self._algorithm(root=root),
50
+ secret=self._secret(),
51
+ )
52
+
53
+ def _root(self) -> Path:
54
+ return Path(self.mapper.get(Keys.ROOT, ""))
55
+
56
+ def _dids(self) -> Sequence[str]:
57
+ return loads(self.mapper.get(Keys.DIDS)) if Keys.DIDS in self.mapper else []
58
+
59
+ def _files(
60
+ self,
61
+ root: Path,
62
+ dids: Optional[Sequence[Path]],
63
+ ) -> Mapping[str, Sequence[Path]]:
64
+ files: Mapping[str, Sequence[Path]] = {}
65
+ for did in dids:
66
+ # Retrieve DDO from disk
67
+ file = root / Paths.DDOS / did
68
+ with open(file, "r") as f:
69
+ ddo = load(f)
70
+ for service in ddo[DidKeys.SERVICE]:
71
+ if service[DidKeys.SERVICE_TYPE] == ServiceType.METADATA:
72
+ base_path = root / Paths.INPUTS / did
73
+ files[did] = [
74
+ base_path / str(idx)
75
+ for idx in range(
76
+ len(
77
+ service[DidKeys.ATTRIBUTES][DidKeys.MAIN][
78
+ DidKeys.FILES
79
+ ]
80
+ )
81
+ )
82
+ ]
83
+ return files
84
+
85
+ def _metadata(self) -> Mapping[str, str]:
86
+ return {}
87
+
88
+ def _algorithm(self, root: Path) -> Algorithm:
89
+ did = self.mapper.get(Keys.ALGORITHM, None)
90
+ if not did:
91
+ return None
92
+ return Algorithm(
93
+ did=did,
94
+ ddo=root / Paths.DDOS / did,
95
+ )
96
+
97
+ def _secret(self) -> str:
98
+ return self.mapper.get(Keys.SECRET, "")
@@ -0,0 +1,15 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import Generic, TypeVar
3
+
4
+
5
+ T = TypeVar("T")
6
+
7
+
8
+ class Loader(ABC, Generic[T]):
9
+ @abstractmethod
10
+ def load(self, *args, **kwargs) -> T:
11
+ """Load an instance of the given type"""
12
+ pass
13
+
14
+
15
+ del T