digitalhub 0.13.0b2__py3-none-any.whl → 0.13.0b4__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.

Files changed (61) hide show
  1. digitalhub/__init__.py +1 -1
  2. digitalhub/context/api.py +5 -5
  3. digitalhub/context/builder.py +3 -5
  4. digitalhub/context/context.py +9 -1
  5. digitalhub/entities/_base/material/entity.py +3 -3
  6. digitalhub/entities/_commons/metrics.py +64 -30
  7. digitalhub/entities/_commons/utils.py +36 -9
  8. digitalhub/entities/_processors/base.py +150 -79
  9. digitalhub/entities/_processors/context.py +363 -212
  10. digitalhub/entities/_processors/utils.py +74 -30
  11. digitalhub/entities/artifact/utils.py +28 -13
  12. digitalhub/entities/dataitem/crud.py +10 -2
  13. digitalhub/entities/dataitem/table/entity.py +3 -3
  14. digitalhub/entities/dataitem/utils.py +84 -35
  15. digitalhub/entities/model/utils.py +28 -13
  16. digitalhub/entities/task/_base/models.py +12 -3
  17. digitalhub/factory/factory.py +25 -3
  18. digitalhub/factory/utils.py +11 -3
  19. digitalhub/runtimes/_base.py +1 -1
  20. digitalhub/runtimes/builder.py +18 -1
  21. digitalhub/stores/client/__init__.py +12 -0
  22. digitalhub/stores/client/_base/api_builder.py +14 -0
  23. digitalhub/stores/client/_base/client.py +93 -0
  24. digitalhub/stores/client/_base/key_builder.py +28 -0
  25. digitalhub/stores/client/_base/params_builder.py +14 -0
  26. digitalhub/stores/client/api.py +10 -5
  27. digitalhub/stores/client/builder.py +3 -1
  28. digitalhub/stores/client/dhcore/api_builder.py +17 -0
  29. digitalhub/stores/client/dhcore/client.py +276 -58
  30. digitalhub/stores/client/dhcore/configurator.py +336 -141
  31. digitalhub/stores/client/dhcore/error_parser.py +35 -1
  32. digitalhub/stores/client/dhcore/params_builder.py +113 -17
  33. digitalhub/stores/client/dhcore/utils.py +32 -14
  34. digitalhub/stores/client/local/api_builder.py +17 -0
  35. digitalhub/stores/client/local/client.py +6 -8
  36. digitalhub/stores/credentials/api.py +8 -8
  37. digitalhub/stores/credentials/configurator.py +176 -3
  38. digitalhub/stores/credentials/enums.py +17 -3
  39. digitalhub/stores/credentials/handler.py +73 -45
  40. digitalhub/stores/credentials/ini_module.py +59 -27
  41. digitalhub/stores/credentials/store.py +33 -1
  42. digitalhub/stores/data/_base/store.py +8 -3
  43. digitalhub/stores/data/api.py +20 -16
  44. digitalhub/stores/data/builder.py +69 -13
  45. digitalhub/stores/data/s3/configurator.py +64 -23
  46. digitalhub/stores/data/s3/store.py +30 -27
  47. digitalhub/stores/data/s3/utils.py +9 -9
  48. digitalhub/stores/data/sql/configurator.py +76 -25
  49. digitalhub/stores/data/sql/store.py +180 -91
  50. digitalhub/utils/exceptions.py +6 -0
  51. digitalhub/utils/file_utils.py +53 -30
  52. digitalhub/utils/generic_utils.py +41 -33
  53. digitalhub/utils/git_utils.py +24 -14
  54. digitalhub/utils/io_utils.py +19 -18
  55. digitalhub/utils/uri_utils.py +31 -31
  56. {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b4.dist-info}/METADATA +1 -1
  57. {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b4.dist-info}/RECORD +60 -61
  58. digitalhub/entities/_commons/types.py +0 -9
  59. {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b4.dist-info}/WHEEL +0 -0
  60. {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b4.dist-info}/licenses/AUTHORS +0 -0
  61. {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b4.dist-info}/licenses/LICENSE +0 -0
digitalhub/__init__.py CHANGED
@@ -104,7 +104,7 @@ except ImportError:
104
104
  # Register entities into registry
105
105
  from digitalhub.factory.utils import register_entities, register_runtimes_entities
106
106
  from digitalhub.stores.client.dhcore.utils import refresh_token, set_dhcore_env
107
- from digitalhub.stores.credentials.api import get_current_env, set_current_env
107
+ from digitalhub.stores.credentials.api import get_current_profile, set_current_profile
108
108
 
