oceanprotocol-job-details 0.2.6__py3-none-any.whl → 0.2.7__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.
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oceanprotocol-job-details
3
- Version: 0.2.6
3
+ Version: 0.2.7
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
@@ -0,0 +1,14 @@
1
+ oceanprotocol_job_details/__init__.py,sha256=C67wv7fy5ZT5FtbGD-oQeSoLU-x6e2ts-820koFo034,55
2
+ oceanprotocol_job_details/di.py,sha256=PE6FGLRZPLDx-J7FfutCNES7sqpZA8e6jdu4tNe-AjQ,1210
3
+ oceanprotocol_job_details/ocean.py,sha256=t1BP4bdIcNgzEkXuVM7g9Bg0pEz_ljctE2CQEtSPnwA,7431
4
+ oceanprotocol_job_details/paths.py,sha256=o2IwhKO8nxIp03-NXYUhhWC7XPiMjz61AACStZRcJX0,877
5
+ oceanprotocol_job_details/loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ oceanprotocol_job_details/loaders/loader.py,sha256=HIzsVKCuGP7ghfM7ppN3ANVybvsA64wr3h8I68mqS6A,195
7
+ oceanprotocol_job_details/loaders/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ oceanprotocol_job_details/loaders/impl/ddo.py,sha256=SuPvQBc2MS-q0g8BQOfCXPAvMvhl7Vnbq9GHugAU--s,828
9
+ oceanprotocol_job_details/loaders/impl/files.py,sha256=ZiIb-gblgIqU5HBy0mrZwooH-Qu_HSWyaJ3VtBIhJcs,1696
10
+ oceanprotocol_job_details/loaders/impl/job_details.py,sha256=wf0xNAG4tESq57vqkdtMQ8BdiyS91j5f7FL8Gfwbjh4,770
11
+ oceanprotocol_job_details-0.2.7.dist-info/METADATA,sha256=uuxmkYSbZFKGb01Ng_miulyrUv4cx0Djv0Obte575dk,4507
12
+ oceanprotocol_job_details-0.2.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
+ oceanprotocol_job_details-0.2.7.dist-info/licenses/LICENSE,sha256=ni3ix7P_GxK1W3VGC4fJ3o6QoCngCEpSuTJwO4nkpbw,1055
14
+ oceanprotocol_job_details-0.2.7.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- oceanprotocol_job_details/__init__.py,sha256=C67wv7fy5ZT5FtbGD-oQeSoLU-x6e2ts-820koFo034,55
2
- oceanprotocol_job_details/di.py,sha256=j2BvpaGpiQwt9MSiViYPFup4MnzTHm44Zq12_TQ07kY,1180
3
- oceanprotocol_job_details/ocean.py,sha256=uABP0JZdCpd3NrTmfXWGuG8XOEVx680-jjRDV0hHync,7373
4
- oceanprotocol_job_details/paths.py,sha256=N90IF8OQCBELULGPaBv9yALApa-lC2dsVKXMWLdqa14,851
5
- oceanprotocol_job_details/loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- oceanprotocol_job_details/loaders/loader.py,sha256=HIzsVKCuGP7ghfM7ppN3ANVybvsA64wr3h8I68mqS6A,195
7
- oceanprotocol_job_details/loaders/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- oceanprotocol_job_details/loaders/impl/ddo.py,sha256=_xl0PozuvIm0n6jU--Znk6qfw1A6OLBq3SERbDGIF74,844
9
- oceanprotocol_job_details/loaders/impl/files.py,sha256=oFkA_0Ma5NBgWvVEk_rhyDIDrAam_zjesh0-bxZaIU8,1443
10
- oceanprotocol_job_details/loaders/impl/job_details.py,sha256=wf0xNAG4tESq57vqkdtMQ8BdiyS91j5f7FL8Gfwbjh4,770
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,,