digitalhub 0.10.0b2__py3-none-any.whl → 0.10.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 (50) hide show
  1. digitalhub/entities/_base/entity/builder.py +5 -5
  2. digitalhub/entities/_base/material/entity.py +4 -17
  3. digitalhub/entities/_base/material/status.py +1 -1
  4. digitalhub/entities/_commons/models.py +7 -3
  5. digitalhub/entities/_commons/utils.py +5 -4
  6. digitalhub/entities/_operations/processor.py +5 -4
  7. digitalhub/entities/artifact/artifact/spec.py +3 -1
  8. digitalhub/entities/artifact/crud.py +3 -2
  9. digitalhub/entities/builders.py +6 -18
  10. digitalhub/entities/dataitem/crud.py +17 -5
  11. digitalhub/entities/dataitem/table/models.py +4 -3
  12. digitalhub/entities/dataitem/table/utils.py +7 -7
  13. digitalhub/entities/dataitem/utils.py +50 -6
  14. digitalhub/entities/model/_base/spec.py +6 -7
  15. digitalhub/entities/model/crud.py +3 -2
  16. digitalhub/entities/model/huggingface/spec.py +4 -2
  17. digitalhub/entities/model/mlflow/spec.py +6 -4
  18. digitalhub/entities/project/_base/spec.py +8 -6
  19. digitalhub/entities/project/crud.py +2 -2
  20. digitalhub/entities/run/_base/spec.py +4 -2
  21. digitalhub/entities/secret/_base/spec.py +4 -2
  22. digitalhub/entities/secret/crud.py +2 -0
  23. digitalhub/entities/task/_base/models.py +41 -40
  24. digitalhub/entities/task/_base/utils.py +2 -2
  25. digitalhub/stores/_base/store.py +5 -4
  26. digitalhub/stores/local/store.py +4 -3
  27. digitalhub/stores/remote/store.py +4 -3
  28. digitalhub/stores/s3/store.py +5 -4
  29. digitalhub/stores/sql/configurator.py +4 -4
  30. digitalhub/stores/sql/enums.py +1 -1
  31. digitalhub/stores/sql/store.py +7 -3
  32. digitalhub/utils/file_utils.py +8 -7
  33. digitalhub/utils/generic_utils.py +20 -8
  34. digitalhub/utils/types.py +6 -0
  35. digitalhub/utils/uri_utils.py +1 -1
  36. {digitalhub-0.10.0b2.dist-info → digitalhub-0.10.0b4.dist-info}/METADATA +27 -33
  37. {digitalhub-0.10.0b2.dist-info → digitalhub-0.10.0b4.dist-info}/RECORD +39 -49
  38. {digitalhub-0.10.0b2.dist-info → digitalhub-0.10.0b4.dist-info}/WHEEL +1 -2
  39. digitalhub-0.10.0b2.dist-info/top_level.txt +0 -2
  40. test/local/CRUD/test_artifacts.py +0 -96
  41. test/local/CRUD/test_dataitems.py +0 -96
  42. test/local/CRUD/test_models.py +0 -95
  43. test/local/imports/test_imports.py +0 -65
  44. test/local/instances/test_validate.py +0 -55
  45. test/test_crud_functions.py +0 -109
  46. test/test_crud_runs.py +0 -86
  47. test/test_crud_tasks.py +0 -81
  48. test/testkfp.py +0 -37
  49. test/testkfp_pipeline.py +0 -22
  50. {digitalhub-0.10.0b2.dist-info → digitalhub-0.10.0b4.dist-info/licenses}/LICENSE.txt +0 -0
@@ -24,10 +24,10 @@ class EntityBuilder:
24
24
 
25
25
  # Class variables
26
26
  ENTITY_TYPE: str = None
27
- ENTITY_CLASS: Entity = None
28
- ENTITY_SPEC_CLASS: Spec = None
29
- ENTITY_SPEC_VALIDATOR: SpecValidator = None
30
- ENTITY_STATUS_CLASS: Status = None
27
+ ENTITY_CLASS: type[Entity] = None
28
+ ENTITY_SPEC_CLASS: type[Spec] = None
29
+ ENTITY_SPEC_VALIDATOR: type[SpecValidator] = None
30
+ ENTITY_STATUS_CLASS: type[Status] = None
31
31
  ENTITY_KIND: str = None