109
109
  register_entities()
110
110
  register_runtimes_entities()
digitalhub/context/api.py CHANGED
@@ -17,15 +17,15 @@ def build_context(project: Project, overwrite: bool = False) -> Context:
17
17
  """
18
18
  Build a new context for a project.
19
19
 
20
- Creates or updates a context instance for the given project in the global
21
- context registry.
20
+ Creates or updates a context instance for the given project
21
+ in the global context registry.
22
22
 
23
23
  Parameters
24
24
  ----------
25
25
  project : Project
26
26
  The project object used to build the context.
27
27
  overwrite : bool, optional
28
- If True, overwrites existing context if it exists, by default False.
28
+ If True, overwrites existing context if it exists. Default is False.
29
29
 
30
30
  Returns
31
31
  -------
@@ -37,7 +37,7 @@ def build_context(project: Project, overwrite: bool = False) -> Context:
37
37
 
38
38
  def get_context(project: str) -> Context:
39
39
  """
40
- Wrapper for ContextBuilder.get().
40
+ Get the context for a given project name.
41
41
 
42
42
  Parameters
43
43
  ----------
@@ -54,7 +54,7 @@ def get_context(project: str) -> Context:
54
54
 
55
55
  def delete_context(project: str) -> None:
56
56
  """
57
- Wrapper for ContextBuilder.remove().
57
+ Delete the context for a given project name.
58
58
 
59
59
  Parameters
60
60
  ----------
@@ -39,8 +39,7 @@ class ContextBuilder:
39
39
  project : Project
40
40
  The project instance to create a context for.
41
41
  overwrite : bool, optional
42
- If True, overwrites existing context if project name already exists,
43
- by default False.
42
+ If True, overwrites existing context if project name already exists. Default is False.
44
43
 
45
44
  Returns
46
45
  -------
@@ -87,12 +86,11 @@ class ContextBuilder:
87
86
  Returns
88
87
  -------
89
88
  None
90
- This method doesn't return anything.
89
+ This method does not return anything.
91
90
 
92
91
  Notes
93
92
  -----
94
- If the project doesn't exist in the registry, this method
95
- silently does nothing.
93
+ If the project does not exist in the registry, this method silently does nothing.
96
94
  """
97
95
  self._instances.pop(project, None)
98
96
 
@@ -56,6 +56,10 @@ class Context:
56
56
  ----------
57
57
  run_ctx : str
58
58
  The run key to set.
59
+
60
+ Returns
61
+ -------
62
+ None
59
63
  """
60
64
  self.is_running = True
61
65
  self._run_ctx = run_ctx
@@ -63,6 +67,10 @@ class Context:
63
67
  def unset_run(self) -> None:
64
68
  """
65
69
  Clear the current run key and reset running state.
70
+
71
+ Returns
72
+ -------
73
+ None
66
74
  """
67
75
  self.is_running = False
68
76
  self._run_ctx = None
@@ -73,7 +81,7 @@ class Context:
73
81
 
74
82
  Returns
75
83
  -------
76
- str | None
84
+ str or None
77
85
  The current run key if set, None otherwise.
78
86
  """
79
87
  return self._run_ctx
@@ -82,7 +82,7 @@ class MaterialEntity(VersionedEntity):
82
82
  list[str]
83
83
  List of file paths.
84
84
  """
85
- store = get_store(self.project, self.spec.path)
85
+ store = get_store(self.spec.path)
86
86
  dst = store._build_temp()
87
87
  return store.download(self.spec.path, dst=dst)
88
88
 
@@ -121,7 +121,7 @@ class MaterialEntity(VersionedEntity):
121
121
  >>> print(path)
122
122
  dataitem/data.csv
123
123
  """
124
- store = get_store(self.project, self.spec.path)
124
+ store = get_store(self.spec.path)
125
125
 
126
126
  if destination is None:
127
127
  dst = self._context().root / self.ENTITY_TYPE
@@ -158,7 +158,7 @@ class MaterialEntity(VersionedEntity):
158
158
  >>> entity.upload('./data')
159
159
  """
160
160
  # Get store and upload object
161
- store = get_store(self.project, self.spec.path)
161
+ store = get_store(self.spec.path)
162
162
  paths = store.upload(source, self.spec.path)
163
163
 
164
164
  # Update files info
@@ -13,7 +13,15 @@ MetricType = Union[float, int, list[Union[float, int]]]
13
13
 
14
14
  class Metric(BaseModel):
15
15
  """
