digitalhub 0.13.0b3__py3-none-any.whl → 0.14.0b0__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 (67) hide show
  1. digitalhub/__init__.py +3 -8
  2. digitalhub/entities/_base/_base/entity.py +0 -11
  3. digitalhub/entities/_base/entity/builder.py +5 -5
  4. digitalhub/entities/_base/executable/entity.py +1 -1
  5. digitalhub/entities/_base/runtime_entity/builder.py +53 -18
  6. digitalhub/entities/_commons/metrics.py +64 -30
  7. digitalhub/entities/_commons/utils.py +100 -30
  8. digitalhub/entities/_processors/base.py +160 -81
  9. digitalhub/entities/_processors/context.py +424 -224
  10. digitalhub/entities/_processors/utils.py +77 -33
  11. digitalhub/entities/artifact/crud.py +20 -4
  12. digitalhub/entities/artifact/utils.py +29 -14
  13. digitalhub/entities/dataitem/crud.py +20 -4
  14. digitalhub/entities/dataitem/table/entity.py +0 -21
  15. digitalhub/entities/dataitem/utils.py +84 -34
  16. digitalhub/entities/function/_base/entity.py +1 -1
  17. digitalhub/entities/function/crud.py +15 -4
  18. digitalhub/entities/model/_base/entity.py +21 -1
  19. digitalhub/entities/model/crud.py +21 -5
  20. digitalhub/entities/model/utils.py +29 -14
  21. digitalhub/entities/project/_base/entity.py +65 -33
  22. digitalhub/entities/project/crud.py +8 -1
  23. digitalhub/entities/run/_base/entity.py +21 -1
  24. digitalhub/entities/run/crud.py +22 -5
  25. digitalhub/entities/secret/crud.py +22 -5
  26. digitalhub/entities/task/crud.py +22 -5
  27. digitalhub/entities/trigger/crud.py +20 -4
  28. digitalhub/entities/workflow/_base/entity.py +1 -1
  29. digitalhub/entities/workflow/crud.py +15 -4
  30. digitalhub/factory/enums.py +18 -0
  31. digitalhub/factory/factory.py +136 -57
  32. digitalhub/factory/utils.py +3 -54
  33. digitalhub/stores/client/api.py +6 -10
  34. digitalhub/stores/client/builder.py +3 -3
  35. digitalhub/stores/client/dhcore/client.py +104 -162
  36. digitalhub/stores/client/dhcore/configurator.py +92 -289
  37. digitalhub/stores/client/dhcore/enums.py +0 -16
  38. digitalhub/stores/client/dhcore/params_builder.py +41 -83
  39. digitalhub/stores/client/dhcore/utils.py +14 -22
  40. digitalhub/stores/client/local/client.py +77 -45
  41. digitalhub/stores/credentials/enums.py +1 -0
  42. digitalhub/stores/credentials/ini_module.py +0 -16
  43. digitalhub/stores/data/api.py +1 -1
  44. digitalhub/stores/data/builder.py +66 -4
  45. digitalhub/stores/data/local/store.py +0 -103
  46. digitalhub/stores/data/s3/configurator.py +60 -6
  47. digitalhub/stores/data/s3/store.py +44 -2
  48. digitalhub/stores/data/sql/configurator.py +57 -7
  49. digitalhub/stores/data/sql/store.py +184 -78
  50. digitalhub/utils/file_utils.py +0 -17
  51. digitalhub/utils/generic_utils.py +1 -2
  52. digitalhub/utils/store_utils.py +44 -0
  53. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/METADATA +3 -2
  54. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/RECORD +63 -65
  55. digitalhub/entities/_commons/types.py +0 -9
  56. digitalhub/entities/task/_base/utils.py +0 -22
  57. digitalhub/stores/client/dhcore/models.py +0 -40
  58. digitalhub/stores/data/s3/utils.py +0 -78
  59. /digitalhub/entities/{_base/entity/_constructors → _constructors}/__init__.py +0 -0
  60. /digitalhub/entities/{_base/entity/_constructors → _constructors}/metadata.py +0 -0
  61. /digitalhub/entities/{_base/entity/_constructors → _constructors}/name.py +0 -0
  62. /digitalhub/entities/{_base/entity/_constructors → _constructors}/spec.py +0 -0
  63. /digitalhub/entities/{_base/entity/_constructors → _constructors}/status.py +0 -0
  64. /digitalhub/entities/{_base/entity/_constructors → _constructors}/uuid.py +0 -0
  65. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/WHEEL +0 -0
  66. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/licenses/AUTHORS +0 -0
  67. {digitalhub-0.13.0b3.dist-info → digitalhub-0.14.0b0.dist-info}/licenses/LICENSE +0 -0