32
32
 
33
33
  def __init__(self) -> None:
@@ -60,7 +60,7 @@ class EntityBuilder:
60
60
  """
61
61
  return build_name(name)
62
62
 
63
- def build_uuid(self, uuid: str) -> str:
63
+ def build_uuid(self, uuid: str | None = None) -> str:
64
64
  """
65
65
  Build entity uuid.
66
66
 
@@ -6,6 +6,7 @@ from pathlib import Path
6
6
  from digitalhub.entities._base.versioned.entity import VersionedEntity
7
7
  from digitalhub.entities._operations.processor import processor
8
8
  from digitalhub.stores.api import get_store
9
+ from digitalhub.utils.types import SourcesOrListOfSources
9
10
 
10
11
  if typing.TYPE_CHECKING:
11
12
  from digitalhub.entities._base.entity.metadata import Metadata
@@ -34,9 +35,6 @@ class MaterialEntity(VersionedEntity):
34
35
  self.spec: MaterialSpec
35
36
  self.status: MaterialStatus
36
37
 
37
- # Init files info
38
- self._init_files_info()
39
-
40
38
  def save(self, update: bool = False) -> MaterialEntity:
41
39
  """
42
40
  Save entity into backend.
@@ -139,7 +137,7 @@ class MaterialEntity(VersionedEntity):
139
137
 
140
138
  return store.download(self.spec.path, dst=dst, src=paths, overwrite=overwrite)
141
139
 
142
- def upload(self, source: str | list[str]) -> None:
140
+ def upload(self, source: SourcesOrListOfSources) -> None:
143
141
  """
144
142
  Upload object from given local path to spec path destination.
145
143
  Source must be a local path. If the path is a folder, destination
@@ -178,17 +176,6 @@ class MaterialEntity(VersionedEntity):
178
176
  # Public Helpers
179
177
  ##############################
180
178
 
181
- def _init_files_info(self) -> None:
182
- """
183
- Initialize files info.
184
-
185
- Returns
186
- -------
187
- None
188
- """
189
- if self.status.files is None:
190
- self.status.files = []
191
-
192
179
  def add_files_info(self, files: list[dict]) -> None:
193
180
  """
194
181
  Add a file to the status.
@@ -207,13 +194,13 @@ class MaterialEntity(VersionedEntity):
207
194
  if f.get("path") not in path_list:
208
195
  self.status.files.append(f)
209
196
 
210
- def get_file_paths(self) -> list[str]:
197
+ def get_file_paths(self) -> list:
211
198
  """
212
199
  Get the paths of the files in the status.
213
200
 
214
201
  Returns
215
202
  -------
216
- list[str]
203
+ list
217
204
  Paths of the files in the status.
218
205
  """
219
206
  return [f.get("path") for f in self.status.files]
@@ -15,4 +15,4 @@ class MaterialStatus(Status):
15
15
  files: list[dict] | None = None,
16
16
  ) -> None:
17
17
  super().__init__(state, message)
18
- self.files = files
18
+ self.files = files if files is not None else []
@@ -1,9 +1,13 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Union
4
-
5
3
  from pydantic import BaseModel
6
4
 
5
+ from digitalhub.utils.types import MetricType
6
+
7
7
 
8
8
  class Metric(BaseModel):
9
- value: Union[float, int, list[Union[float, int]]]
9
+ """
10
+ Metric.
11
+ """
12
+
13
+ value: MetricType
@@ -6,9 +6,10 @@ from pydantic import ValidationError
6
6
 
7
7
  from digitalhub.entities._commons.enums import EntityTypes
8
8
  from digitalhub.entities._commons.models import Metric
9
+ from digitalhub.utils.types import MetricType
9
10
 
10
11
 
11
- def parse_entity_key(key: str) -> tuple[str]:
12
+ def parse_entity_key(key: str) -> tuple[str, str, str, str | None, str]:
12
13
  """
13
14
  Parse the entity key. Returns project, entity type, kind, name and uuid.
14
15
 
@@ -19,7 +20,7 @@ def parse_entity_key(key: str) -> tuple[str]:
19
20
 
20
21
  Returns
21
22
  -------
