digitalhub 0.8.0__py3-none-any.whl → 0.8.0b1__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 (248) hide show
  1. digitalhub/__init__.py +4 -5
  2. digitalhub/client/builder.py +58 -3
  3. digitalhub/client/{dhcore/client.py → objects/dhcore.py} +60 -48
  4. digitalhub/client/{local/client.py → objects/local.py} +2 -2
  5. digitalhub/context/builder.py +85 -1
  6. digitalhub/context/context.py +1 -1
  7. digitalhub/datastores/builder.py +37 -13
  8. digitalhub/datastores/{_base/datastore.py → objects/base.py} +3 -3
  9. digitalhub/datastores/{local/datastore.py → objects/local.py} +2 -10
  10. digitalhub/datastores/{remote/datastore.py → objects/remote.py} +1 -9
  11. digitalhub/datastores/{s3/datastore.py → objects/s3.py} +2 -10
  12. digitalhub/datastores/{sql/datastore.py → objects/sql.py} +2 -10
  13. digitalhub/entities/_base/{_base/entity.py → base.py} +1 -1
  14. digitalhub/entities/_base/crud.py +389 -247
  15. digitalhub/entities/_base/entity/{entity.py → base.py} +34 -8
  16. digitalhub/entities/_base/{context/entity.py → entity/context.py} +6 -6
  17. digitalhub/entities/_base/{executable/entity.py → entity/executable.py} +36 -61
  18. digitalhub/entities/_base/{material/entity.py → entity/material.py} +6 -6
  19. digitalhub/entities/_base/entity/unversioned.py +87 -0
  20. digitalhub/entities/_base/entity/versioned.py +94 -0
  21. digitalhub/entities/_base/{entity/metadata.py → metadata.py} +2 -2
  22. digitalhub/entities/_base/{entity/spec.py → spec/base.py} +11 -11
  23. digitalhub/entities/_base/{material/spec.py → spec/material.py} +3 -3
  24. digitalhub/entities/_base/{entity/status.py → status/base.py} +3 -14
  25. digitalhub/entities/_base/{material/status.py → status/material.py} +1 -1
  26. digitalhub/entities/_builders/metadata.py +60 -0
  27. digitalhub/entities/_builders/spec.py +43 -0
  28. digitalhub/entities/_builders/status.py +62 -0
  29. digitalhub/entities/{_base/entity/_constructors → _builders}/uuid.py +11 -4
  30. digitalhub/entities/artifact/builder.py +133 -0
  31. digitalhub/entities/artifact/crud.py +48 -22
  32. digitalhub/entities/artifact/{_base/entity.py → entity/_base.py} +5 -5
  33. digitalhub/entities/artifact/entity/artifact.py +9 -0
  34. digitalhub/entities/artifact/{artifact/spec.py → spec.py} +16 -4
  35. digitalhub/entities/artifact/{artifact/status.py → status.py} +1 -1
  36. digitalhub/entities/dataitem/builder.py +144 -0
  37. digitalhub/entities/dataitem/crud.py +52 -29
  38. digitalhub/entities/dataitem/{_base/entity.py → entity/_base.py} +5 -5
  39. digitalhub/entities/dataitem/entity/dataitem.py +9 -0
  40. digitalhub/entities/dataitem/entity/iceberg.py +7 -0
  41. digitalhub/entities/dataitem/{table/entity.py → entity/table.py} +4 -25
  42. digitalhub/entities/dataitem/spec.py +61 -0
  43. digitalhub/entities/dataitem/status.py +38 -0
  44. digitalhub/entities/function/builder.py +86 -0
  45. digitalhub/entities/function/crud.py +43 -17
  46. digitalhub/entities/function/{_base/entity.py → entity.py} +12 -9
  47. digitalhub/entities/function/{_base/models.py → models.py} +1 -1
  48. digitalhub/entities/function/spec.py +81 -0
  49. digitalhub/entities/function/status.py +9 -0
  50. digitalhub/entities/model/builder.py +152 -0
  51. digitalhub/entities/model/crud.py +48 -21
  52. digitalhub/entities/model/{_base/entity.py → entity/_base.py} +5 -5
  53. digitalhub/entities/model/entity/huggingface.py +9 -0
  54. digitalhub/entities/model/{mlflow/utils.py → entity/mlflow.py} +10 -1
  55. digitalhub/entities/model/entity/model.py +9 -0
  56. digitalhub/entities/model/entity/sklearn.py +9 -0
  57. digitalhub/entities/model/spec.py +146 -0
  58. digitalhub/entities/model/status.py +33 -0
  59. digitalhub/entities/project/builder.py +82 -0
  60. digitalhub/entities/project/crud.py +12 -19
  61. digitalhub/entities/project/{_base/entity.py → entity.py} +102 -120
  62. digitalhub/entities/project/{_base/spec.py → spec.py} +4 -4
  63. digitalhub/entities/project/status.py +9 -0
  64. digitalhub/entities/registries.py +48 -0
  65. digitalhub/entities/run/builder.py +77 -0
  66. digitalhub/entities/run/crud.py +33 -20
  67. digitalhub/entities/run/{_base/entity.py → entity.py} +189 -35
  68. digitalhub/entities/run/spec.py +153 -0
  69. digitalhub/entities/run/status.py +114 -0
  70. digitalhub/entities/secret/builder.py +93 -0
  71. digitalhub/entities/secret/crud.py +31 -27
  72. digitalhub/entities/secret/{_base/entity.py → entity.py} +7 -8
  73. digitalhub/entities/secret/{_base/spec.py → spec.py} +4 -4
  74. digitalhub/entities/secret/status.py +9 -0
  75. digitalhub/entities/task/builder.py +74 -0
  76. digitalhub/entities/task/crud.py +33 -20
  77. digitalhub/entities/task/{_base/entity.py → entity.py} +8 -9
  78. digitalhub/entities/task/{_base/models.py → models.py} +0 -9
  79. digitalhub/entities/task/{_base/spec.py → spec.py} +7 -9
  80. digitalhub/entities/task/status.py +9 -0
  81. digitalhub/entities/{utils/utils.py → utils.py} +2 -20
  82. digitalhub/entities/workflow/builder.py +91 -0
  83. digitalhub/entities/workflow/crud.py +43 -17
  84. digitalhub/entities/workflow/{_base/entity.py → entity.py} +12 -9
  85. digitalhub/entities/workflow/spec.py +15 -0
  86. digitalhub/entities/workflow/status.py +9 -0
  87. digitalhub/readers/builder.py +54 -0
  88. digitalhub/readers/{pandas/reader.py → objects/pandas.py} +1 -1
  89. digitalhub/readers/registry.py +15 -0
  90. digitalhub/registry/models.py +87 -0
  91. digitalhub/registry/registry.py +74 -0
  92. digitalhub/registry/utils.py +150 -0
  93. digitalhub/runtimes/{_base.py → base.py} +65 -3
  94. digitalhub/runtimes/builder.py +40 -19
  95. digitalhub/runtimes/kind_registry.py +170 -0
  96. digitalhub/stores/builder.py +52 -6
  97. digitalhub/stores/{local/store.py → objects/local.py} +1 -1
  98. digitalhub/stores/{remote/store.py → objects/remote.py} +1 -1
  99. digitalhub/stores/{s3/store.py → objects/s3.py} +1 -1
  100. digitalhub/stores/{sql/store.py → objects/sql.py} +1 -1
  101. digitalhub/{client/dhcore/utils.py → utils/env_utils.py} +14 -2
  102. digitalhub/utils/exceptions.py +0 -12
  103. digitalhub/utils/generic_utils.py +42 -18
  104. digitalhub/utils/io_utils.py +2 -39
  105. {digitalhub-0.8.0.dist-info → digitalhub-0.8.0b1.dist-info}/METADATA +2 -3
  106. digitalhub-0.8.0b1.dist-info/RECORD +161 -0
  107. {digitalhub-0.8.0.dist-info → digitalhub-0.8.0b1.dist-info}/WHEEL +1 -1
  108. test/test_crud_artifacts.py +96 -0
  109. test/test_crud_dataitems.py +96 -0
  110. test/test_crud_functions.py +1 -1
  111. test/test_crud_runs.py +1 -1
  112. test/test_crud_tasks.py +1 -1
  113. digitalhub/client/api.py +0 -63
  114. digitalhub/client/dhcore/env.py +0 -21
  115. digitalhub/client/dhcore/models.py +0 -46
  116. digitalhub/context/api.py +0 -93
  117. digitalhub/datastores/api.py +0 -37
  118. digitalhub/entities/_base/api_utils.py +0 -620
  119. digitalhub/entities/_base/entity/_constructors/metadata.py +0 -44
  120. digitalhub/entities/_base/entity/_constructors/spec.py +0 -33
  121. digitalhub/entities/_base/entity/_constructors/status.py +0 -52
  122. digitalhub/entities/_base/entity/builder.py +0 -175
  123. digitalhub/entities/_base/executable/__init__.py +0 -0
  124. digitalhub/entities/_base/material/__init__.py +0 -0
  125. digitalhub/entities/_base/runtime_entity/__init__.py +0 -0
  126. digitalhub/entities/_base/runtime_entity/builder.py +0 -106
  127. digitalhub/entities/_base/unversioned/__init__.py +0 -0
  128. digitalhub/entities/_base/unversioned/builder.py +0 -66
  129. digitalhub/entities/_base/unversioned/entity.py +0 -49
  130. digitalhub/entities/_base/versioned/__init__.py +0 -0
  131. digitalhub/entities/_base/versioned/builder.py +0 -68
  132. digitalhub/entities/_base/versioned/entity.py +0 -53
  133. digitalhub/entities/artifact/_base/__init__.py +0 -0
  134. digitalhub/entities/artifact/_base/builder.py +0 -86
  135. digitalhub/entities/artifact/_base/spec.py +0 -15
  136. digitalhub/entities/artifact/_base/status.py +0 -9
  137. digitalhub/entities/artifact/artifact/__init__.py +0 -0
  138. digitalhub/entities/artifact/artifact/builder.py +0 -18
  139. digitalhub/entities/artifact/artifact/entity.py +0 -32
  140. digitalhub/entities/builders.py +0 -63
  141. digitalhub/entities/dataitem/_base/__init__.py +0 -0
  142. digitalhub/entities/dataitem/_base/builder.py +0 -86
  143. digitalhub/entities/dataitem/_base/spec.py +0 -15
  144. digitalhub/entities/dataitem/_base/status.py +0 -20
  145. digitalhub/entities/dataitem/dataitem/__init__.py +0 -0
  146. digitalhub/entities/dataitem/dataitem/builder.py +0 -18
  147. digitalhub/entities/dataitem/dataitem/entity.py +0 -32
  148. digitalhub/entities/dataitem/dataitem/spec.py +0 -15
  149. digitalhub/entities/dataitem/dataitem/status.py +0 -9
  150. digitalhub/entities/dataitem/iceberg/__init__.py +0 -0
  151. digitalhub/entities/dataitem/iceberg/builder.py +0 -18
  152. digitalhub/entities/dataitem/iceberg/entity.py +0 -32
  153. digitalhub/entities/dataitem/iceberg/spec.py +0 -15
  154. digitalhub/entities/dataitem/iceberg/status.py +0 -9
  155. digitalhub/entities/dataitem/table/__init__.py +0 -0
  156. digitalhub/entities/dataitem/table/builder.py +0 -18
  157. digitalhub/entities/dataitem/table/spec.py +0 -25
  158. digitalhub/entities/dataitem/table/status.py +0 -9
  159. digitalhub/entities/function/_base/__init__.py +0 -0
  160. digitalhub/entities/function/_base/builder.py +0 -79
  161. digitalhub/entities/function/_base/spec.py +0 -15
  162. digitalhub/entities/function/_base/status.py +0 -9
  163. digitalhub/entities/model/_base/__init__.py +0 -0
  164. digitalhub/entities/model/_base/builder.py +0 -86
  165. digitalhub/entities/model/_base/spec.py +0 -49
  166. digitalhub/entities/model/_base/status.py +0 -9
  167. digitalhub/entities/model/huggingface/__init__.py +0 -0
  168. digitalhub/entities/model/huggingface/builder.py +0 -18
  169. digitalhub/entities/model/huggingface/entity.py +0 -32
  170. digitalhub/entities/model/huggingface/spec.py +0 -36
  171. digitalhub/entities/model/huggingface/status.py +0 -9
  172. digitalhub/entities/model/mlflow/__init__.py +0 -0
  173. digitalhub/entities/model/mlflow/builder.py +0 -18
  174. digitalhub/entities/model/mlflow/entity.py +0 -32
  175. digitalhub/entities/model/mlflow/spec.py +0 -44
  176. digitalhub/entities/model/mlflow/status.py +0 -9
  177. digitalhub/entities/model/model/__init__.py +0 -0
  178. digitalhub/entities/model/model/builder.py +0 -18
  179. digitalhub/entities/model/model/entity.py +0 -32
  180. digitalhub/entities/model/model/spec.py +0 -15
  181. digitalhub/entities/model/model/status.py +0 -9
  182. digitalhub/entities/model/sklearn/__init__.py +0 -0
  183. digitalhub/entities/model/sklearn/builder.py +0 -18
  184. digitalhub/entities/model/sklearn/entity.py +0 -32
  185. digitalhub/entities/model/sklearn/spec.py +0 -15
  186. digitalhub/entities/model/sklearn/status.py +0 -9
  187. digitalhub/entities/project/_base/__init__.py +0 -0
  188. digitalhub/entities/project/_base/builder.py +0 -128
  189. digitalhub/entities/project/_base/status.py +0 -9
  190. digitalhub/entities/run/_base/__init__.py +0 -0
  191. digitalhub/entities/run/_base/builder.py +0 -94
  192. digitalhub/entities/run/_base/spec.py +0 -50
  193. digitalhub/entities/run/_base/status.py +0 -9
  194. digitalhub/entities/secret/_base/__init__.py +0 -0
  195. digitalhub/entities/secret/_base/builder.py +0 -81
  196. digitalhub/entities/secret/_base/status.py +0 -9
  197. digitalhub/entities/task/_base/__init__.py +0 -0
  198. digitalhub/entities/task/_base/builder.py +0 -91
  199. digitalhub/entities/task/_base/status.py +0 -9
  200. digitalhub/entities/utils/__init__.py +0 -0
  201. digitalhub/entities/workflow/_base/__init__.py +0 -0
  202. digitalhub/entities/workflow/_base/builder.py +0 -79
  203. digitalhub/entities/workflow/_base/spec.py +0 -15
  204. digitalhub/entities/workflow/_base/status.py +0 -9
  205. digitalhub/factory/__init__.py +0 -0
  206. digitalhub/factory/api.py +0 -277
  207. digitalhub/factory/factory.py +0 -268
  208. digitalhub/factory/utils.py +0 -90
  209. digitalhub/readers/_base/__init__.py +0 -0
  210. digitalhub/readers/_base/builder.py +0 -26
  211. digitalhub/readers/api.py +0 -80
  212. digitalhub/readers/factory.py +0 -133
  213. digitalhub/readers/pandas/__init__.py +0 -0
  214. digitalhub/readers/pandas/builder.py +0 -29
  215. digitalhub/stores/_base/__init__.py +0 -0
  216. digitalhub/stores/api.py +0 -54
  217. digitalhub/stores/local/__init__.py +0 -0
  218. digitalhub/stores/remote/__init__.py +0 -0
  219. digitalhub/stores/s3/__init__.py +0 -0
  220. digitalhub/stores/sql/__init__.py +0 -0
  221. digitalhub/utils/s3_utils.py +0 -58
  222. digitalhub-0.8.0.dist-info/RECORD +0 -231
  223. test/local/CRUD/test_artifacts.py +0 -96
  224. test/local/CRUD/test_dataitems.py +0 -96
  225. test/local/CRUD/test_models.py +0 -95
  226. /digitalhub/client/{_base → objects}/__init__.py +0 -0
  227. /digitalhub/client/{_base/client.py → objects/base.py} +0 -0
  228. /digitalhub/{client/dhcore → datastores/objects}/__init__.py +0 -0
  229. /digitalhub/entities/{utils → _base}/api.py +0 -0
  230. /digitalhub/{client/local → entities/_base/spec}/__init__.py +0 -0
  231. /digitalhub/entities/{utils → _base}/state.py +0 -0
  232. /digitalhub/{datastores/_base → entities/_base/status}/__init__.py +0 -0
  233. /digitalhub/{datastores/local → entities/_builders}/__init__.py +0 -0
  234. /digitalhub/entities/{_base/entity/_constructors → _builders}/name.py +0 -0
  235. /digitalhub/{datastores/remote → entities/artifact/entity}/__init__.py +0 -0
  236. /digitalhub/{datastores/s3 → entities/dataitem/entity}/__init__.py +0 -0
  237. /digitalhub/entities/dataitem/{table/models.py → models.py} +0 -0
  238. /digitalhub/entities/{utils/entity_types.py → entity_types.py} +0 -0
  239. /digitalhub/{datastores/sql → entities/model/entity}/__init__.py +0 -0
  240. /digitalhub/entities/model/{mlflow/models.py → models.py} +0 -0
  241. /digitalhub/{entities/_base/_base → readers/objects}/__init__.py +0 -0
  242. /digitalhub/readers/{_base/reader.py → objects/base.py} +0 -0
  243. /digitalhub/{entities/_base/context → registry}/__init__.py +0 -0
  244. /digitalhub/{entities/_base/entity/_constructors → stores/objects}/__init__.py +0 -0
  245. /digitalhub/stores/{_base/store.py → objects/base.py} +0 -0
  246. {digitalhub-0.8.0.dist-info → digitalhub-0.8.0b1.dist-info}/LICENSE.txt +0 -0
  247. {digitalhub-0.8.0.dist-info → digitalhub-0.8.0b1.dist-info}/top_level.txt +0 -0
  248. /test/{local/imports/test_imports.py → test_imports.py} +0 -0
