digitalhub 0.13.2__py3-none-any.whl → 0.13.4__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.

Potentially problematic release.


This version of digitalhub might be problematic. Click here for more details.

@@ -8,7 +8,9 @@ import os
8
8
  import typing
9
9
  from pathlib import Path
10
10
 
11
+ from digitalhub.entities._commons.enums import EntityTypes, ApiCategories, BackendOperations
11
12
  from digitalhub.runtimes.enums import RuntimeEnvVar
13
+ from digitalhub.utils.exceptions import BackendError
12
14
 
13
15
  if typing.TYPE_CHECKING:
14
16
  from digitalhub.entities.project._base.entity import Project
@@ -58,7 +60,18 @@ class Context:
58
60
  """
59
61
  run_id = os.getenv(RuntimeEnvVar.RUN_ID.value)
60
62
  if run_id is not None:
61
- self.set_run(run_id)
63
+ try:
64
+ api = self.client.build_api(
65
+ category=ApiCategories.CONTEXT.value,
66
+ operation=BackendOperations.READ.value,
67
+ project=self.name,
68
+ entity_type=EntityTypes.RUN.value,
69
+ entity_id=run_id,
70
+ )
71
+ run_key = self.client.read_object(api=api)["key"]
72
+ self.set_run(run_key)
73
+ except BackendError:
74
+ pass
62
75
 
63
76
  def set_run(self, run_ctx: str) -> None:
64
77
  """
@@ -7,6 +7,7 @@ from __future__ import annotations
7
7
  import typing
8
8
  from pathlib import Path
9
9
 
10
+ from digitalhub.entities._base.material.utils import refresh_decorator
10
11
  from digitalhub.entities._base.versioned.entity import VersionedEntity
11
12
  from digitalhub.entities._processors.context import context_processor
12
13
  from digitalhub.stores.data.api import get_store
@@ -72,6 +73,7 @@ class MaterialEntity(VersionedEntity):
72
73
  # I/O Methods
73
74
  ##############################
74
75
 
76
+ @refresh_decorator
75
77
  def as_file(self) -> list[str]:
76
78
  """
77
79
  Get object as file(s). It downloads the object from storage in
@@ -86,6 +88,7 @@ class MaterialEntity(VersionedEntity):
86
88
  dst = store._build_temp()
87
89
  return store.download(self.spec.path, dst=dst)
88
90
 
91
+ @refresh_decorator
89
92
  def download(
90
93
  self,
91
94
  destination: str | None = None,
@@ -130,6 +133,7 @@ class MaterialEntity(VersionedEntity):
130
133
 
131
134
  return store.download(self.spec.path, dst, overwrite=overwrite)
132
135
 
136
+ @refresh_decorator
133
137
  def upload(self, source: SourcesOrListOfSources) -> None:
134
138
  """
135
139
  Upload object from given local path to spec path destination.
@@ -4,9 +4,11 @@
4
4
 
5
5
  from __future__ import annotations
6
6
 
7
+ import typing
7
8
  from pathlib import Path
8
9
 
9
10
  from digitalhub.stores.data.api import get_default_store
11
+ from digitalhub.utils.exceptions import BackendError
10
12
  from digitalhub.utils.file_utils import eval_zip_type
11
13
  from digitalhub.utils.uri_utils import has_local_scheme
12
14
 