22
- tuple[str]
23
+ tuple[str, str, str, str | None, str]
23
24
  Project, entity type, kind, name and uuid.
24
25
  """
25
26
  try:
@@ -88,7 +89,7 @@ def get_project_from_key(key: str) -> str:
88
89
  return project
89
90
 
90
91
 
91
- def validate_metric_value(value: Any) -> float | int | list[float | int]:
92
+ def validate_metric_value(value: Any) -> MetricType:
92
93
  """
93
94
  Validate metric value.
94
95
 
@@ -99,7 +100,7 @@ def validate_metric_value(value: Any) -> float | int | list[float | int]:
99
100
 
100
101
  Returns
101
102
  -------
102
- float | int | list[float | int]
103
+ MetricType
103
104
  The validated value.
104
105
  """
105
106
  try:
@@ -10,6 +10,7 @@ from digitalhub.entities._commons.utils import get_project_from_key, parse_entit
10
10
  from digitalhub.factory.api import build_entity_from_dict, build_entity_from_params
11
11
  from digitalhub.utils.exceptions import ContextError, EntityAlreadyExistsError, EntityError, EntityNotExistsError
12
12
  from digitalhub.utils.io_utils import read_yaml
13
+ from digitalhub.utils.types import SourcesOrListOfSources
13
14
 
14
15
  if typing.TYPE_CHECKING:
15
16
  from digitalhub.client._base.client import Client
@@ -605,7 +606,7 @@ class OperationsProcessor:
605
606
  MaterialEntity
606
607
  Object instance.
607
608
  """
608
- source = kwargs.pop("source")
609
+ source: SourcesOrListOfSources = kwargs.pop("source")
609
610
  context = self._get_context(kwargs["project"])
610
611
  obj = build_entity_from_params(**kwargs)
611
612
  if context.is_running:
@@ -1382,7 +1383,7 @@ class OperationsProcessor:
1382
1383
  project=context.name,
1383
1384
  entity_type=entity_type,
1384
1385
  )
1385
- return context.client.update_object(api, data, **kwargs)
1386
+ context.client.update_object(api, data, **kwargs)
1386
1387
 
1387
1388
  def read_run_logs(
1388
1389
  self,
@@ -1453,7 +1454,7 @@ class OperationsProcessor:
1453
1454
  entity_type=entity_type,
1454
1455
  entity_id=entity_id,
1455
1456
  )
1456
- return context.client.create_object(api, **kwargs)
1457
+ context.client.create_object(api, **kwargs)
1457
1458
 
1458
1459
  def resume_run(
1459
1460
  self,
@@ -1488,7 +1489,7 @@ class OperationsProcessor:
1488
1489
  entity_type=entity_type,
1489
1490
  entity_id=entity_id,
1490
1491
  )
1491
- return context.client.create_object(api, **kwargs)
1492
+ context.client.create_object(api, **kwargs)
1492
1493
 