16
- Metric.
16
+ Pydantic model for validating metric values.
17
+
18
+ This model ensures that metric values are of the correct type,
19
+ accepting single numeric values or lists of numeric values.
20
+
21
+ Attributes
22
+ ----------
23
+ value : MetricType
24
+ The metric value, which can be a float, int, or list of floats/ints.
17
25
  """
18
26
 
19
27
  value: MetricType
@@ -21,17 +29,25 @@ class Metric(BaseModel):
21
29
 
22
30
  def validate_metric_value(value: Any) -> MetricType:
23
31
  """
24
- Validate metric value.
32
+ Validate and convert a value to a proper metric type.
33
+
34
+ Uses Pydantic validation to ensure the input value conforms to
35
+ the MetricType specification (float, int, or list of floats/ints).
25
36
 
26
37
  Parameters
27
38
  ----------
28
39
  value : Any
29
- The value to validate.
40
+ The value to validate and convert.
30
41
 
31
42
  Returns
32
43
  -------
33
44
  MetricType
34
- The validated value.
45
+ The validated metric value.
46
+
47
+ Raises
48
+ ------
49
+ ValueError
50
+ If the value cannot be converted to a valid metric type.
35
51
  """
36
52
  try:
37
53
  return Metric(value=value).value
@@ -47,23 +63,30 @@ def set_metrics(
47
63
  single_value: bool,
48
64
  ) -> dict[str, MetricType]:
49
65
  """
50
- Set metric value.
66
+ Set or update a metric value in the metrics dictionary.
67
+
68
+ This function routes to appropriate handling based on the value type
69
+ and the single_value flag. It can handle single values, lists, and
70
+ appending to existing metrics.
51
71
 
52
72
  Parameters
53
73
  ----------
54
74
  metrics : dict[str, MetricType]
55
- The metrics dictionary.
75
+ The metrics dictionary to update.
56
76
  key : str
57
- The key of the entity.
77
+ The metric key to set or update.
58
78
  value : Any
59
- The value to set.
79
+ The value to set for the metric.
60
80
  overwrite : bool
61
- Whether to overwrite the metric.
81
+ Whether to overwrite existing metrics.
82
+ single_value : bool
83
+ Whether to treat the value as a single metric rather than
84
+ appending to a list.
62
85
 
63
86
  Returns
64
87
  -------
65
88
  dict[str, MetricType]
66
- The metrics dictionary.
89
+ The updated metrics dictionary.
67
90
  """
68
91
  if isinstance(value, list):
69
92
  return handle_metric_list(metrics, key, value, overwrite)
@@ -79,23 +102,26 @@ def handle_metric_single(
79
102
  overwrite: bool,
80
103
  ) -> dict:
81
104
  """
82
- Handle metric single value.
105
+ Handle setting a single metric value.
106
+
107
+ Sets or overwrites a metric with a single numeric value. If the key
108
+ already exists and overwrite is False, the existing value is preserved.
83
109
 
84
110
  Parameters
85
111
  ----------
86
112
  metrics : dict[str, MetricType]
87
- Metrics dictionary.
113
+ The metrics dictionary to update.
88
114
  key : str
89
- Key of the metric.
90
- value : float
91
- Value of the metric.
115
+ The metric key to set.
116
+ value : float | int
117
+ The single numeric value to set.
92
118
  overwrite : bool
93
- If True, overwrite existing metric.
119
+ Whether to overwrite an existing metric with the same key.
94
120
 
95
121
  Returns
96
122
  -------
97
123
  dict
98
- Metrics dictionary.
124
+ The updated metrics dictionary.
99
125
  """
100
126
  if key not in metrics or overwrite:
101
127
  metrics[key] = value
@@ -109,23 +135,27 @@ def handle_metric_list_append(
109
135
  overwrite: bool,
110
136
  ) -> dict:
111
137
  """
112
- Handle metric list append.
138
+ Handle appending a single value to a metric list.
139
+
140
+ If the metric doesn't exist or overwrite is True, creates a new list
141
+ with the single value. If the metric exists as a list, appends to it.
142
+ If the metric exists as a single value, converts it to a list and appends.
113
143
 
114
144
  Parameters
115
145
  ----------
116
146
  metrics : dict[str, MetricType]
117
- Metrics dictionary.
147
+ The metrics dictionary to update.
118
148
  key : str
119
- Key of the metric.
120
- value : float
121
- Value of the metric.
149
+ The metric key to append to.
150
+ value : float | int
151
+ The numeric value to append.
122
152
  overwrite : bool