digitalhub/__init__.py CHANGED
@@ -68,15 +68,14 @@ from digitalhub.entities.workflow.crud import (
68
68
  )
69
69
 
70
70
  try:
71
- from digitalhub.entities.model.mlflow.utils import from_mlflow_run
71
+ from digitalhub.entities.model.entity.mlflow import from_mlflow_run
72
72
  except ImportError:
73
73
  ...
74
74
 
75
- from digitalhub.client.dhcore.utils import refresh_token, set_dhcore_env
75
+ from digitalhub.registry.utils import register_entities, register_runtimes_entities
76
+ from digitalhub.stores.builder import set_store
77
+ from digitalhub.utils.env_utils import refresh_token, set_dhcore_env
76
78
 
77
79
  # Register entities into registry
78
- from digitalhub.factory.utils import register_entities, register_runtimes_entities
79
- from digitalhub.stores.api import set_store
80
-
81
80
  register_entities()
82
81
  register_runtimes_entities()
@@ -2,11 +2,11 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.client.dhcore.client import ClientDHCore
6
- from digitalhub.client.local.client import ClientLocal
5
+ from digitalhub.client.objects.dhcore import ClientDHCore
6
+ from digitalhub.client.objects.local import ClientLocal
7
7
 
8
8
  if typing.TYPE_CHECKING:
