oceanprotocol-job-details 0.0.11__py3-none-any.whl → 0.0.12__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.
@@ -6,7 +6,7 @@ from pathlib import Path
6
6
  class _DidKeys:
7
7
  """Common keys inside the DIDs"""
8
8
 
9
- SERVICE: str = "service"
9
+ SERVICES: str = "services"
10
10
  SERVICE_TYPE: str = "type"
11
11
  ATTRIBUTES: str = "attributes"
12
12
  MAIN: str = "main"
@@ -1,4 +1,3 @@
1
- from ctypes import ArgumentError
2
1
  import logging
3
2
  import os
4
3
  from typing import Any, Literal, Mapping, Optional
@@ -14,7 +13,7 @@ logging.basicConfig(
14
13
  handlers=[logging.StreamHandler()],
15
14
  )
16
15
 
17
- _Implementations = Literal["map"]
16
+ _Implementations = Literal["env"]
18
17
 
19
18
 
20
19
  class OceanProtocolJobDetails(Loader[JobDetails]):
@@ -28,33 +27,14 @@ class OceanProtocolJobDetails(Loader[JobDetails]):
28
27
  *args,
29
28
  **kwargs,
30
29
  ):
31
- match implementation.lower():
32
- case "map":
33
- self._loader = lambda: Map(mapper=mapper, keys=keys, *args, **kwargs)
34
- case _:
35
- raise ArgumentError(f"Implementation {implementation} not valid")
30
+ if implementation == "map":
31
+ # As there are not more implementations, we can use the EnvironmentLoader directly
32
+ self._loader = lambda: Map(mapper=mapper, keys=keys, *args, **kwargs)
33
+ else:
34
+ raise NotImplementedError(f"Implementation {implementation} not supported")
36
35
 
37
36
  def load(self) -> JobDetails:
38
37
  return self._loader().load()
39
38
 
40
39
 
41
40
  del _Implementations
42
-
43
-
44
- def _main():
45
- """Main function to test functionalities"""
46
-
47
- # Re-define logging configuration
48
- logging.basicConfig(
49
- level=logging.DEBUG,
50
- format="%(asctime)s [%(threadName)s] [%(levelname)s] %(message)s",
51
- handlers=[logging.StreamHandler()],
52
- force=True,
53
- )
54
-
55
- job_details = OceanProtocolJobDetails().load()
56
- logging.info(f"Loaded job details: {job_details}")
57
-
58
-
59
- if __name__ == "__main__":
60
- _main()
@@ -41,7 +41,10 @@ def _update_paths_from_root(root: Path):
41
41
 
42
42
 
43
43
  def _files_from_service(service):
44
- return service[DidKeys.ATTRIBUTES][DidKeys.MAIN][DidKeys.FILES]
44
+ files = service[DidKeys.FILES]
45
+ if isinstance(files, str):
46
+ return [files]
47
+ return files
45
48
 
46
49
 
47
50
  @final
@@ -60,7 +63,7 @@ class Map(Loader[JobDetails]):
60
63
  def load(self, *args, **kwargs) -> JobDetails:
61
64
  return self._from_dids(self._dids())
62
65
 
63
- def _from_dids(self, dids: Sequence[Path]) -> JobDetails:
66
+ def _from_dids(self, dids: Sequence[str]) -> JobDetails:
64
67
  return JobDetails(
65
68
  dids=dids,
66
69
  files=self._files(dids),
@@ -68,14 +71,14 @@ class Map(Loader[JobDetails]):
68
71
  secret=self._secret(),
69
72
  )
70
73
 
71
- def _dids(self) -> Sequence[Path]:
74
+ def _dids(self) -> Sequence[str]:
72
75
  return loads(self._mapper.get(self._keys.DIDS, []))
73
76
 