@@ -108,3 +110,28 @@ def build_log_path_from_source(
108
110
  path += f"/{Path(source).name}"
109
111
 
110
112
  return path
113
+
114
+ def refresh_decorator(fn: typing.Callable) -> typing.Callable:
115
+ """
116
+ Refresh decorator.
117
+
118
+ Parameters
119
+ ----------
120
+ fn : Callable
121
+ Function to decorate.
122
+
123
+ Returns
124
+ -------
125
+ Callable
126
+ Decorated function.
127
+ """
128
+
129
+ def wrapper(self, *args, **kwargs):
130
+ # Prevent rising error if entity is not yet created in backend
131
+ try:
132
+ self.refresh()
133
+ except BackendError:
134
+ pass
135
+ return fn(self, *args, **kwargs)
136
+
137
+ return wrapper
@@ -9,6 +9,7 @@ import typing
9
9
  from pathlib import Path
10
10
  from typing import Any
11
11
 
12
+ from digitalhub.entities._base.material.utils import refresh_decorator
12
13
  from digitalhub.entities.dataitem._base.entity import Dataitem
13
14
  from digitalhub.stores.data.api import get_store
14
15
  from digitalhub.utils.uri_utils import has_sql_scheme
@@ -65,6 +66,7 @@ class DataitemTable(Dataitem):
65
66
  self._query = query
66
67
  return self
67
68
 
69
+ @refresh_decorator
68
70
  def as_df(
69
71
  self,
70
72
  file_format: str | None = None,
@@ -107,6 +109,7 @@ class DataitemTable(Dataitem):
107
109
  **kwargs,
108
110
  )
109
111
 
112
+ @refresh_decorator
110
113
  def write_df(
111
114
  self,
112
115
  df: Any,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: digitalhub
3
- Version: 0.13.2
3
+ Version: 0.13.4
4
4
  Summary: Python SDK for Digitalhub
5
5
  Project-URL: Homepage, https://github.com/scc-digitalhub/digitalhub-sdk
6
6
  Author-email: Fondazione Bruno Kessler <digitalhub@fbk.eu>, Matteo Martini <mmartini@fbk.eu>
@@ -1,7 +1,7 @@
1
1
  digitalhub/__init__.py,sha256=JrwZhABki1rBFSP3uHBJOckWQiF213_UXuJRoX7QFHA,2572
2
2
  digitalhub/context/api.py,sha256=eIVsYhneu8bEQiUV15sUNlv5WlZu6zV7Dvidvg_0FfA,1500
3
3
  digitalhub/context/builder.py,sha256=NM4xcD2n4jXwdTS2hl3MAobf-BVUQH-9LB6U3J_F3pM,2826
4
- digitalhub/context/context.py,sha256=IXgrLtI6nKp0S9XclqiyiMcsbkTVveNVkkVnURBFvFc,2569
4
+ digitalhub/context/context.py,sha256=3_tbJljm2lB2mpR64gzObhpORUSQOZK8kvlCmp84hqI,3170
5
5
  digitalhub/entities/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
6
6
  digitalhub/entities/builders.py,sha256=I-RVAFNgnZGmx7Dyz8_n7gfsG-BVgbgfraJal5NWipE,2054
7
7
  digitalhub/entities/_base/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
@@ -24,10 +24,10 @@ digitalhub/entities/_base/entity/_constructors/uuid.py,sha256=7QhQ9epJAnYLCKUPY6
24
24
  digitalhub/entities/_base/executable/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
25
25
  digitalhub/entities/_base/executable/entity.py,sha256=duxjwi3ROHM4hewYfUzkTpHuETfHQ8WsQ4n3wprj3DA,13321
26
26
  digitalhub/entities/_base/material/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
27
- digitalhub/entities/_base/material/entity.py,sha256=ZthX0Zctc4OZPOSHLsTygkY8lSR4uILCy_nzGtk8Kz0,6807
27
+ digitalhub/entities/_base/material/entity.py,sha256=lhqhp5s2tzKW3lj6p_GrI4Y9-JDiadL3p_IBU7H7iSQ,6947
28
28
  digitalhub/entities/_base/material/spec.py,sha256=7lF_Pv7zGJUAR2ixmmCt-UPnoASgOLxnb9yffqwBVp8,544
29
29
  digitalhub/entities/_base/material/status.py,sha256=vAIb5qti5KxdIPdB9WYmWrCnqwGyUxuF6CpGSpcWxbE,520
30
- digitalhub/entities/_base/material/utils.py,sha256=diFtnOjCumenzOL1Su0ROA3KdrIJlRq5Jh845axvAtU,2512
30
+ digitalhub/entities/_base/material/utils.py,sha256=beAcQta_pysWEz8hUBXFBV8dwcxTfFdVKm7-eY74sQ0,3086
31
31
  digitalhub/entities/_base/runtime_entity/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
32
32
  digitalhub/entities/_base/runtime_entity/builder.py,sha256=VvhNKHeMj434q-bMQsoBN_abz2igvQAqIFYQ-abzX8c,2522
33
33
  digitalhub/entities/_base/unversioned/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
@@ -77,7 +77,7 @@ digitalhub/entities/dataitem/iceberg/spec.py,sha256=vtfaV9OE1WBKTtTHoYSdMnjQfUey
77
77
  digitalhub/entities/dataitem/iceberg/status.py,sha256=HMBNAzqQplUxmnnIVb57cCcjhmUQ1v8K3wAGUnYdRlA,310
78
78
  digitalhub/entities/dataitem/table/__init__.py,sha256=IRY2i9U97wptE3OcC_NO-EBmcAH6-Q36gMCspKetQ0k,107
79
79
  digitalhub/entities/dataitem/table/builder.py,sha256=FoXrW09HXCZ0XNnCPHNSZs_iLrIG_8WPCZo_5Vq6_YI,824
80
- digitalhub/entities/dataitem/table/entity.py,sha256=brqBpU6oYyOAJg3iX15bBoEO-dtM38whGUilviwrBxs,4214
80
+ digitalhub/entities/dataitem/table/entity.py,sha256=qhv6BXOm_zd68tHeOckgkyWHFtwn7HH36dMkw5QUjsI,4331
81
81
  digitalhub/entities/dataitem/table/models.py,sha256=5wqwm4GQjikdJVtDPEn5hwUR_FWxW_7hwIf-GLikqjQ,1269
82
82
  digitalhub/entities/dataitem/table/spec.py,sha256=oYgh5XqFrdzIpGxXe1FW5bsGlFHokUJdHJSamuyFs4k,779
83
83
  digitalhub/entities/dataitem/table/status.py,sha256=_-_UrcPZh3maGENDZ99pLA8Gz1yrXapvsxs_lPI1skw,306
@@ -252,8 +252,8 @@ digitalhub/utils/io_utils.py,sha256=p2K9VFJGzl3PmXc7GfXKZkPyg5hImduvXlfYVpnsMck,
252
252
  digitalhub/utils/logger.py,sha256=hH3gGE35L8jRxrg8EPXGZZAK1OA5-CvWnayuBZzteBM,545
253
253
  digitalhub/utils/types.py,sha256=orCxY43zXMJfKZsOj6FUR85u9wRBPJ0wdkzrBHTnVW8,217
254
254
  digitalhub/utils/uri_utils.py,sha256=Go787CxAOo2MMjFIEt8XssomtyV8vTdIrpyjSQK3gAM,4408
255
- digitalhub-0.13.2.dist-info/METADATA,sha256=eX13WzRWm-g-BL4xyAJjrF3a8ufDVEKBItHOHJWpEsM,18026
256
- digitalhub-0.13.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
257
- digitalhub-0.13.2.dist-info/licenses/AUTHORS,sha256=iDleK_2EAMmh0o8Te_E9mdXQCP4rBfFr9dW9d0-pCno,301
258
- digitalhub-0.13.2.dist-info/licenses/LICENSE,sha256=z3xQCHfGmTnigfoUe3uidW_GUSVeFBdos30w9VNTRec,11361
259
- digitalhub-0.13.2.dist-info/RECORD,,
255
+ digitalhub-0.13.4.dist-info/METADATA,sha256=yfhL-VxD-MYGDp88_n_7JdJgU8QifMmTheZh1xsjSyk,18026
256
+ digitalhub-0.13.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
257
+ digitalhub-0.13.4.dist-info/licenses/AUTHORS,sha256=iDleK_2EAMmh0o8Te_E9mdXQCP4rBfFr9dW9d0-pCno,301
258
+ digitalhub-0.13.4.dist-info/licenses/LICENSE,sha256=z3xQCHfGmTnigfoUe3uidW_GUSVeFBdos30w9VNTRec,11361
259
+ digitalhub-0.13.4.dist-info/RECORD,,