@@ -8,7 +8,7 @@ import typing
8
8
 
9
9
  from digitalhub.context.api import get_context
10
10
  from digitalhub.entities._commons.enums import ApiCategories, BackendOperations, EntityTypes
11
- from digitalhub.entities._commons.utils import get_project_from_key, parse_entity_key
11
+ from digitalhub.entities._commons.utils import get_project_from_key, is_valid_key, parse_entity_key
12
12
  from digitalhub.factory.factory import factory
13
13
  from digitalhub.stores.client.api import get_client
14
14
  from digitalhub.utils.exceptions import ContextError, EntityError, EntityNotExistsError
@@ -26,25 +26,38 @@ def parse_identifier(
26
26
  entity_id: str | None = None,
27
27
  ) -> tuple[str, str, str | None, str | None, str | None]:
28
28
  """
29
- Parse entity identifier.
29
+ Parse and validate entity identifier into its components.
30
+
31
+ Processes an entity identifier that can be either a full entity key
32
+ (store://) or a simple entity name. When using a simple name,
33
+ additional parameters must be provided for proper identification.
30
34
 
31
35
  Parameters
32
36
  ----------
33
37
  identifier : str
34
- Entity key (store://...) or entity name.
35
- project : str
36
- Project name.
37
- entity_type : str
38
- Entity type.
39
- entity_id : str
40
- Entity ID.
38
+ The entity identifier to parse. Can be either a full entity key
39
+ (store://project/entity_type/kind/name:id) or a simple entity name.
40
+ project : str, optional
41
+ The project name. Required when identifier is not a full key.
42
+ entity_type : str, optional
43
+ The entity type. Required when identifier is not a full key.
44
+ entity_kind : str, optional
45
+ The entity kind specification.
46
+ entity_id : str, optional
47
+ The entity version identifier.
41
48
 
42
49
  Returns
43
50
  -------
44
51
  tuple[str, str, str | None, str | None, str | None]
45
- Project name, entity type, entity kind, entity name, entity ID.
52
+ A tuple containing (project_name, entity_type, entity_kind,
53
+ entity_name, entity_id) parsed from the identifier.
54
+
55
+ Raises
56
+ ------
57
+ ValueError
58
+ If identifier is not a full key and project or entity_type is None.
46
59
  """
47
- if not identifier.startswith("store://"):
60
+ if not is_valid_key(identifier):
48
61
  if project is None or entity_type is None:
49
62
  raise ValueError("Project and entity type must be specified.")
50
63
  return project, entity_type, entity_kind, identifier, entity_id
@@ -56,21 +69,31 @@ def get_context_from_identifier(
56
69
  project: str | None = None,
57
70
  ) -> Context:
58
71
  """
59
- Get context from project.
72
+ Retrieve context instance from entity identifier or project name.
73
+
74
+ Extracts project information from the identifier and returns the
75
+ corresponding context. If the identifier is not a full key, the
76
+ project parameter must be provided explicitly.
60
77
 
61
78
  Parameters
62
79
  ----------
63
80
  identifier : str
64
- Entity key (store://...) or entity name.
65
- project : str
66
- Project name.
81
+ The entity identifier to extract context from. Can be either
82
+ a full entity key (store://...) or a simple entity name.
83
+ project : str, optional
84
+ The project name. Required when identifier is not a full key.
67
85
 
68
86
  Returns
69
87
  -------
70
88
  Context
71
- Context.
89
+ The context instance associated with the identified project.
90
+
91
+ Raises
92
+ ------
93
+ EntityError
94
+ If identifier is not a full key and project parameter is None.
72
95
  """
