digitalhub 0.12.0__py3-none-any.whl → 0.13.0__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 (79) 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/executable/entity.py +105 -57
  6. digitalhub/entities/_base/material/entity.py +11 -18
  7. digitalhub/entities/_base/material/utils.py +1 -1
  8. digitalhub/entities/_commons/metrics.py +64 -30
  9. digitalhub/entities/_commons/utils.py +36 -9
  10. digitalhub/entities/_processors/base.py +150 -79
  11. digitalhub/entities/_processors/context.py +366 -215
  12. digitalhub/entities/_processors/utils.py +74 -30
  13. digitalhub/entities/artifact/crud.py +4 -0
  14. digitalhub/entities/artifact/utils.py +28 -13
  15. digitalhub/entities/dataitem/crud.py +14 -2
  16. digitalhub/entities/dataitem/table/entity.py +3 -3
  17. digitalhub/entities/dataitem/utils.py +84 -35
  18. digitalhub/entities/model/crud.py +4 -0
  19. digitalhub/entities/model/utils.py +28 -13
  20. digitalhub/entities/project/_base/entity.py +0 -2
  21. digitalhub/entities/run/_base/entity.py +2 -2
  22. digitalhub/entities/task/_base/models.py +12 -3
  23. digitalhub/entities/trigger/_base/entity.py +11 -0
  24. digitalhub/factory/factory.py +25 -3
  25. digitalhub/factory/utils.py +11 -3
  26. digitalhub/runtimes/_base.py +1 -1
  27. digitalhub/runtimes/builder.py +18 -1
  28. digitalhub/stores/client/__init__.py +12 -0
  29. digitalhub/stores/client/_base/api_builder.py +14 -0
  30. digitalhub/stores/client/_base/client.py +93 -0
  31. digitalhub/stores/client/_base/key_builder.py +28 -0
  32. digitalhub/stores/client/_base/params_builder.py +14 -0
  33. digitalhub/stores/client/api.py +10 -5
  34. digitalhub/stores/client/builder.py +3 -1
  35. digitalhub/stores/client/dhcore/api_builder.py +17 -0
  36. digitalhub/stores/client/dhcore/client.py +325 -70
  37. digitalhub/stores/client/dhcore/configurator.py +485 -193
  38. digitalhub/stores/client/dhcore/enums.py +3 -0
  39. digitalhub/stores/client/dhcore/error_parser.py +35 -1
  40. digitalhub/stores/client/dhcore/params_builder.py +113 -17
  41. digitalhub/stores/client/dhcore/utils.py +40 -22
  42. digitalhub/stores/client/local/api_builder.py +17 -0
  43. digitalhub/stores/client/local/client.py +6 -8
  44. digitalhub/stores/credentials/api.py +35 -0
  45. digitalhub/stores/credentials/configurator.py +210 -0
  46. digitalhub/stores/credentials/enums.py +68 -0
  47. digitalhub/stores/credentials/handler.py +176 -0
  48. digitalhub/stores/{configurator → credentials}/ini_module.py +60 -28
  49. digitalhub/stores/credentials/store.py +81 -0
  50. digitalhub/stores/data/_base/store.py +27 -9
  51. digitalhub/stores/data/api.py +49 -9
  52. digitalhub/stores/data/builder.py +90 -41
  53. digitalhub/stores/data/local/store.py +4 -7
  54. digitalhub/stores/data/remote/store.py +4 -7
  55. digitalhub/stores/data/s3/configurator.py +65 -80
  56. digitalhub/stores/data/s3/store.py +69 -81
  57. digitalhub/stores/data/s3/utils.py +10 -10
  58. digitalhub/stores/data/sql/configurator.py +76 -73
  59. digitalhub/stores/data/sql/store.py +191 -102
  60. digitalhub/utils/exceptions.py +6 -0
  61. digitalhub/utils/file_utils.py +53 -30
  62. digitalhub/utils/generic_utils.py +41 -33
  63. digitalhub/utils/git_utils.py +24 -14
  64. digitalhub/utils/io_utils.py +19 -18
  65. digitalhub/utils/uri_utils.py +31 -31
  66. {digitalhub-0.12.0.dist-info → digitalhub-0.13.0.dist-info}/METADATA +1 -1
  67. {digitalhub-0.12.0.dist-info → digitalhub-0.13.0.dist-info}/RECORD +71 -74
  68. digitalhub/entities/_commons/types.py +0 -9
  69. digitalhub/stores/configurator/api.py +0 -35
  70. digitalhub/stores/configurator/configurator.py +0 -202
  71. digitalhub/stores/configurator/credentials_store.py +0 -69
  72. digitalhub/stores/configurator/enums.py +0 -25
  73. digitalhub/stores/data/s3/enums.py +0 -20
  74. digitalhub/stores/data/sql/enums.py +0 -20
  75. digitalhub/stores/data/utils.py +0 -38
  76. /digitalhub/stores/{configurator → credentials}/__init__.py +0 -0
  77. {digitalhub-0.12.0.dist-info → digitalhub-0.13.0.dist-info}/WHEEL +0 -0
  78. {digitalhub-0.12.0.dist-info → digitalhub-0.13.0.dist-info}/licenses/AUTHORS +0 -0
  79. {digitalhub-0.12.0.dist-info → digitalhub-0.13.0.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.configurator.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
@@ -5,12 +5,14 @@
5
5
  from __future__ import annotations
6
6
 
7
7
  import typing
8
+ from abc import abstractmethod
8
9
 
9
10
  from digitalhub.entities._base.versioned.entity import VersionedEntity
10
11
  from digitalhub.entities._commons.enums import EntityTypes
11
12
  from digitalhub.entities._processors.context import context_processor
12
- from digitalhub.entities.run.crud import delete_run, get_run, list_runs
13
- from digitalhub.entities.task.crud import delete_task
13
+ from digitalhub.entities.run.crud import list_runs
14
+ from digitalhub.entities.task.crud import delete_task, list_tasks
15
+ from digitalhub.entities.trigger.crud import list_triggers
14
16
  from digitalhub.factory.factory import factory
15
17
  from digitalhub.utils.exceptions import EntityAlreadyExistsError, EntityError
16
18
 
@@ -123,13 +125,13 @@ class ExecutableEntity(VersionedEntity):
123
125
  if task_obj.spec.function == self._get_executable_string():
124
126
  self._tasks[task_obj.kind] = task_obj
125
127
 
126
- def new_task(self, task_kind: str, **kwargs) -> Task:
128
+ def new_task(self, kind: str, **kwargs) -> Task:
127
129
  """
128
130
  Create new task. If the task already exists, update it.
129
131
 
130
132
  Parameters
131
133
  ----------
132
- task_kind : str
134
+ kind : str
133
135
  Kind the object.
134
136
  **kwargs : dict
135
137
  Keyword arguments.
@@ -139,21 +141,18 @@ class ExecutableEntity(VersionedEntity):
139
141
  Task
140
142
  New task.
141
143
  """
142
- self._raise_if_exists(task_kind)
143
-
144
- if kwargs is None:
145
- kwargs = {}
144
+ self._raise_if_exists(kind)
146
145
 
147
146
  # Override kwargs
148
147
  kwargs["project"] = self.project
149
148
  kwargs[self.ENTITY_TYPE] = self._get_executable_string()
150
- kwargs["kind"] = task_kind
149
+ kwargs["kind"] = kind
151
150
 
152
151
  # Create object instance
153
152
  task: Task = factory.build_entity_from_params(**kwargs)
154
153
  task.save()
155
154
 
156
- self._tasks[task_kind] = task
155
+ self._tasks[kind] = task
157
156
  return task
158
157
 
159
158
  def get_task(self, kind: str) -> Task:
@@ -184,6 +183,23 @@ class ExecutableEntity(VersionedEntity):
184
183
  self._tasks[kind] = resp[0]
185
184
  return self._tasks[kind]
186
185
 
186
+ def list_task(self, **kwargs) -> list[Task]:
187
+ """
188
+ List tasks.
189
+
190
+ Parameters
191
+ ----------
192
+ **kwargs : dict
193
+ Keyword arguments.
194
+
195
+ Returns
196
+ -------
197
+ list
198
+ List of tasks.
199
+ """
200
+ kwargs["params"] = {self.ENTITY_TYPE: self._get_executable_string()}
201
+ return list_tasks(self.project, **kwargs)
202
+
187
203
  def update_task(self, kind: str, **kwargs) -> Task:
188
204
  """
189
205
  Update task.
@@ -202,9 +218,6 @@ class ExecutableEntity(VersionedEntity):
202
218
  """
203
219
  self._raise_if_not_exists(kind)
204
220
 
205
- if kwargs is None:
206
- kwargs = {}
207
-
208
221
  # Update kwargs
209
222
  kwargs["project"] = self.project
210
223
  kwargs["kind"] = kind
@@ -319,6 +332,12 @@ class ExecutableEntity(VersionedEntity):
319
332
  # Runs
320
333
  ##############################
321
334
 
335
+ @abstractmethod
336
+ def run(self, *args, **kwargs) -> Run:
337
+ """
338
+ Create and execute a new run.
339
+ """
340
+
322
341
  def get_run(
323
342
  self,
324
343
  identifier: str,
@@ -347,13 +366,14 @@ class ExecutableEntity(VersionedEntity):
347
366
  Using entity ID:
348
367
  >>> obj = executable.get_run("123")
349
368
  """
350
- obj = get_run(
351
- identifier=identifier,
352
- project=self.project,
353
- **kwargs,
354
- )
355
- self.refresh()
356
- return obj
369
+ entities = self.list_runs(**kwargs)
370
+ for entity in entities:
371
+ if getattr(entity.spec, self.ENTITY_TYPE) == self._get_executable_string():
372
+ if entity.id == identifier:
373
+ return entity
374
+ if entity.key == identifier:
375
+ return entity
376
+ raise EntityError(f"Run '{identifier}' does not exist or does not belong to this executable.")
357
377
 
358
378
  def list_runs(self, **kwargs) -> list[Run]:
359
379
  """
@@ -373,47 +393,20 @@ class ExecutableEntity(VersionedEntity):
373
393
  --------
374
394
  >>> objs = executable.list_runs()
375
395
  """
376
- if kwargs is None:
377
- kwargs = {}
378
396
  kwargs["params"] = {self.ENTITY_TYPE: self._get_executable_string()}
379
397
  return list_runs(self.project, **kwargs)
380
398
 
381
- def delete_run(
382
- self,
383
- identifier: str,
384
- **kwargs,
385
- ) -> None:
386
- """
387
- Delete run from backend.
388
-
389
- Parameters
390
- ----------
391
- identifier : str
392
- Entity key (store://...) or entity ID.
393
- **kwargs : dict
394
- Parameters to pass to the API call.
395
-
396
- Returns
397
- -------
398
- dict
399
- Response from backend.
400
-
401
- Examples
402
- --------
403
- >>> executable.delete_run("store://my-run-key")
404
-
405
- """
406
- delete_run(
407
- identifier=identifier,
408
- project=self.project,
409
- **kwargs,
410
- )
411
-
412
399
  ##############################
413
400
  # Trigger
414
401
  ##############################
415
402
 
416
- def trigger(self, action: str, trigger_kind: str, trigger_name: str, **kwargs) -> Trigger:
403
+ def trigger(
404
+ self,
405
+ action: str,
406
+ trigger_kind: str,
407
+ trigger_name: str,
408
+ **kwargs,
409
+ ) -> Trigger:
417
410
  """
418
411
  Trigger function.
419
412
 
@@ -439,9 +432,6 @@ class ExecutableEntity(VersionedEntity):
439
432
  # Get run validator for building trigger template
440
433
  run_kind = factory.get_run_kind(self.kind)
441
434
  run_validator: SpecValidator = factory.get_spec_validator(run_kind)
442
- if kwargs is None:
443
- kwargs = {}
444
-
445
435
  # Override kwargs
446
436
  kwargs["project"] = self.project
447
437
  kwargs["kind"] = trigger_kind
@@ -454,3 +444,61 @@ class ExecutableEntity(VersionedEntity):
454
444
  trigger: Trigger = factory.build_entity_from_params(**kwargs)
455
445
  trigger.save()
456
446
  return trigger
447
+
448
+ def get_trigger(
449
+ self,
450
+ identifier: str,
451
+ **kwargs,
452
+ ) -> Trigger:
453
+ """
454
+ Get object from backend.
455
+
456
+ Parameters
457
+ ----------
458
+ identifier : str
459
+ Entity key (store://...) or entity ID.
460
+ **kwargs : dict
461
+ Parameters to pass to the API call.
462
+
463
+ Returns
464
+ -------
465
+ Trigger
466
+ Object instance.
467
+
468
+ Examples
469
+ --------
470
+ Using entity key:
471
+ >>> obj = executable.get_trigger("store://my-trigger-key")
472
+
473
+ Using entity ID:
474
+ >>> obj = executable.get_trigger("123")
475
+ """
476
+ entities = self.list_triggers(**kwargs)
477
+ for entity in entities:
478
+ if getattr(entity.spec, self.ENTITY_TYPE) == self._get_executable_string():
479
+ if entity.id == identifier:
480
+ return entity
481
+ if entity.key == identifier:
482
+ return entity
483
+ raise EntityError(f"Trigger '{identifier}' does not exist or does not belong to this executable.")
484
+
485
+ def list_triggers(self, **kwargs) -> list[Trigger]:
486
+ """
487
+ List all triggers from backend.
488
+
489
+ Parameters
490
+ ----------
491
+ **kwargs : dict
492
+ Parameters to pass to the API call.
493
+
494
+ Returns
495
+ -------
496
+ list[Trigger]
497
+ List of object instances.
498
+
499
+ Examples
500
+ --------
501
+ >>> objs = executable.list_triggers()
502
+ """
503
+ kwargs["params"] = {self.ENTITY_TYPE: self._get_executable_string()}
504
+ return list_triggers(self.project, **kwargs)
@@ -82,10 +82,9 @@ class MaterialEntity(VersionedEntity):
82
82
  list[str]
83
83
  List of file paths.
84
84
  """
85
- store = get_store(self.project, self.spec.path)
86
- paths = self.get_file_paths()
85
+ store = get_store(self.spec.path)
87
86
  dst = store._build_temp()
88
- return store.download(self.spec.path, dst=dst, src=paths)
87
+ return store.download(self.spec.path, dst=dst)
89
88
 
90
89
  def download(
91
90
  self,
@@ -94,10 +93,7 @@ class MaterialEntity(VersionedEntity):
94
93
  ) -> str:
95
94
  """
96
95
  This function downloads one or more file from storage on local
97
- machine.
98
- It looks inside the object's status for the file(s) path under
99
- files attribute. If it does not find it, it will try to download
100
- what it can from spec.path.
96
+ machine from spec.path.
101
97
  The files are downloaded into a destination folder. If the destination
102
98
  is not specified, it will set by default under the context path
103
99
  as '<ctx-root>/<entity_type>', e.g. './dataitem'.
@@ -115,31 +111,24 @@ class MaterialEntity(VersionedEntity):
115
111
  Returns
116
112
  -------
117
113
  str
118
- Downloaded path.
114
+ Download path.
119
115
 
120
116
  Examples
121
117
  --------
122
118
  Download a single file:
123
119
 
124
- >>> entity.status.files[0]
125
- {
126
- "path ": "data.csv",
127
- "name ": "data.csv",
128
- "content_type ": "text/csv;charset=utf-8 "
129
- }
130
120
  >>> path = entity.download()
131
121
  >>> print(path)
132
122
  dataitem/data.csv
133
123
  """
134
- store = get_store(self.project, self.spec.path)
135
- paths = self.get_file_paths()
124
+ store = get_store(self.spec.path)
136
125
 
137
126
  if destination is None:
138
127
  dst = self._context().root / self.ENTITY_TYPE
139
128
  else:
140
129
  dst = Path(destination)
141
130
 
142
- return store.download(self.spec.path, dst=dst, src=paths, overwrite=overwrite)
131
+ return store.download(self.spec.path, dst, overwrite=overwrite)
143
132
 
144
133
  def upload(self, source: SourcesOrListOfSources) -> None:
145
134
  """
@@ -169,7 +158,7 @@ class MaterialEntity(VersionedEntity):
169
158
  >>> entity.upload('./data')
170
159
  """
171
160
  # Get store and upload object
172
- store = get_store(self.project, self.spec.path)
161
+ store = get_store(self.spec.path)
173
162
  paths = store.upload(source, self.spec.path)
174
163
 
175
164
  # Update files info
@@ -193,6 +182,10 @@ class MaterialEntity(VersionedEntity):
193
182
  -------
194
183
  None
195
184
  """
185
+ available = 100 - len(self.status.files)
186
+ if len(files) > available:
187
+ files = files[:available]
188
+
196
189
  path_list = self.get_file_paths()
197
190
  for f in files:
198
191
  if f.get("path") not in path_list:
@@ -6,7 +6,7 @@ from __future__ import annotations
6
6
 
7
7
  from pathlib import Path
8
8
 
9
- from digitalhub.stores.data.utils import get_default_store
9
+ from digitalhub.stores.data.api import get_default_store
10
10
  from digitalhub.utils.file_utils import eval_zip_type
11
11
  from digitalhub.utils.uri_utils import has_local_scheme
12
12
 
@@ -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