9
- from digitalhub.client._base.client import Client
9
+ from digitalhub.client.objects.base import Client
10
10
 
11
11
 
12
12
  class ClientBuilder:
@@ -47,4 +47,59 @@ class ClientBuilder:
47
47
  return self._dhcore
48
48
 
49
49
 
50
+ def get_client(local: bool = False) -> Client:
51
+ """
52
+ Wrapper around ClientBuilder.build.
53
+
54
+ Parameters
55
+ ----------
56
+ local : bool
57
+ Whether to create a local client or not.
58
+
59
+ Returns
60
+ -------
61
+ Client
62
+ The client instance.
63
+ """
64
+ return client_builder.build(local)
65
+
66
+
67
+ def build_client(local: bool = False, config: dict | None = None) -> None:
68
+ """
69
+ Wrapper around ClientBuilder.build.
70
+
71
+ Parameters
72
+ ----------
73
+ local : bool
74
+ Whether to create a local client or not.
75
+ config : dict
76
+ DHCore environment configuration.
77
+
78
+ Returns
79
+ -------
80
+ Client
81
+ The client instance.
82
+ """
83
+ client_builder.build(local, config)
84
+
85
+
86
+ def check_client_exists(local: bool = False) -> bool:
87
+ """
88
+ Check if client exists.
89
+
90
+ Parameters
91
+ ----------
92
+ local : bool
93
+ Check client existence by local.
94
+
95
+ Returns
96
+ -------
97
+ bool
98
+ True if client exists, False otherwise.
99
+ """
100
+ if local:
101
+ return client_builder._local is not None
102
+ return client_builder._dhcore is not None
103
+
104
+
50
105
  client_builder = ClientBuilder()