73
- if not identifier.startswith("store://"):
96
+ if not is_valid_key(identifier):
74
97
  if project is None:
75
98
  raise EntityError("Specify project if you do not specify entity key.")
76
99
  else:
@@ -83,19 +106,26 @@ def get_context_from_project(
83
106
  project: str,
84
107
  ) -> Context:
85
108
  """
86
- Check if the given project is in the context.
87
- Otherwise try to get the project from remote.
88
- Finally return the client.
109
+ Retrieve context for a project, fetching from remote if necessary.
110
+
111
+ Attempts to get the project context from the local cache first.
112
+ If the project is not found locally, tries to fetch it from the
113
+ remote backend and create the context.
89
114
 
90
115
  Parameters
91
116
  ----------
92
117
  project : str
93
- Project name.
118
+ The name of the project to get context for.
94
119
 
95
120
  Returns
96
121
  -------
97
122
  Context
98
- Context.
123
+ The context instance for the specified project.
124
+
125
+ Raises
126
+ ------
127
+ ContextError
128
+ If the project cannot be found locally or remotely.
99
129
  """
100
130
  try:
101
131
  return get_context(project)
@@ -105,19 +135,28 @@ def get_context_from_project(
105
135
 
106
136
  def get_context_from_remote(
107
137
  project: str,
108
- ) -> Client:
138
+ ) -> Context:
109
139
  """
110
- Get context from remote.
140
+ Fetch project context from remote backend and create local context.
141
+
142
+ Retrieves project information from the remote backend, builds the
143
+ project entity locally, and returns the corresponding context.
144
+ Used when a project is not available in the local context cache.
111
145
 
112
146
  Parameters
113
147
  ----------
114
148
  project : str
115
- Project name.
149
+ The name of the project to fetch from remote.
116
150
 
117
151
  Returns
118
152
  -------
119
- Client
120
- Client.
153
+ Context
154
+ The context instance created from the remote project data.
155
+
156
+ Raises
157
+ ------
158
+ ContextError
159
+ If the project is not found on the remote backend.
121
160
  """
122
161
  try:
123
162
  client = get_client()
@@ -135,23 +174,28 @@ def _read_base_entity(
135
174
  **kwargs,
136
175
  ) -> dict:
137
176
  """
138
- Read object from backend.
177
+ Read entity data from the backend API.
178
+
179
+ Internal utility function that performs a base-level entity read
180
+ operation through the client API. Builds the appropriate API
181
+ endpoint and retrieves the entity data as a dictionary.
139
182
 
140
183
  Parameters
141
184
  ----------
142
185
  client : Client
143
- Client instance.
186
+ The client instance to use for the API request.
144
187
  entity_type : str
145
- Entity type.
188
+ The type of entity to read (e.g., 'project', 'function').
146
189
  entity_name : str
147
- Entity name.
190
+ The name identifier of the entity to retrieve.
148
191
  **kwargs : dict
149
- Parameters to pass to the API call.
192
+ Additional parameters to pass to the API call, such as
193
+ version specifications or query filters.
150
194
 
151
195
  Returns
152
196
  -------
153
197
  dict
154
- Object instance.
198
+ Dictionary containing the entity data retrieved from the backend.
155
199
  """
156
200
  api = client.build_api(
157
201
  ApiCategories.BASE.value,
@@ -238,14 +238,25 @@ def list_artifacts(project: str, **kwargs) -> list[Artifact]:
238
238
  )
239
239
 
240
240
 
241
- def import_artifact(file: str) -> Artifact:
241
+ def import_artifact(
242
+ file: str | None = None,
243
+ key: str | None = None,
244
+ reset_id: bool = False,
245
+ context: str | None = None,
246
+ ) -> Artifact:
242
247
  """
243
- Import object from a YAML file and create a new object into the backend.
248
+ Import an object from a YAML file or from a storage key.
244
249
 
245
250
  Parameters
246
251
  ----------
247
252
  file : str
248
- Path to YAML file.
253
+ Path to the YAML file.
254
+ key : str
255
+ Entity key (store://...).
256
+ reset_id : bool
257
+ Flag to determine if the ID of executable entities should be reset.
258
+ context : str
259
+ Project name to use for context resolution.
249
260
 
250
261
  Returns
251
262
  -------
@@ -256,7 +267,12 @@ def import_artifact(file: str) -> Artifact:
256
267
  --------
257
268
  >>> obj = import_artifact("my-artifact.yaml")
258
269
  """
