oceanprotocol-job-details 0.3.9__py3-none-any.whl → 0.3.13__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.
@@ -1,4 +1,5 @@
1
1
  from .helpers import create_container, load_job_details
2
2
  from .ocean import JobDetails
3
+ from .executors import run_in_executor
3
4
 
4
- __all__ = [JobDetails, load_job_details, create_container] # type: ignore
5
+ __all__ = [JobDetails, load_job_details, create_container, run_in_executor] # type: ignore
@@ -1,4 +1,3 @@
1
- from types import NoneType
2
1
  from typing import Generic, TypeVar
3
2
  from dependency_injector import containers, providers
4
3
  from pydantic import BaseModel
@@ -1,7 +1,7 @@
1
1
  # mypy: disable-error-code=explicit-any
2
2
  from dataclasses import InitVar, dataclass, field
3
3
  from pathlib import Path
4
- from typing import Generator, List, Optional, Sequence, TypeAlias, TypeVar
4
+ from typing import Generator, List, Optional, Sequence, TypeAlias
5
5
 
6
6
  from pydantic import BaseModel, ConfigDict, Field, JsonValue
7
7
 
@@ -0,0 +1,25 @@
1
+ import asyncio
2
+ import inspect
3
+ from typing import Any, Callable, Coroutine, TypeVar
4
+
5
+ T = TypeVar("T")
6
+
7
+
8
+ async def run_in_executor(
9
+ obj: Callable[..., T]
10
+ | Callable[..., Coroutine[Any, Any, T]]
11
+ | Coroutine[Any, Any, T],
12
+ *args,
13
+ **kwargs,
14
+ ) -> T:
15
+ if inspect.iscoroutinefunction(obj):
16
+ return await obj(*args, **kwargs)
17
+
18
+ if inspect.iscoroutine(obj):
19
+ return await obj
20
+
21
+ if callable(obj):
22
+ loop = asyncio.get_running_loop()
23
+ return await loop.run_in_executor(None, obj, *args, **kwargs)
24
+
25
+ return obj
@@ -3,13 +3,13 @@ from __future__ import annotations
3
3
  import asyncio
4
4
  from functools import cached_property
5
5
  from pathlib import Path
6
- from types import NoneType
7
6
  from typing import Generator, Generic, Tuple, Type, TypeVar, final
8
7
 
9
8
  import aiofiles
10
9
  from pydantic import BaseModel, ConfigDict, Secret
11
10
 
12
11
  from oceanprotocol_job_details.domain import DDO, Files, Paths
12
+ from oceanprotocol_job_details.executors import run_in_executor
13
13
 
14
14
  InputParametersT = TypeVar("InputParametersT", BaseModel, None)
15
15
 
@@ -24,6 +24,8 @@ class JobDetails(BaseModel, Generic[InputParametersT]): # type: ignore[explicit
24
24
 
25
25
  model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)
26
26
 
27
+ _input_parameters: InputParametersT | None = None
28
+
27
29
  def inputs(self) -> Generator[Tuple[int, Path], None, None]:
28
30
  yield from (
29
31
  (idx, file)
@@ -31,11 +33,13 @@ class JobDetails(BaseModel, Generic[InputParametersT]): # type: ignore[explicit
31
33
  for file in files.input_files
32
34
  )
33
35
 
34
- @cached_property
35
- def input_parameters(self) -> InputParametersT | None:
36
- return asyncio.run(self.ainput_parameters())
36
+ async def input_parameters(self) -> InputParametersT:
37
+ if self._input_parameters is None:
38
+ input_parameters = await self.ainput_parameters()
39
+ object.__setattr__(self, "_input_parameters", input_parameters)
40
+ return self._input_parameters
37
41
 
38
- async def ainput_parameters(self) -> InputParametersT | None:
42
+ async def ainput_parameters(self) -> InputParametersT:
39
43
  if self.input_type is None:
40
44
  return None
41
45
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oceanprotocol-job-details
3
- Version: 0.3.9
3
+ Version: 0.3.13
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
@@ -32,9 +32,7 @@ A Python package to get details from OceanProtocol jobs
32
32
 
33
33
  ```bash
34
34
  pip install oceanprotocol-job-details
35
- ```
36
-
37
- ```bash
35
+ #or
38
36
  uv add oceanprotocol-job-details
39
37
  ```
40
38
 