@@ -1,18 +1,15 @@
1
1
  from __future__ import annotations
2
2
 
3
- import datetime
4
- import json
5
3
  import os
6
4
  import typing
7
5
  from urllib.parse import urlparse
8
6
 
9
7
  from dotenv import load_dotenv, set_key
8
+ from pydantic import BaseModel
10
9
  from requests import request
11
10
  from requests.exceptions import HTTPError, JSONDecodeError, RequestException
12
11
 
13
- from digitalhub.client._base.client import Client
14
- from digitalhub.client.dhcore.env import ENV_FILE, FALLBACK_USER, MAX_API_LEVEL, MIN_API_LEVEL
15
- from digitalhub.client.dhcore.models import BasicAuth, OAuth2TokenAuth
12
+ from digitalhub.client.objects.base import Client
16
13
  from digitalhub.utils.exceptions import (
17
14
  BackendError,
18
15
  BadRequestError,
@@ -27,6 +24,52 @@ if typing.TYPE_CHECKING:
27
24
  from requests import Response
28
25
 
29
26
 
27
+ # Use env user as fallback in the API calls
28
+ try:
29
+ FALLBACK_USER = os.getlogin()
30
+ except Exception:
31
+ FALLBACK_USER = None
32
+
33
+ # File where to write DHCORE_ACCESS_TOKEN and DHCORE_REFRESH_TOKEN
34
+ # It's used because we inject the variables in jupyter env,
35
+ # but refresh token is only available once. Is it's used, we cannot
36
+ # overwrite it with coder, so we need to store the new one in a file,
37
+ # preserved for jupyter restart
38
+ ENV_FILE = ".dhcore"
39
+
40
+
41
+ # API levels that are supported
42
+ MAX_API_LEVEL = 20
43
+ MIN_API_LEVEL = 8
44
+
45
+
46
+ class AuthConfig(BaseModel):
47
+ """Client configuration model."""
48
+
49
+ user: str = FALLBACK_USER
50
+ """Username."""
51
+
52
+
53
+ class OAuth2TokenAuth(AuthConfig):
54
+ """OAuth2 token authentication model."""
55
+
56
+ access_token: str
57
+ """OAuth2 token."""
58
+
59
+ refresh_token: str = None
60
+ """OAuth2 refresh token."""
61
+
62
+ client_id: str = None
63
+ """OAuth2 client id."""
64
+
65
+
66
+ class BasicAuth(AuthConfig):
67
+ """Basic authentication model."""
68
+
69
+ password: str
70
+ """Basic authentication password."""
71
+
72
+
30
73
  class ClientDHCore(Client):
31
74
  """
32
75
  DHCore client.
@@ -85,10 +128,7 @@ class ClientDHCore(Client):
85
128
  dict
86
129
  Response object.
87
130
  """
88
- if "headers" not in kwargs:
89
- kwargs["headers"] = {}
90
- kwargs["headers"]["Content-Type"] = "application/json"
91
- kwargs["data"] = json.dumps(obj, default=ClientDHCore._json_serialize)
131
+ kwargs["json"] = obj
92
132
  return self._prepare_call("POST", api, **kwargs)
93
133
 
94
134
  def read_object(self, api: str, **kwargs) -> dict:
@@ -127,10 +167,7 @@ class ClientDHCore(Client):
127
167
  dict
128
168
  Response object.
129
169
  """
130
- if "headers" not in kwargs:
131
- kwargs["headers"] = {}
132
- kwargs["headers"]["Content-Type"] = "application/json"
133
- kwargs["data"] = json.dumps(obj, default=ClientDHCore._json_serialize)
170
+ kwargs["json"] = obj
134
171
  return self._prepare_call("PUT", api, **kwargs)
135
172
 
136
173
  def delete_object(self, api: str, **kwargs) -> dict:
@@ -173,7 +210,7 @@ class ClientDHCore(Client):
173
210
  if kwargs is None:
174
211
  kwargs = {}
175
212
 
176
- if "params" not in kwargs:
213
+ if kwargs.get("params") is None:
177
214
  kwargs["params"] = {}
178
215
 
179
216
  start_page = 0
@@ -211,31 +248,12 @@ class ClientDHCore(Client):
211
248
  try:
212
249
  return self.list_objects(api, **kwargs)[0]
213
250
  except IndexError:
214
- raise BackendError("No object found.")
251
+ raise IndexError("No objects found")
215
252
 
216
253
  ##############################
217
254
  # Call methods
218
255
  ##############################
219
256
 
220
- @staticmethod
221
- def _json_serialize(obj: dict) -> dict:
222
- """
223
- JSON datetime to ISO format serializer.
224
-
225
- Parameters
226
- ----------
227
- obj : dict
228
- The object to serialize.
229
-
230
- Returns
231
- -------
232
- dict
233
- The serialized object.
234
- """
235
- if isinstance(obj, (datetime.datetime, datetime.date)):
236
- return obj.isoformat()
237
- raise TypeError("Type %s not serializable" % type(obj))
238
-
239
257
  def _prepare_call(self, call_type: str, api: str, **kwargs) -> dict:
240
258
  """
241
259
  Prepare a call to the DHCore API.
@@ -257,12 +275,12 @@ class ClientDHCore(Client):
257
275
  if kwargs is None:
258
276
  kwargs = {}
259
277
  url = self._endpoint_core + api
260
- kwargs = self._set_auth(kwargs)
278
+ kwargs = self._set_auth_header(kwargs)
261
279
  return self._make_call(call_type, url, **kwargs)
262
280
 
263
- def _set_auth(self, kwargs: dict) -> dict:
281
+ def _set_auth_header(self, kwargs: dict) -> dict:
264
282
  """
265
- Set the authentication type.
283
+ Set the authentication header.
266
284
 
267
285
  Parameters
268
286
  ----------
@@ -272,14 +290,13 @@ class ClientDHCore(Client):
272
290
  Returns
273
291
  -------
274
292
  dict
275
- Keyword arguments with the authentication parameters.
293
+ Keyword arguments with the authentication header.
276
294
  """
277
295
  if self._auth_type == "basic":
278
296
  kwargs["auth"] = self._user, self._password
279
297
  elif self._auth_type == "oauth2":
280
- if "headers" not in kwargs:
281
- kwargs["headers"] = {}
282
- kwargs["headers"]["Authorization"] = f"Bearer {self._access_token}"
298
+ kwargs["headers"] = {"Authorization": f"Bearer {self._access_token}"}
299
+
283
300
  return kwargs
284
301
 
285
302
  def _make_call(self, call_type: str, url: str, refresh_token: bool = True, **kwargs) -> dict:
@@ -309,7 +326,7 @@ class ClientDHCore(Client):
309
326
  # Handle token refresh
310
327
  if response.status_code in [401] and refresh_token:
311
328
  self._get_new_access_token()
312
- kwargs = self._set_auth(kwargs)
329
+ kwargs = self._set_auth_header(kwargs)
313
330
  return self._make_call(call_type, url, refresh_token=False, **kwargs)
314
331
 
315
332
  self._raise_for_error(response)
@@ -607,16 +624,11 @@ class ClientDHCore(Client):
607
624
  dict
608
625
  Response object.
609
626
  """
610
- # Get refersh token from .core file to avoid concurrency
611
- # in a shared workspace
612
- self._load_env()
613
- refresh_token = os.getenv("DHCORE_REFRESH_TOKEN")
614
-
615
627
  # Send request to get new access token
616
628
  payload = {
617
629
  "grant_type": "refresh_token",
618
630
  "client_id": self._client_id,
619
- "refresh_token": refresh_token,
631
+ "refresh_token": self._refresh_token,
620
632
  }
621
633
  headers = {"Content-Type": "application/x-www-form-urlencoded"}
622
634
  r = request("POST", url, data=payload, headers=headers, timeout=60)
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from copy import deepcopy
4
4
  from datetime import datetime, timezone
5
5
 
6
- from digitalhub.client._base.client import Client
6
+ from digitalhub.client.objects.base import Client
7
7
  from digitalhub.utils.exceptions import BackendError
8
8
 
9
9
 
@@ -470,7 +470,7 @@ class ClientLocal(Client):
470
470
  copied = deepcopy(entity)
471
471
 
472
472
  # Remove spec if not embedded
473
- if not copied.get("metadata", {}).get("embedded", False):
473
+ if not copied.get("metadata", {}).get("embedded", True):
474
474
  copied.pop("spec", None)
475
475
 
476
476
  # Add to project spec
@@ -5,7 +5,7 @@ import typing
5
5
  from digitalhub.context.context import Context
6
6
 
7
7
  if typing.TYPE_CHECKING:
8
- from digitalhub.entities.project._base.entity import Project
8
+ from digitalhub.entities.project.entity._base import Project
9
9
 
10
10
 
11
11
  class ContextBuilder:
@@ -91,4 +91,88 @@ class ContextBuilder:
91
91
  self._instances[context.name] = context
92
92
 
93
93
 
94
+ def set_context(project: Project) -> None:
95
+ """
96
+ Wrapper for ContextBuilder.build().
97
+
98
+ Parameters
99
+ ----------
100
+ project : Project
101
+ The project object used to set the current context.
102
+
103
+ Returns
104
+ -------
105
+ None
106
+ """
107
+ context_builder.build(project)
108
+
109
+
110
+ def set_context_object(context: Context) -> None:
111
+ """
112
+ Wrapper for ContextBuilder.set().
113
+
114
+ Parameters
115
+ ----------
116
+ context : Context
117
+ The context to set.
118
+
119
+ Returns
120
+ -------
121
+ None
122
+ """
123
+ context_builder.set(context)
124
+
125
+
126
+ def get_context(project: str) -> Context:
127
+ """
128
+ Wrapper for ContextBuilder.get().
129
+
130
+ Parameters
131
+ ----------
132
+ project : str
133
+ Project name.
134
+
135
+ Returns
136
+ -------
137
+ Context
138
+ The context for the given project name.
139
+ """
140
+ return context_builder.get(project)
141
+
142
+
143
+ def delete_context(project: str) -> None:
144
+ """
145
+ Wrapper for ContextBuilder.remove().
146
+
147
+ Parameters
148
+ ----------
149
+ project : str
150
+ Project name.
151
+
152
+ Returns
153
+ -------
154
+ None
155
+ """
156
+ context_builder.remove(project)
157
+
158
+
159
+ def check_context(project: str) -> None:
160
+ """
161
+ Check if the given project is in the context.
162
+
163
+ Parameters
164
+ ----------
165
+ project : str
166
+ Project name.
167
+
168
+ Returns
169
+ -------
170
+ bool
171
+ True if the project is in the context, False otherwise.
172
+ """
173
+ if project not in context_builder._instances:
174
+ msg = f"Context missing. Set context by creating or importing a project named '{project}'."
175
+ raise RuntimeError(msg)
176
+
177
+
94
178
  context_builder = ContextBuilder()
@@ -4,7 +4,7 @@ import typing
4
4
  from pathlib import Path
5
5
 
6
6
  if typing.TYPE_CHECKING:
7
- from digitalhub.entities.project._base.entity import Project
7
+ from digitalhub.entities.project.entity._base import Project
8
8
 
9
9
 
10
10
  class Context:
@@ -2,24 +2,19 @@ from __future__ import annotations
2
2
 
3
3
  import typing
4
4
 
5
- from digitalhub.datastores.local.datastore import LocalDatastore
6
- from digitalhub.datastores.remote.datastore import RemoteDatastore
7
- from digitalhub.datastores.s3.datastore import S3Datastore
8
- from digitalhub.datastores.sql.datastore import SqlDatastore
9
- from digitalhub.stores.api import get_default_store, get_store
5
+ from digitalhub.datastores.objects.local import LocalDatastore
6
+ from digitalhub.datastores.objects.remote import RemoteDatastore
7
+ from digitalhub.datastores.objects.s3 import S3Datastore
8
+ from digitalhub.datastores.objects.sql import SqlDatastore
9
+ from digitalhub.stores.builder import get_default_store, get_store
10
10
  from digitalhub.utils.uri_utils import map_uri_scheme
11
11
 
12
12
  if typing.TYPE_CHECKING:
13
- from digitalhub.datastores._base.datastore import Datastore
14
- from digitalhub.stores._base.store import Store
13
+ from digitalhub.datastores.objects.base import Datastore
14
+ from digitalhub.stores.objects.base import Store
15
15
 
16
16
 
17
- REGISTRY_DATASTORES = {
18
- "local": LocalDatastore,
19
- "remote": RemoteDatastore,
20
- "s3": S3Datastore,
21
- "sql": SqlDatastore,
22
- }
17
+ REGISTRY_DATASTORES = {"local": LocalDatastore, "remote": RemoteDatastore, "s3": S3Datastore, "sql": SqlDatastore}
23
18
 
24
19
 
25
20
  class DatastoreBuilder:
@@ -108,3 +103,32 @@ class DatastoreBuilder:
108
103
 
109
104
 
110
105
  builder = DatastoreBuilder()
106
+
107
+
108
+ def get_datastore(uri: str) -> Datastore:
109
+ """
110
+ Get a datastore instance by URI.
111
+
112
+ Parameters
113
+ ----------
114
+ uri : str
115
+ URI to parse.
116
+
117
+ Returns
118
+ -------
119
+ Datastore
120
+ The datastore instance.
121
+ """
122
+ return builder.get(uri)
123
+
124
+
125
+ def get_default_datastore() -> Datastore:
126
+ """
127
+ Get the default datastore instance.
128
+
129
+ Returns
130
+ -------
131
+ Datastore
132
+ The default datastore instance.
133
+ """
134
+ return builder.default()
@@ -4,10 +4,10 @@ import typing
4
4
  from abc import ABCMeta, abstractmethod
5
5
  from typing import Any
6
6
 
7
- from digitalhub.readers.api import get_reader_by_engine
7
+ from digitalhub.readers.builder import get_reader_by_engine
8
8
 
9
9
  if typing.TYPE_CHECKING:
10
- from digitalhub.stores._base.store import Store
10
+ from digitalhub.stores.objects.base import Store
11
11
 
12
12
 
13
13
  class Datastore(metaclass=ABCMeta):
@@ -32,7 +32,7 @@ class Datastore(metaclass=ABCMeta):
32
32
  self,
33
33
  path: str | list[str],
34
34
  extension: str,
35
- engine: str | None = None,
35
+ engine: str | None = "pandas",
36
36
  **kwargs,
37
37
  ) -> Any:
38
38
  """
@@ -1,14 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing
4
3
  from pathlib import Path
5
4
  from typing import Any
6
5
 
7
- from digitalhub.datastores._base.datastore import Datastore
8
- from digitalhub.readers.api import get_reader_by_object
9
-
10
- if typing.TYPE_CHECKING:
11
- from digitalhub.stores.local.store import LocalStore
6
+ from digitalhub.datastores.objects.base import Datastore
7
+ from digitalhub.readers.builder import get_reader_by_object
12
8
 
13
9
 
14
10
  class LocalDatastore(Datastore):
@@ -16,10 +12,6 @@ class LocalDatastore(Datastore):
16
12
  Local Datastore class.
17
13
  """
18
14
 
19
- def __init__(self, store: LocalStore, **kwargs) -> None:
20
- super().__init__(store, **kwargs)
21
- self.store: LocalStore
22
-
23
15
  def write_df(self, df: Any, dst: str, extension: str | None = None, **kwargs) -> str:
24
16
  """
25
17
  Method to write a dataframe to a file. Kwargs are passed to df.to_parquet().
@@ -1,12 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing
4
3
  from typing import Any
5
4
 
6
- from digitalhub.datastores._base.datastore import Datastore
7
-
8
- if typing.TYPE_CHECKING:
9
- from digitalhub.stores.remote.store import RemoteStore
5
+ from digitalhub.datastores.objects.base import Datastore
10
6
 
11
7
 
12
8
  class RemoteDatastore(Datastore):
@@ -14,10 +10,6 @@ class RemoteDatastore(Datastore):
14
10
  Remote Datastore class.
15
11
  """
16
12
 
17
- def __init__(self, store: RemoteStore, **kwargs) -> None:
18
- super().__init__(store, **kwargs)
19
- self.store: RemoteStore
20
-
21
13
  def write_df(self, df: Any, dst: str, extension: str | None = None, **kwargs) -> str:
22
14
  """
23
15
  Method to write a dataframe to a file. Note that this method is not implemented
@@ -1,14 +1,10 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing
4
3
  from io import BytesIO
5
4
  from typing import Any
6
5
 
7
- from digitalhub.datastores._base.datastore import Datastore
8
- from digitalhub.readers.api import get_reader_by_object
9
-
10
- if typing.TYPE_CHECKING:
11
- from digitalhub.stores.s3.store import S3Store
6
+ from digitalhub.datastores.objects.base import Datastore
7
+ from digitalhub.readers.builder import get_reader_by_object
12
8
 
13
9
 
14
10
  class S3Datastore(Datastore):
@@ -16,10 +12,6 @@ class S3Datastore(Datastore):
16
12
  S3 Datastore class.
17
13
  """
18
14
 
19
- def __init__(self, store: S3Store, **kwargs) -> None:
20
- super().__init__(store, **kwargs)
21
- self.store: S3Store
22
-
23
15
  def write_df(self, df: Any, dst: str, extension: str | None = None, **kwargs) -> str:
24
16
  """
25
17
  Write a dataframe to S3 based storage. Kwargs are passed to df.to_parquet().
@@ -1,13 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing
4
3
  from typing import Any
5
4
 
6
- from digitalhub.datastores._base.datastore import Datastore
7
- from digitalhub.readers.api import get_reader_by_object
8
-
9
- if typing.TYPE_CHECKING:
10
- from digitalhub.stores.sql.store import SqlStore
5
+ from digitalhub.datastores.objects.base import Datastore
6
+ from digitalhub.readers.builder import get_reader_by_object
11
7
 
12
8
 
13
9
  class SqlDatastore(Datastore):
@@ -15,10 +11,6 @@ class SqlDatastore(Datastore):
15
11
  Sql Datastore class.
16
12
  """
17
13
 
18
- def __init__(self, store: SqlStore, **kwargs) -> None:
19
- super().__init__(store, **kwargs)
20
- self.store: SqlStore
21
-
22
14
  def write_df(self, df: Any, dst: str, extension: str | None = None, **kwargs) -> str:
23
15
  """
24
16
  Write a dataframe to a database. Kwargs are passed to df.to_sql().
@@ -3,7 +3,7 @@ from __future__ import annotations
3
3
  from digitalhub.utils.generic_utils import dict_to_json
4
4
 
5
5
 
6
- class Base:
6
+ class ModelObj:
7
7
  """
8
8
  Base class for all entities.
9
9
  It implements to_dict abd to_json method to represent