259
- return context_processor.import_context_entity(file)
270
+ return context_processor.import_context_entity(
271
+ file,
272
+ key,
273
+ reset_id,
274
+ context,
275
+ )
260
276
 
261
277
 
262
278
  def load_artifact(file: str) -> Artifact:
@@ -6,25 +6,32 @@ from __future__ import annotations
6
6
 
7
7
  from typing import Any
8
8
 
9
- from digitalhub.entities._base.entity._constructors.uuid import build_uuid
10
9
  from digitalhub.entities._base.material.utils import build_log_path_from_source, eval_local_source
11
10
  from digitalhub.entities._commons.enums import EntityTypes
11
+ from digitalhub.entities._constructors.uuid import build_uuid
12
12
 
13
13
 
14
14
  def eval_source(
15
15
  source: str | list[str] | None = None,
16
16
  ) -> Any:
17
17
  """
18
- Evaluate if source is local.
18
+ Evaluate whether the source is local or remote.
19
+
20
+ Determines if the provided source(s) reference local files or
21
+ remote resources. This evaluation affects how the artifact
22
+ will be processed and stored.
19
23
 
20
24
  Parameters
21
25
  ----------
22
- source : str | list[str]
23
- Source(s).
26
+ source : str, list[str], or None, optional
27
+ The source specification(s) to evaluate. Can be a single
28
+ source string, a list of source strings, or None.
24
29
 
25
30
  Returns
26
31
  -------
27
- None
32
+ Any
33
+ The result of the local source evaluation, indicating
34
+ whether the source is local or remote.
28
35
  """
29
36
  return eval_local_source(source)
30
37
 
@@ -37,25 +44,33 @@ def process_kwargs(
37
44
  **kwargs,
38
45
  ) -> dict:
39
46
  """
40
- Process spec kwargs.
47
+ Process and enhance specification parameters for artifact creation.
48
+
49
+ Processes the keyword arguments for artifact specification, handling
50
+ path generation and UUID assignment. If no path is provided, generates
51
+ a unique path based on project, entity type, name, and source.
41
52
 
42
53
  Parameters
43
54
  ----------
44
55
  project : str
45
- Project name.
56
+ The name of the project.
46
57
  name : str
47
- Object name.
48
- source : str
49
- Source(s).
50
- path : str
51
- Destination path of the entity. If not provided, it's generated.
58
+ The name of the artifact entity.
59
+ source : str or list[str]
60
+ The source specification(s) for the artifact content.
61
+ Can be a single source or multiple sources.
62
+ path : str, optional
63
+ The destination path for the artifact entity.
64
+ If None, a path will be automatically generated.
52
65
  **kwargs : dict
53
- Spec parameters.
66
+ Additional specification parameters to be processed
67
+ and passed to the artifact creation.
54
68
 
55
69
  Returns
56
70
  -------
57
71
  dict
58
- Kwargs updated.
72
+ The updated kwargs dictionary with processed path
73
+ and UUID information included.
59
74
  """
60
75
  if path is None:
61
76
  uuid = build_uuid()
@@ -264,14 +264,25 @@ def list_dataitems(project: str, **kwargs) -> list[Dataitem]:
264
264
  )
265
265
 
266
266
 