1493
1494
  def read_files_info(
1494
1495
  self,
@@ -1,5 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from typing import Optional
4
+
3
5
  from digitalhub.entities.artifact._base.spec import ArtifactSpec, ArtifactValidator
4
6
 
5
7
 
@@ -23,5 +25,5 @@ class ArtifactValidatorArtifact(ArtifactValidator):
23
25
  ArtifactValidatorArtifact validator.
24
26
  """
25
27
 
26
- src_path: str = None
28
+ src_path: Optional[str] = None
27
29
  """Source path of the artifact."""
@@ -6,6 +6,7 @@ from digitalhub.entities._commons.enums import EntityTypes
6
6
  from digitalhub.entities._operations.processor import processor
7
7
  from digitalhub.entities.artifact._base.entity import Artifact
8
8
  from digitalhub.entities.artifact.utils import eval_source, process_kwargs
9
+ from digitalhub.utils.types import SourcesOrListOfSources
9
10
 
10
11
  if typing.TYPE_CHECKING:
11
12
  from digitalhub.entities.artifact._base.entity import Artifact
@@ -78,7 +79,7 @@ def log_artifact(
78
79
  project: str,
79
80
  name: str,
80
81
  kind: str,
81
- source: list[str] | str,
82
+ source: SourcesOrListOfSources,
82
83
  path: str | None = None,
83
84
  **kwargs,
84
85
  ) -> Artifact:
@@ -93,7 +94,7 @@ def log_artifact(
93
94
  Object name.
94
95
  kind : str
95
96
  Kind the object.
96
- source : str
97
+ source : SourcesOrListOfSources
97
98
  Artifact location on local path.
98
99
  path : str
99
100
  Destination path of the artifact. If not provided, it's generated.
@@ -7,7 +7,7 @@ from digitalhub.entities.model.mlflow.builder import ModelModelBuilder
7
7
  from digitalhub.entities.project._base.builder import ProjectProjectBuilder
8
8
  from digitalhub.entities.secret._base.builder import SecretSecretBuilder
9
9
 
10
- entity_builders = (
10
+ entity_builders: tuple = (
11
11
  (ProjectProjectBuilder.ENTITY_KIND, ProjectProjectBuilder),
12
12
  (SecretSecretBuilder.ENTITY_KIND, SecretSecretBuilder),
13
13
  (ArtifactArtifactBuilder.ENTITY_KIND, ArtifactArtifactBuilder),
@@ -17,17 +17,14 @@ entity_builders = (
17
17
  )
18
18
 
19
19
  ##############################
20
- # Potential uninstalled entities
20
+ # Add custom entities here
21
21
  ##############################
22
22
 
23
23
 
24
24
  try:
25
25
  from digitalhub.entities.dataitem.iceberg.builder import DataitemIcebergBuilder
26
26
 
27
- entity_builders = (
28
- *entity_builders,
29
- (DataitemIcebergBuilder.ENTITY_KIND, DataitemIcebergBuilder),
30
- )
27
+ entity_builders += ((DataitemIcebergBuilder.ENTITY_KIND, DataitemIcebergBuilder),)
31
28
  except ImportError:
32
29
  ...
33
30
 
@@ -35,29 +32,20 @@ except ImportError:
35
32
  try:
36
33
  from digitalhub.entities.model.model.builder import ModelMlflowBuilder
37
34
 
38
- entity_builders = (
39
- *entity_builders,
40
- (ModelMlflowBuilder.ENTITY_KIND, ModelMlflowBuilder),
41
- )
35
+ entity_builders += ((ModelMlflowBuilder.ENTITY_KIND, ModelMlflowBuilder),)
42
36
  except ImportError:
43
37
  ...
44
38
 
45
39
  try:
46
40
  from digitalhub.entities.model.sklearn.builder import ModelSklearnBuilder
47
41
 
48
- entity_builders = (
49
- *entity_builders,
50
- (ModelSklearnBuilder.ENTITY_KIND, ModelSklearnBuilder),
51
- )
42
+ entity_builders += ((ModelSklearnBuilder.ENTITY_KIND, ModelSklearnBuilder),)
52
43
  except ImportError:
53
44
  ...
54
45
 
55
46
  try:
56
47
  from digitalhub.entities.model.huggingface.builder import ModelHuggingfaceBuilder
57
48
 
58
- entity_builders = (
59
- *entity_builders,
60
- (ModelHuggingfaceBuilder.ENTITY_KIND, ModelHuggingfaceBuilder),
61
- )
49
+ entity_builders += ((ModelHuggingfaceBuilder.ENTITY_KIND, ModelHuggingfaceBuilder),)
62
50
  except ImportError:
63
51
  ...
@@ -5,7 +5,8 @@ from typing import Any
5
5
 
6
6
  from digitalhub.entities._commons.enums import EntityTypes
7
7
  from digitalhub.entities._operations.processor import processor
8
- from digitalhub.entities.dataitem.utils import clean_tmp_path, eval_source, post_process, process_kwargs
8
+ from digitalhub.entities.dataitem.utils import clean_tmp_path, eval_data, eval_source, post_process, process_kwargs
9
+ from digitalhub.utils.types import SourcesOrListOfSources
9
10
 
10
11
  if typing.TYPE_CHECKING:
11
12
  from digitalhub.entities.dataitem._base.entity import Dataitem
@@ -78,9 +79,11 @@ def log_dataitem(
78
79
  project: str,
79
80
  name: str,
80
81
  kind: str,
81
- source: list[str] | str | None = None,
82
+ source: SourcesOrListOfSources | None = None,
82
83
  data: Any | None = None,
83
84
  path: str | None = None,
85
+ file_format: str | None = None,
86
+ engine: str | None = "pandas",
84
87
  **kwargs,
85
88
  ) -> Dataitem:
86
89
  """
@@ -94,12 +97,16 @@ def log_dataitem(
94
97
  Object name.
95
98
  kind : str
96
99
  Kind the object.
97
- source : str
100
+ source : SourcesOrListOfSources
98
101
  Dataitem location on local path.
99
102
  data : Any
100
103
  Dataframe to log. Alternative to source.
101
104
  path : str
102
105
  Destination path of the dataitem. If not provided, it's generated.
106
+ file_format : str
107
+ Extension of the file.
108
+ engine : str
109
+ Dataframe engine (pandas, polars, etc.).
103
110
  **kwargs : dict
104
111
  New dataitem spec parameters.
105
112
 
@@ -115,7 +122,12 @@ def log_dataitem(
115
122
  >>> kind="table",
116
123
  >>> data=df)
117
124
  """
125
+ cleanup = False
126
+ if data is not None:
127
+ cleanup = True
128
+
118
129
  source = eval_source(source, data, kind, name, project)
130
+ data = eval_data(project, kind, source, data, file_format, engine)
119
131
  kwargs = process_kwargs(project, name, kind, source=source, data=data, path=path, **kwargs)
120
132
  obj = processor.log_material_entity(
121
133
  source=source,
@@ -124,8 +136,8 @@ def log_dataitem(
124
136
  kind=kind,
125
137
  **kwargs,
126
138
  )
127
- if data is not None:
128
- obj = post_process(obj, data)
139
+ obj = post_process(obj, data)
140
+ if cleanup:
129
141
  clean_tmp_path(source)
130
142
  return obj
131
143
 
@@ -1,6 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from enum import Enum
4
+ from typing import Optional
4
5
 
5
6
  from pydantic import BaseModel, ConfigDict, Field
6
7
 
@@ -40,16 +41,16 @@ class TableSchemaFieldEntry(BaseModel):
40
41
  type_: FieldType = Field(alias="type")
41
42
  """Field type."""
42
43
 
43
- title: str = None
44
+ title: Optional[str] = None
44
45
  """Field title."""
45
46
 
46
47
  format_: str = Field(default=None, alias="format")
47
48
  """Field format."""
48
49
 
49
- example: str = None
50
+ example: Optional[str] = None
50
51
  """Field example."""
51
52
 
52
- description: str = None
53
+ description: Optional[str] = None
53
54
  """Field description."""
54
55
 
55
56
 
@@ -76,9 +76,9 @@ def filter_memoryview(data: list[dict]) -> list[dict]:
76
76
  return data
77
77
 
78
78
 
79
- def check_preview_size(preview: dict) -> list:
79
+ def check_preview_size(preview: dict) -> dict:
80
80
  """
81
- Check preview size. If it's too big, return empty list.
81
+ Check preview size. If it's too big, return empty dict.
82
82
 
83
83
  Parameters
84
84
  ----------
@@ -87,11 +87,11 @@ def check_preview_size(preview: dict) -> list:
87
87
 
88
88
  Returns
89
89
  -------
90
- list
90
+ dict
91
91
  Preview.
92
92
  """
93
93
  if len(dump_json(preview)) >= 64000:
94
- return []
94
+ return {}
95
95
  return preview
96
96
 
97
97
 
@@ -101,9 +101,9 @@ def finalize_preview(preview: list[dict] | None = None, rows_count: int | None =
101
101
 
102
102
  Parameters
103
103
  ----------
104
- preview : list[dict] | None
104
+ preview : list[dict]
105
105
  Preview.
106
- rows_count : int | None
106
+ rows_count : int
107
107
  Row count.
108
108
 
109
109
  Returns
@@ -111,7 +111,7 @@ def finalize_preview(preview: list[dict] | None = None, rows_count: int | None =
111
111
  dict
112
112
  Data preview.
113
113
  """
114
- data = {}
114
+ data: dict[str, list[dict] | int] = {}
115
115
  if preview is not None:
116
116
  data["cols"] = preview
117
117
  if rows_count is not None:
@@ -9,7 +9,9 @@ from digitalhub.entities._base.entity._constructors.uuid import build_uuid
9
9
  from digitalhub.entities._base.material.utils import build_log_path_from_source, eval_local_source
10
10
  from digitalhub.entities._commons.enums import EntityKinds, EntityTypes
11
11
  from digitalhub.readers.data.api import get_reader_by_object
12
+ from digitalhub.stores.api import get_store
12
13
  from digitalhub.utils.generic_utils import slugify_string
14
+ from digitalhub.utils.types import SourcesOrListOfSources
13
15
 
14
16
  if typing.TYPE_CHECKING:
15
17
  from digitalhub.entities.dataitem._base.entity import Dataitem
@@ -19,7 +21,7 @@ DEFAULT_EXTENSION = "parquet"
19
21
 
20
22
 
21
23
  def eval_source(
22
- source: str | list[str] | None = None,
24
+ source: SourcesOrListOfSources | None = None,
23
25
  data: Any | None = None,
24
26
  kind: str | None = None,
25
27
  name: str | None = None,
@@ -30,7 +32,7 @@ def eval_source(
30
32
 
31
33
  Parameters
32
34
  ----------
33
- source : str | list[str]
35
+ source : SourcesOrListOfSources
34
36
  Source(s).
35
37
 
36
38
  Returns
@@ -54,11 +56,49 @@ def eval_source(
54
56
  raise NotImplementedError
55
57
 
56
58
 
59
+ def eval_data(
60
+ project: str,
61
+ kind: str,
62
+ source: SourcesOrListOfSources,
63
+ data: Any | None = None,
64
+ file_format: str | None = None,
65
+ engine: str | None = None,
66
+ ) -> Any:
67
+ """
68
+ Evaluate data is loaded.
69
+
70
+ Parameters
71
+ ----------
72
+ project : str
73
+ Project name.
74
+ source : str
75
+ Source(s).
76
+ data : Any
77
+ Dataframe to log. Alternative to source.
78
+ file_format : str
79
+ Extension of the file.
80
+ engine : str
81
+ Engine to use.
82
+
83
+ Returns
84
+ -------
85
+ None
86
+ """
87
+ if kind == EntityKinds.DATAITEM_TABLE.value:
88
+ if data is None:
89
+ return get_store(project, source).read_df(
90
+ source,
91
+ file_format=file_format,
92
+ engine=engine,
93
+ )
94
+ return data
95
+
96
+
57
97
  def process_kwargs(
58
98
  project: str,
59
99
  name: str,
60
100
  kind: str,
61
- source: str | list[str],
101
+ source: SourcesOrListOfSources,
62
102
  data: Any | None = None,
63
103
  path: str | None = None,
64
104
  **kwargs,
@@ -74,7 +114,7 @@ def process_kwargs(
74
114
  Object name.
75
115
  kind : str
76
116
  Kind the object.
77
- source : str
117
+ source : SourcesOrListOfSources
78
118
  Source(s).
79
119
  data : Any
80
120
  Dataframe to log. Alternative to source.
@@ -101,19 +141,23 @@ def process_kwargs(
101
141
  return kwargs
102
142
 
103
143
 
104
- def clean_tmp_path(pth: str) -> None:
144
+ def clean_tmp_path(pth: SourcesOrListOfSources) -> None:
105
145
  """
106
146
  Clean temporary path.
107
147
 
108
148
  Parameters
109
149
  ----------
110
- pth : str
150
+ pth : SourcesOrListOfSources
111
151
  Path to clean.
112
152
 
113
153
  Returns
114
154
  -------
115
155
  None
116
156
  """
157
+ if isinstance(pth, list):
158
+ for p in pth:
159
+ shutil.rmtree(p, ignore_errors=True)
160
+ return
117
161
  shutil.rmtree(pth, ignore_errors=True)
118
162
 
119
163
 
@@ -1,5 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from typing import Optional
4
+
3
5
  from digitalhub.entities._base.material.spec import MaterialSpec, MaterialValidator
4
6
 
5
7
 
@@ -15,7 +17,7 @@ class ModelSpec(MaterialSpec):
15
17
  algorithm: str | None = None,
16
18
  parameters: dict | None = None,
17
19
  ) -> None:
18
- self.path = path
20
+ super().__init__(path)
19
21
  self.framework = framework
20
22
  self.algorithm = algorithm
21
23
  self.parameters = parameters
@@ -26,14 +28,11 @@ class ModelValidator(MaterialValidator):
26
28
  ModelValidator validator.
27
29
  """
28
30
 
29
- path: str
30
- """Path to the model."""
31
-
32
- framework: str = None
31
+ framework: Optional[str] = None
33
32
  """Model framework (e.g. 'pytorch')."""
34
33
 
35
- algorithm: str = None
34
+ algorithm: Optional[str] = None
36
35
  """Model algorithm (e.g. 'resnet')."""
37
36
 
38
- parameters: dict = None
37
+ parameters: Optional[dict] = None
39
38
  """Model validator."""
@@ -5,6 +5,7 @@ import typing
5
5
  from digitalhub.entities._commons.enums import EntityTypes
6
6
  from digitalhub.entities._operations.processor import processor
7
7
  from digitalhub.entities.artifact.utils import eval_source, process_kwargs
8
+ from digitalhub.utils.types import SourcesOrListOfSources
8
9
 
9
10
  if typing.TYPE_CHECKING:
10
11
  from digitalhub.entities.model._base.entity import Model
@@ -77,7 +78,7 @@ def log_model(
77
78
  project: str,
78
79
  name: str,
79
80
  kind: str,
80
- source: list[str] | str,
81
+ source: SourcesOrListOfSources,
81
82
  path: str | None = None,
82
83
  **kwargs,
83
84
  ) -> Model:
@@ -92,7 +93,7 @@ def log_model(
92
93
  Object name.
93
94
  kind : str
94
95
  Kind the object.
95
- source : str
96
+ source : SourcesOrListOfSources
96
97
  Model location on local path.
97
98
  path : str
98
99
  Destination path of the model. If not provided, it's generated.
@@ -1,5 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from typing import Optional
4
+
3
5
  from pydantic import Field
4
6
 
5
7
  from digitalhub.entities.model._base.spec import ModelSpec, ModelValidator
@@ -18,7 +20,7 @@ class ModelSpecHuggingface(ModelSpec):
18
20
  parameters: dict | None = None,
19
21
  base_model: str | None = None,
20
22
  model_id: str | None = None,
21
- model_revision: str = None,
23
+ model_revision: str | None = None,
22
24
  ) -> None:
23
25
  super().__init__(path, framework, algorithm, parameters)
24
26
  self.base_model = base_model
@@ -31,7 +33,7 @@ class ModelValidatorHuggingface(ModelValidator):
31
33
  ModelValidatorHuggingface validator.
32
34
  """
33
35
 
34
- base_model: str = None
36
+ base_model: Optional[str] = None
35
37
  """Base model."""
36
38
 
37
39
  placeholder_model_id: str = Field(default=None, alias="model_id")
@@ -1,5 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from typing import Optional
4
+
3
5
  from pydantic import Field
4
6
 
5
7
  from digitalhub.entities.model._base.spec import ModelSpec, ModelValidator
@@ -20,7 +22,7 @@ class ModelSpecMlflow(ModelSpec):
20
22
  flavor: str | None = None,
21
23
  model_config: dict | None = None,
22
24
  input_datasets: list[Dataset] | None = None,
23
- signature: Signature = None,
25
+ signature: Signature | None = None,
24
26
  ) -> None:
25
27
  super().__init__(path, framework, algorithm, parameters)
26
28
  self.flavor = flavor
@@ -34,14 +36,14 @@ class ModelValidatorMlflow(ModelValidator):
34
36
  ModelValidatorMlflow validator.
35
37
  """
36
38
 
37
- flavor: str = None
39
+ flavor: Optional[str] = None
38
40
  """Mlflow model flavor."""
39
41
 
40
42
  placeholder_cfg_: dict = Field(default=None, alias="model_config")
41
43
  """Mlflow model config."""
42
44
 
43
- input_datasets: list[Dataset] = None
45
+ input_datasets: Optional[list[Dataset]] = None
44
46
  """Mlflow input datasets."""
45
47
 
46
- signature: Signature = None
48
+ signature: Optional[Signature] = None
47
49
  """Mlflow model signature."""