123
- If True, overwrite existing metric.
153
+ Whether to overwrite an existing metric instead of appending.
124
154
 
125
155
  Returns
126
156
  -------
127
157
  dict
128
- Metrics dictionary.
158
+ The updated metrics dictionary.
129
159
  """
130
160
  if key not in metrics or overwrite:
131
161
  metrics[key] = [value]
@@ -143,23 +173,27 @@ def handle_metric_list(
143
173
  overwrite: bool,
144
174
  ) -> dict:
145
175
  """
146
- Handle metric list.
176
+ Handle setting or extending a metric with a list of values.
177
+
178
+ If the metric doesn't exist or overwrite is True, sets the metric to
179
+ the provided list. If the metric exists and overwrite is False, extends
180
+ the existing list with the new values.
147
181
 
148
182
  Parameters
149
183
  ----------
150
184
  metrics : dict[str, MetricType]
151
- Metrics dictionary.
185
+ The metrics dictionary to update.
152
186
  key : str
153
- Key of the metric.
187
+ The metric key to set or extend.
154
188
  value : list[int | float]
155
- Value of the metric.
189
+ The list of numeric values to set or extend with.
156
190
  overwrite : bool
157
- If True, overwrite existing metric.
191
+ Whether to overwrite an existing metric instead of extending it.
158
192
 
159
193
  Returns
160
194
  -------
161
195
  dict
162
- Metrics dictionary.
196
+ The updated metrics dictionary.
163
197
  """
164
198
  if key not in metrics or overwrite:
165
199
  metrics[key] = value
@@ -9,17 +9,28 @@ from digitalhub.entities._commons.enums import EntityTypes
9
9
 
10
10
  def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
11
11
  """
12
- Parse the entity key. Returns project, entity type, kind, name and uuid.
12
+ Parse an entity key into its constituent components.
13
+
14
+ Extracts project name, entity type, kind, name, and UUID from a
15
+ standardized entity key format. Handles special cases for tasks
16
+ and runs which don't have name components.
13
17
 
14
18
  Parameters
15
19
  ----------
16
20
  key : str
17
- The entity key.
21
+ The entity key in format "store://project/type/kind/name:uuid"
22
+ or "store://project/type/kind/uuid" for tasks and runs.
18
23
 
19
24
  Returns
20
25
  -------
21
26
  tuple[str, str, str, str | None, str]
22
- Project, entity type, kind, name and uuid.
27
+ A tuple containing (project, entity_type, kind, name, uuid).
28
+ The name component is None for tasks and runs.
29
+
30
+ Raises
31
+ ------
32
+ ValueError
33
+ If the key format is invalid or cannot be parsed.
23
34
  """
24
35
  try:
25
36
  # Remove "store://" from the key
@@ -53,17 +64,25 @@ def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
53
64
 
54
65
  def get_entity_type_from_key(key: str) -> str:
55
66
  """
56
- Get entity type from key.
67
+ Extract the entity type from an entity key.
68
+
69
+ Parses the entity key and returns only the entity type component,
70
+ which indicates the kind of entity (artifact, function, run, etc.).
57
71
 
58
72
  Parameters
59
73
  ----------
60
74
  key : str
61
- The key of the entity.
75
+ The entity key in standardized format.
62
76
 
63
77
  Returns
64
78
  -------
65
79
  str
66
- The entity type.
80
+ The entity type extracted from the key.
81
+
82
+ Raises
83
+ ------
84
+ ValueError
85
+ If the key format is invalid or cannot be parsed.
67
86
  """
68
87
  _, entity_type, _, _, _ = parse_entity_key(key)
69
88
  return entity_type
@@ -71,17 +90,25 @@ def get_entity_type_from_key(key: str) -> str:
71
90
 
72
91
  def get_project_from_key(key: str) -> str:
73
92
  """
74
- Get project from key.
93
+ Extract the project name from an entity key.
94
+
95
+ Parses the entity key and returns only the project component,
96
+ which identifies the project context the entity belongs to.
75
97
 
76
98
  Parameters
77
99
  ----------
78
100
  key : str
79
- The key of the entity.
101
+ The entity key in standardized format.
80
102
 
81
103
  Returns
82
104
  -------
83
105
  str
84
- The project.
106
+ The project name extracted from the key.
107
+
108
+ Raises
109
+ ------
110
+ ValueError
111
+ If the key format is invalid or cannot be parsed.
85
112
  """
86
113
  project, _, _, _, _ = parse_entity_key(key)
87
114
  return project