267
- def import_dataitem(file: str) -> Dataitem:
267
+ def import_dataitem(
268
+ file: str | None = None,
269
+ key: str | None = None,
270
+ reset_id: bool = False,
271
+ context: str | None = None,
272
+ ) -> Dataitem:
268
273
  """
269
- Import object from a YAML file and create a new object into the backend.
274
+ Import an object from a YAML file or from a storage key.
270
275
 
271
276
  Parameters
272
277
  ----------
273
278
  file : str
274
- Path to YAML file.
279
+ Path to the YAML file.
280
+ key : str
281
+ Entity key (store://...).
282
+ reset_id : bool
283
+ Flag to determine if the ID of executable entities should be reset.
284
+ context : str
285
+ Project name to use for context resolution.
275
286
 
276
287
  Returns
277
288
  -------
@@ -282,7 +293,12 @@ def import_dataitem(file: str) -> Dataitem:
282
293
  --------
283
294
  >>> obj = import_dataitem("my-dataitem.yaml")
284
295
  """
285
- return context_processor.import_context_entity(file)
296
+ return context_processor.import_context_entity(
297
+ file,
298
+ key,
299
+ reset_id,
300
+ context,
301
+ )
286
302
 
287
303
 
288
304
  def load_dataitem(file: str) -> Dataitem:
@@ -4,9 +4,7 @@
4
4
 
5
5
  from __future__ import annotations
6
6
 
7
- import shutil
8
7
  import typing
9
- from pathlib import Path
10
8
  from typing import Any
11
9
 
12
10
  from digitalhub.entities.dataitem._base.entity import Dataitem
@@ -138,22 +136,3 @@ class DataitemTable(Dataitem):
138
136
  extension=extension,
139
137
  **kwargs,
140
138
  )
141
-
142
- @staticmethod
143
- def _clean_tmp_path(pth: Path | None, clean: bool) -> None:
144
- """
145
- Clean temporary path.
146
-
147
- Parameters
148
- ----------
149
- pth : Path | None
150
- Path to clean.
151
- clean : bool
152
- If True, the path will be cleaned.
153
-
154
- Returns
155
- -------
156
- None
157
- """
158
- if pth is not None and clean:
159
- shutil.rmtree(pth)
@@ -9,9 +9,9 @@ import typing
9
9
  from typing import Any
10
10
 
11
11
  from digitalhub.context.api import get_context
12
- from digitalhub.entities._base.entity._constructors.uuid import build_uuid
13
12
  from digitalhub.entities._base.material.utils import build_log_path_from_source, eval_local_source
14
13
  from digitalhub.entities._commons.enums import EntityKinds, EntityTypes
14
+ from digitalhub.entities._constructors.uuid import build_uuid
15
15
  from digitalhub.stores.data.api import get_store
16
16
  from digitalhub.stores.readers.data.api import get_reader_by_object
17
17
  from digitalhub.utils.enums import FileExtensions
@@ -33,16 +33,39 @@ def eval_source(
33
33
  project: str | None = None,
34
34
  ) -> Any:
35
35
  """
36
- Evaluate if source is local.
36
+ Evaluate and process data source for dataitem creation.
37
+
38
+ Determines the appropriate source handling based on whether a source
39
+ path or data object is provided. For table dataitems with data objects,
40
+ writes the data to a Parquet file and returns the file path.
37
41
 
38
42
  Parameters
39
43
  ----------
40
- source : SourcesOrListOfSources
41
- Source(s).
44
+ source : SourcesOrListOfSources, optional
45
+ The source specification(s) for the dataitem. Can be file paths,
46
+ URLs, or other source identifiers.
47
+ data : Any, optional
48
+ The data object to process (e.g., DataFrame). Alternative to source.
49
+ Exactly one of source or data must be provided.
50
+ kind : str, optional
51
+ The kind of dataitem being created (e.g., 'table').
52
+ name : str, optional
53
+ The name of the dataitem, used for generating file paths.
54
+ project : str, optional
55
+ The project name, used for context and path generation.
42
56
 
43
57
  Returns
44
58
  -------
45
- None
59
+ Any
60
+ The processed source. Returns the original source if provided,
61
+ or the path to a generated file if data was processed.
62
+
63
+ Raises
64
+ ------
65
+ ValueError
66
+ If both source and data are provided or both are None.
67
+ NotImplementedError
68
+ If the specified kind is not supported for data processing.
46
69
  """
47
70
  if (source is None) == (data is None):
48
71
  raise ValueError("You must provide source or data.")
@@ -69,24 +92,32 @@ def eval_data(
69
92
  engine: str | None = None,
70
93
  ) -> Any:
71
94
  """
72
- Evaluate data is loaded.
95
+ Evaluate and load data from source or return provided data.
96
+
97
+ For table dataitems, loads data from the source using the appropriate
98
+ store and reader. For other kinds, returns the data as-is.
73
99
 
74
100
  Parameters
75
101
  ----------
76
- project : str
77
- Project name.
78
- source : str
79
- Source(s).
80
- data : Any
81
- Dataframe to log. Alternative to source.
82
- file_format : str
83
- Extension of the file.
84
- engine : str
85
- Engine to use.
102
+ kind : str
103
+ The kind of dataitem (e.g., 'table') that determines
104
+ how data should be processed.
105
+ source : SourcesOrListOfSources
106
+ The source specification(s) to load data from.
107
+ data : Any, optional
108
+ Pre-loaded data object. If provided, may be returned directly
109
+ depending on the dataitem kind.
110
+ file_format : str, optional
111
+ The file format specification for reading the source
112
+ (e.g., 'parquet', 'csv').
113
+ engine : str, optional
114
+ The engine to use for reading the data (e.g., 'pandas', 'polars').
86
115
 
87
116
  Returns
88
117
  -------
89
- None
118
+ Any
119
+ The loaded data object for table dataitems, or the original
120
+ data parameter for other kinds.
90
121
  """
91
122
  if kind == EntityKinds.DATAITEM_TABLE.value:
92
123
  if data is None:
@@ -108,29 +139,37 @@ def process_kwargs(
108
139
  **kwargs,
109
140
  ) -> dict:
110
141
  """
111
- Process spec kwargs.
142
+ Process and enhance specification parameters for dataitem creation.
143
+
144
+ Processes the keyword arguments for dataitem specification, handling
145
+ schema extraction for table dataitems and path generation. Extracts
146
+ schema information from data objects when available.
112
147
 
113
148
  Parameters
114
149
  ----------
115
150
  project : str
116
- Project name.
151
+ The name of the project.
117
152
  name : str
118
- Object name.
153
+ The name of the dataitem entity.
119
154
  kind : str
120
- Kind the object.
155
+ The kind of dataitem being created (e.g., 'table').
121
156
  source : SourcesOrListOfSources
122
- Source(s).
123
- data : Any
124
- Dataframe to log. Alternative to source.
125
- path : str
126
- Destination path of the entity. If not provided, it's generated.
157
+ The source specification(s) for the dataitem content.
158
+ data : Any, optional
159
+ The data object for schema extraction and processing.
160
+ Used as an alternative to source for table dataitems.
161
+ path : str, optional
162
+ The destination path for the dataitem entity.
163
+ If None, a path will be automatically generated.
127
164
  **kwargs : dict
128
- Spec parameters.
165
+ Additional specification parameters to be processed
166
+ and passed to the dataitem creation.
129
167
 
130
168
  Returns
131
169
  -------
132
170
  dict
133
- Kwargs updated.
171
+ The updated kwargs dictionary with processed path,
172
+ UUID, and schema information included.
134
173
  """
135
174
  if data is not None:
136
175
  if kind == EntityKinds.DATAITEM_TABLE.value:
@@ -147,12 +186,17 @@ def process_kwargs(
147
186
 
148
187
  def clean_tmp_path(pth: SourcesOrListOfSources) -> None:
149
188
  """
150
- Clean temporary path.
189
+ Clean up temporary files and directories.
190
+
191
+ Removes temporary files or directories created during dataitem
192
+ processing. Handles both single paths and lists of paths,
193
+ ignoring any errors that occur during cleanup.
151
194
 
152
195
  Parameters
153
196
  ----------
154
197
  pth : SourcesOrListOfSources
155
- Path to clean.
198
+ The path or list of paths to clean up. Can be file paths
199
+ or directory paths that need to be removed.
156
200
 
157
201
  Returns
158
202
  -------
@@ -167,19 +211,25 @@ def clean_tmp_path(pth: SourcesOrListOfSources) -> None:
167
211
 
168
212
  def post_process(obj: Dataitem, data: Any) -> Dataitem:
169
213
  """
170
- Post process object.
214
+ Post-process dataitem object with additional metadata and previews.
215
+
216
+ Enhances the dataitem object with additional information extracted
217
+ from the data. For table dataitems, generates and stores a data
218
+ preview in the object's status.
171
219
 
172
220
  Parameters
173
221
  ----------
174
222
  obj : Dataitem
175
- The object.
223
+ The dataitem object to post-process and enhance.
176
224
  data : Any
177
- The data.
225
+ The data object used to generate previews and extract
226
+ additional metadata information.
178
227
 
179
228
  Returns
180
229
  -------
181
230
  Dataitem
182
- The object.
231
+ The enhanced dataitem object with updated status information
232
+ and saved changes.
183
233
  """
184
234
  if obj.kind == EntityKinds.DATAITEM_TABLE.value:
185
235
  reader = get_reader_by_object(data)
@@ -77,7 +77,7 @@ class Function(ExecutableEntity):
77
77
  """
78
78
  # Get task and run kind
79
79
  task_kind = factory.get_task_kind_from_action(self.kind, action)
80
- run_kind = factory.get_run_kind(self.kind)
80
+ run_kind = factory.get_run_kind_from_action(self.kind, action)
81
81
 
82
82
  # Create or update new task
83
83
  task = self._get_or_create_task(task_kind)
@@ -182,14 +182,25 @@ def list_functions(project: str, **kwargs) -> list[Function]:
182
182
  )
183
183
 
184
184
 
185
- def import_function(file: str) -> Function:
185
+ def import_function(
186
+ file: str | None = None,
187
+ key: str | None = None,
188
+ reset_id: bool = False,
189
+ context: str | None = None,
190
+ ) -> Function:
186
191
  """
187
- Import object from a YAML file and create a new object into the backend.
192
+ Import an object from a YAML file or from a storage key.
188
193
 
189
194
  Parameters
190
195
  ----------
191
196
  file : str
192
- Path to YAML file.
197
+ Path to the YAML file.
198
+ key : str
199
+ Entity key (store://...).
200
+ reset_id : bool
201
+ Flag to determine if the ID of executable entities should be reset.
202
+ context : str
203
+ Project name to use for context resolution.
193
204
 
194
205
  Returns
195
206
  -------
@@ -200,7 +211,7 @@ def import_function(file: str) -> Function:
200
211
  --------
201
212
  >>> obj = import_function("my-function.yaml")
202
213
  """
203
- return context_processor.import_executable_entity(file)
214
+ return context_processor.import_executable_entity(file, key, reset_id, context)
204
215
 
205
216
 
206
217
  def load_function(file: str) -> Function:
@@ -125,15 +125,35 @@ class Model(MaterialEntity):
125
125
  -------
126
126
  None
127
127
 
128
+ Examples
129
+ --------
130
+ Log multiple metrics at once
131
+ >>> entity.log_metrics({"loss": 0.002, "accuracy": 0.95})
132
+
133
+ Log metrics with lists and single values
134
+ >>> entity.log_metrics({"loss": [0.1, 0.05], "epoch": 10})
135
+
136
+ Append to existing metrics (default behavior)
137
+ >>> entity.log_metrics({"loss": 0.001, "accuracy": 0.96}) # Appends to existing
138
+
139
+ Overwrite existing metrics
140
+ >>> entity.log_metrics({"loss": 0.0005, "accuracy": 0.98}, overwrite=True)
141
+
128
142
  See also
129
143
  --------
130
144
  log_metric
131
145
  """
132
146
  for key, value in metrics.items():
147
+ # For lists, use log_metric which handles appending correctly
133
148
  if isinstance(value, list):
134
149
  self.log_metric(key, value, overwrite)
150
+
151
+ # For single values, check if we should append or create new
135
152
  else:
136
- self.log_metric(key, value, overwrite, single_value=True)
153
+ if not overwrite and key in self.status.metrics:
154
+ self.log_metric(key, value)
155
+ else:
156
+ self.log_metric(key, value, overwrite, single_value=True)
137
157
 
138
158
  ##############################
139
159
  # Helper methods