@@ -74,8 +72,9 @@ class InputParameters(BaseModel):
74
72
  job_details = load_job_details({"base_dir": "...", "transformation_did": "..."}, InputParameters)
75
73
 
76
74
  # Usage
77
- job_details.input_parameters.foo
78
- job_details.input_parameters.foo.bar
75
+ parameters = await job_details.input_parameters()
76
+ parameters.foo
77
+ parameters.foo.bar
79
78
  ```
80
79
 
81
80
  The values to fill the custom `InputParameters` will be parsed from the `algoCustomData.json` located next to the input data directories.
@@ -1,8 +1,9 @@
1
- oceanprotocol_job_details/__init__.py,sha256=nJMrZsEC5F1n9WF-v5QV095Yyc8UkhFw0AzD9o7X0IE,162
2
- oceanprotocol_job_details/di.py,sha256=URBCcwla3pBKt4hWhRwG7s-Ib_KzoBk2-EtLzQOyAyM,1343
3
- oceanprotocol_job_details/domain.py,sha256=2_USbeA_7VIEYS8DVb2MW6dCZasjiqIxQaGUnNUKspY,3851
1
+ oceanprotocol_job_details/__init__.py,sha256=sq_C8Ey4_4oHiX9cO1wne7ZsWqs86WWgHfKQ5PMwwak,218
2
+ oceanprotocol_job_details/di.py,sha256=H4_n9NrNuRB2s9uarSkwDYzjD1i7sV8dySRfHt21QWM,1316
3
+ oceanprotocol_job_details/domain.py,sha256=ifw-hKFAJj0Gl_wJuH-51LQx4KPsCyEVDsT10xg9uBw,3842
4
+ oceanprotocol_job_details/executors.py,sha256=Csc1MaUf0-Ve4Wp80qIanL7reRTT2qA3W3QrSE2jQO4,556
4
5
  oceanprotocol_job_details/helpers.py,sha256=ABm3oIRwPd-4XeCOIszCbfL2wkUJqVJJ2bqy3hR4jyw,1064
5
- oceanprotocol_job_details/ocean.py,sha256=ocoI4OO8A5_SovXbASVucFq4W-tJr_M4C67UbS4aSF8,1473
6
+ oceanprotocol_job_details/ocean.py,sha256=kq7tAHJ36s7piJ_WpXVaTmSAMe87tuwHDeMQB-xS0T4,1702
6
7
  oceanprotocol_job_details/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
8
  oceanprotocol_job_details/settings.py,sha256=o_1Hn2vl5hMk7bAkdS7GjE4nKOAyHm7dScO2_o2sPuY,1345
8
9
  oceanprotocol_job_details/loaders/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -11,7 +12,7 @@ oceanprotocol_job_details/loaders/impl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JC
11
12
  oceanprotocol_job_details/loaders/impl/ddo.py,sha256=XthrQFhmP85XSVzVjBlLePtTowGR3BAsmVp3jngiQ08,668
12
13
  oceanprotocol_job_details/loaders/impl/files.py,sha256=Y2vFBT2T9w9zrdpmf550-LQJxwtNPUGa0UU6bBzk9AU,1145
13
14
  oceanprotocol_job_details/loaders/impl/job_details.py,sha256=QwlUaG9KozkI1wX66oDTPg4TjGkvSsi8O-TctF6eWvo,724
14
- oceanprotocol_job_details-0.3.9.dist-info/METADATA,sha256=_6PvqdSeGHboxzX9RryS7-vnzPdnAWlozE290s0UCr4,4503
15
- oceanprotocol_job_details-0.3.9.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
16
- oceanprotocol_job_details-0.3.9.dist-info/licenses/LICENSE,sha256=ni3ix7P_GxK1W3VGC4fJ3o6QoCngCEpSuTJwO4nkpbw,1055
17
- oceanprotocol_job_details-0.3.9.dist-info/RECORD,,
15
+ oceanprotocol_job_details-0.3.13.dist-info/METADATA,sha256=9jFrlbS9oWNQXrHj_jY3ia16bA3HvdBeMt6nMdUguHk,4509
16
+ oceanprotocol_job_details-0.3.13.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
17
+ oceanprotocol_job_details-0.3.13.dist-info/licenses/LICENSE,sha256=ni3ix7P_GxK1W3VGC4fJ3o6QoCngCEpSuTJwO4nkpbw,1055
18
+ oceanprotocol_job_details-0.3.13.dist-info/RECORD,,