74
- def _files(self, dids: Optional[Sequence[Path]]) -> Mapping[str, Sequence[Path]]:
77
+ def _files(self, dids: Optional[Sequence[str]]) -> Mapping[str, Sequence[Path]]:
75
78
  """Iterate through the given DIDs and retrieve their respective filepaths
76
79
 
77
80
  :param dids: dids to read the files from
78
- :type dids: Optional[Sequence[Path]]
81
+ :type dids: Optional[Sequence[str]]
79
82
  :raises FileNotFoundError: if the DDO file does not exist
80
83
  :return: _description_
81
84
  :rtype: Mapping[str, Sequence[Path]]
@@ -84,7 +87,6 @@ class Map(Loader[JobDetails]):
84
87
  files: Mapping[str, Sequence[Path]] = {}
85
88
  for did in dids:
86
89
  # For each given DID, check if the DDO file exists and read its metadata
87
-
88
90
  ddo_path = Paths.DDOS / did
89
91
  do(lambda: ddo_path.exists(), exc=FileNotFoundError("Missing DDO file"))
90
92
 
@@ -93,9 +95,9 @@ class Map(Loader[JobDetails]):
93
95
  if not ddo:
94
96
  continue
95
97
 
96
- for service in do(lambda: ddo[DidKeys.SERVICE], KeyError, default=[]):
97
- if service[DidKeys.SERVICE_TYPE] != ServiceType.METADATA:
98
- continue # Only read the metadata of the services
98
+ for service in do(lambda: ddo[DidKeys.SERVICES], KeyError, default=[]):
99
+ # if service[DidKeys.SERVICE_TYPE] != ServiceType.METADATA:
100
+ # continue # Only read the metadata of the services
99
101
 
100
102
  files_n = do(lambda: len(_files_from_service(service)), KeyError)
101
103
  ddo_path = Paths.INPUTS / did
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oceanprotocol-job-details
3
- Version: 0.0.11
3
+ Version: 0.0.12
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
@@ -1,15 +1,15 @@
1
1
  oceanprotocol_job_details/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- oceanprotocol_job_details/job_details.py,sha256=dlQABSV8TQf66vaeFImyw7c4Nms417pRKiDR9d4qDhY,1668
2
+ oceanprotocol_job_details/job_details.py,sha256=DfdRaoytvfFflp0nAFvCKzEm_fk4aMHHM9mC8Gs1vtU,1250
3
3
  oceanprotocol_job_details/dataclasses/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- oceanprotocol_job_details/dataclasses/constants.py,sha256=EHUhbaFpixtK5Kq2V92gbWg-jxYR-tO6ie4Ntb_FPGQ,836
4
+ oceanprotocol_job_details/dataclasses/constants.py,sha256=GgOxQpw1_9lz4ZBuBKPQwsCBiFWN7wS0ccRQ9yv4oxk,838
5
5
  oceanprotocol_job_details/dataclasses/job_details.py,sha256=jho4PQLyqh1iB6e5wlM9ATSZreqAo7J9hOeFdETSHgo,2311
6
6
  oceanprotocol_job_details/dataclasses/ocean.py,sha256=u4Mc5cHPnJz9oc1a43kkWfwEqRgsFsb-Y3UP2eBpoN4,2480
7
7
  oceanprotocol_job_details/loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  oceanprotocol_job_details/loaders/loader.py,sha256=JwR6OSkzIQQkeeyAU-ad_F89W9WNvoRwvHQY7Q3zIXI,256
9
9
  oceanprotocol_job_details/loaders/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- oceanprotocol_job_details/loaders/impl/map.py,sha256=5DF5HilWhmF_lq4j3VdAbyCbGRPGQPkn_-l7K-TOVmM,4090
10
+ oceanprotocol_job_details/loaders/impl/map.py,sha256=2-NscnF9saL6KTOoPBTh3UIjawvc2OdOwoGuXZpJ00U,4128
11
11
  oceanprotocol_job_details/loaders/impl/utils.py,sha256=rxoG8PrXRSKKDYPZh-wkWOXzMfdWXrkZs0f04OfDCIs,1446
12
- oceanprotocol_job_details-0.0.11.dist-info/METADATA,sha256=nuTtra3JG0LP5wcG5PkdC5fdYGirZbQhDE6TRAdajlw,3382
13
- oceanprotocol_job_details-0.0.11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- oceanprotocol_job_details-0.0.11.dist-info/licenses/LICENSE,sha256=ni3ix7P_GxK1W3VGC4fJ3o6QoCngCEpSuTJwO4nkpbw,1055
15
- oceanprotocol_job_details-0.0.11.dist-info/RECORD,,
12
+ oceanprotocol_job_details-0.0.12.dist-info/METADATA,sha256=nNXagh8zuofDlgKUaY29XWkrghqcX-Rp1rxIn-Y-pNo,3382
13
+ oceanprotocol_job_details-0.0.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ oceanprotocol_job_details-0.0.12.dist-info/licenses/LICENSE,sha256=ni3ix7P_GxK1W3VGC4fJ3o6QoCngCEpSuTJwO4nkpbw,1055
15
+ oceanprotocol_job_details-0.0.12.dist-info/RECORD,,