digitalhub 0.13.0b2__py3-none-any.whl → 0.13.0b3__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.
- digitalhub/__init__.py +1 -1
- digitalhub/context/api.py +5 -5
- digitalhub/context/builder.py +3 -5
- digitalhub/context/context.py +9 -1
- digitalhub/entities/_base/material/entity.py +3 -3
- digitalhub/entities/dataitem/crud.py +10 -2
- digitalhub/entities/dataitem/table/entity.py +3 -3
- digitalhub/entities/dataitem/utils.py +1 -2
- digitalhub/entities/task/_base/models.py +12 -3
- digitalhub/factory/factory.py +25 -3
- digitalhub/factory/utils.py +11 -3
- digitalhub/runtimes/_base.py +1 -1
- digitalhub/runtimes/builder.py +18 -1
- digitalhub/stores/client/__init__.py +12 -0
- digitalhub/stores/client/_base/api_builder.py +14 -0
- digitalhub/stores/client/_base/client.py +93 -0
- digitalhub/stores/client/_base/key_builder.py +28 -0
- digitalhub/stores/client/_base/params_builder.py +14 -0
- digitalhub/stores/client/api.py +10 -5
- digitalhub/stores/client/builder.py +3 -1
- digitalhub/stores/client/dhcore/api_builder.py +17 -0
- digitalhub/stores/client/dhcore/client.py +276 -58
- digitalhub/stores/client/dhcore/configurator.py +336 -141
- digitalhub/stores/client/dhcore/error_parser.py +35 -1
- digitalhub/stores/client/dhcore/params_builder.py +113 -17
- digitalhub/stores/client/dhcore/utils.py +32 -14
- digitalhub/stores/client/local/api_builder.py +17 -0
- digitalhub/stores/client/local/client.py +6 -8
- digitalhub/stores/credentials/api.py +8 -8
- digitalhub/stores/credentials/configurator.py +176 -3
- digitalhub/stores/credentials/enums.py +16 -3
- digitalhub/stores/credentials/handler.py +73 -45
- digitalhub/stores/credentials/ini_module.py +59 -27
- digitalhub/stores/credentials/store.py +33 -1
- digitalhub/stores/data/_base/store.py +8 -3
- digitalhub/stores/data/api.py +20 -16
- digitalhub/stores/data/builder.py +3 -9
- digitalhub/stores/data/s3/configurator.py +64 -23
- digitalhub/stores/data/s3/store.py +30 -27
- digitalhub/stores/data/s3/utils.py +9 -9
- digitalhub/stores/data/sql/configurator.py +23 -22
- digitalhub/stores/data/sql/store.py +14 -16
- digitalhub/utils/exceptions.py +6 -0
- digitalhub/utils/file_utils.py +53 -30
- digitalhub/utils/generic_utils.py +41 -33
- digitalhub/utils/git_utils.py +24 -14
- digitalhub/utils/io_utils.py +19 -18
- digitalhub/utils/uri_utils.py +31 -31
- {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b3.dist-info}/METADATA +1 -1
- {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b3.dist-info}/RECORD +53 -53
- {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b3.dist-info}/WHEEL +0 -0
- {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b3.dist-info}/licenses/AUTHORS +0 -0
- {digitalhub-0.13.0b2.dist-info → digitalhub-0.13.0b3.dist-info}/licenses/LICENSE +0 -0
|
@@ -24,29 +24,29 @@ from digitalhub.utils.io_utils import read_text
|
|
|
24
24
|
|
|
25
25
|
def get_timestamp() -> str:
|
|
26
26
|
"""
|
|
27
|
-
Get the current timestamp
|
|
27
|
+
Get the current timestamp in ISO format with timezone.
|
|
28
28
|
|
|
29
29
|
Returns
|
|
30
30
|
-------
|
|
31
31
|
str
|
|
32
|
-
The current timestamp.
|
|
32
|
+
The current timestamp in ISO format with timezone.
|
|
33
33
|
"""
|
|
34
34
|
return datetime.now().astimezone().isoformat()
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
def decode_base64_string(string: str) -> str:
|
|
38
38
|
"""
|
|
39
|
-
Decode a string from base64.
|
|
39
|
+
Decode a string from base64 encoding.
|
|
40
40
|
|
|
41
41
|
Parameters
|
|
42
42
|
----------
|
|
43
43
|
string : str
|
|
44
|
-
The string to decode.
|
|
44
|
+
The base64-encoded string to decode.
|
|
45
45
|
|
|
46
46
|
Returns
|
|
47
47
|
-------
|
|
48
48
|
str
|
|
49
|
-
The
|
|
49
|
+
The decoded string.
|
|
50
50
|
"""
|
|
51
51
|
return base64.b64decode(string).decode()
|
|
52
52
|
|
|
@@ -63,14 +63,14 @@ def encode_string(string: str) -> str:
|
|
|
63
63
|
Returns
|
|
64
64
|
-------
|
|
65
65
|
str
|
|
66
|
-
The
|
|
66
|
+
The base64-encoded string.
|
|
67
67
|
"""
|
|
68
68
|
return base64.b64encode(string.encode()).decode()
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
def encode_source(path: str) -> str:
|
|
72
72
|
"""
|
|
73
|
-
Read a file and encode in base64
|
|
73
|
+
Read a file and encode its content in base64.
|
|
74
74
|
|
|
75
75
|
Parameters
|
|
76
76
|
----------
|
|
@@ -87,14 +87,14 @@ def encode_source(path: str) -> str:
|
|
|
87
87
|
|
|
88
88
|
def requests_chunk_download(source: str, filename: Path) -> None:
|
|
89
89
|
"""
|
|
90
|
-
Download a file in chunks.
|
|
90
|
+
Download a file from a URL in chunks and save to disk.
|
|
91
91
|
|
|
92
92
|
Parameters
|
|
93
93
|
----------
|
|
94
94
|
source : str
|
|
95
|
-
URL to download the file.
|
|
95
|
+
URL to download the file from.
|
|
96
96
|
filename : Path
|
|
97
|
-
Path where to save the file.
|
|
97
|
+
Path where to save the downloaded file.
|
|
98
98
|
|
|
99
99
|
Returns
|
|
100
100
|
-------
|
|
@@ -109,14 +109,14 @@ def requests_chunk_download(source: str, filename: Path) -> None:
|
|
|
109
109
|
|
|
110
110
|
def extract_archive(path: Path, filename: Path) -> None:
|
|
111
111
|
"""
|
|
112
|
-
Extract a zip archive.
|
|
112
|
+
Extract a zip archive to a specified directory.
|
|
113
113
|
|
|
114
114
|
Parameters
|
|
115
115
|
----------
|
|
116
116
|
path : Path
|
|
117
|
-
|
|
117
|
+
Directory where to extract the archive.
|
|
118
118
|
filename : Path
|
|
119
|
-
Path to the archive.
|
|
119
|
+
Path to the zip archive file.
|
|
120
120
|
|
|
121
121
|
Returns
|
|
122
122
|
-------
|
|
@@ -128,12 +128,12 @@ def extract_archive(path: Path, filename: Path) -> None:
|
|
|
128
128
|
|
|
129
129
|
class CustomJsonEncoder(json.JSONEncoder):
|
|
130
130
|
"""
|
|
131
|
-
Custom JSON encoder to handle
|
|
131
|
+
Custom JSON encoder to handle serialization of special types.
|
|
132
132
|
"""
|
|
133
133
|
|
|
134
134
|
def default(self, obj: Any) -> Any:
|
|
135
135
|
"""
|
|
136
|
-
Convert an object to
|
|
136
|
+
Convert an object to a JSON-serializable format.
|
|
137
137
|
|
|
138
138
|
Parameters
|
|
139
139
|
----------
|
|
@@ -143,7 +143,7 @@ class CustomJsonEncoder(json.JSONEncoder):
|
|
|
143
143
|
Returns
|
|
144
144
|
-------
|
|
145
145
|
Any
|
|
146
|
-
The object converted to
|
|
146
|
+
The object converted to a JSON-serializable format.
|
|
147
147
|
"""
|
|
148
148
|
if isinstance(obj, (int, str, float, list, dict)):
|
|
149
149
|
return obj
|
|
@@ -160,24 +160,24 @@ class CustomJsonEncoder(json.JSONEncoder):
|
|
|
160
160
|
|
|
161
161
|
def dump_json(struct: Any) -> str:
|
|
162
162
|
"""
|
|
163
|
-
Convert a
|
|
163
|
+
Convert a Python object to a JSON string using CustomJsonEncoder.
|
|
164
164
|
|
|
165
165
|
Parameters
|
|
166
166
|
----------
|
|
167
|
-
struct :
|
|
168
|
-
The
|
|
167
|
+
struct : Any
|
|
168
|
+
The object to convert to JSON.
|
|
169
169
|
|
|
170
170
|
Returns
|
|
171
171
|
-------
|
|
172
172
|
str
|
|
173
|
-
The
|
|
173
|
+
The JSON string representation of the object.
|
|
174
174
|
"""
|
|
175
175
|
return json.dumps(struct, cls=CustomJsonEncoder)
|
|
176
176
|
|
|
177
177
|
|
|
178
178
|
def slugify_string(filename: str) -> str:
|
|
179
179
|
"""
|
|
180
|
-
Sanitize a filename.
|
|
180
|
+
Sanitize a filename using slugify.
|
|
181
181
|
|
|
182
182
|
Parameters
|
|
183
183
|
----------
|
|
@@ -187,26 +187,31 @@ def slugify_string(filename: str) -> str:
|
|
|
187
187
|
Returns
|
|
188
188
|
-------
|
|
189
189
|
str
|
|
190
|
-
The sanitized filename.
|
|
190
|
+
The sanitized filename (max length 255).
|
|
191
191
|
"""
|
|
192
192
|
return slugify(filename, max_length=255)
|
|
193
193
|
|
|
194
194
|
|
|
195
195
|
def import_function(path: Path, handler: str) -> Callable:
|
|
196
196
|
"""
|
|
197
|
-
Import a function from a module.
|
|
197
|
+
Import a function from a Python module file.
|
|
198
198
|
|
|
199
199
|
Parameters
|
|
200
200
|
----------
|
|
201
201
|
path : Path
|
|
202
|
-
Path
|
|
202
|
+
Path to the Python module file.
|
|
203
203
|
handler : str
|
|
204
|
-
|
|
204
|
+
Name of the function to import.
|
|
205
205
|
|
|
206
206
|
Returns
|
|
207
207
|
-------
|
|
208
208
|
Callable
|
|
209
|
-
|
|
209
|
+
The imported function.
|
|
210
|
+
|
|
211
|
+
Raises
|
|
212
|
+
------
|
|
213
|
+
RuntimeError
|
|
214
|
+
If the module or function cannot be loaded or is not callable.
|
|
210
215
|
"""
|
|
211
216
|
spec = imputil.spec_from_file_location(path.stem, path)
|
|
212
217
|
if spec is None:
|
|
@@ -226,7 +231,7 @@ def import_function(path: Path, handler: str) -> Callable:
|
|
|
226
231
|
|
|
227
232
|
def list_enum(enum: EnumMeta) -> list[Any]:
|
|
228
233
|
"""
|
|
229
|
-
Get all values of an enum.
|
|
234
|
+
Get all values of an enum class.
|
|
230
235
|
|
|
231
236
|
Parameters
|
|
232
237
|
----------
|
|
@@ -235,7 +240,7 @@ def list_enum(enum: EnumMeta) -> list[Any]:
|
|
|
235
240
|
|
|
236
241
|
Returns
|
|
237
242
|
-------
|
|
238
|
-
list
|
|
243
|
+
list
|
|
239
244
|
List of enum values.
|
|
240
245
|
"""
|
|
241
246
|
vals: MappingProxyType[str, Enum] = enum.__members__
|
|
@@ -244,7 +249,8 @@ def list_enum(enum: EnumMeta) -> list[Any]:
|
|
|
244
249
|
|
|
245
250
|
def carriage_return_warn(string: str) -> None:
|
|
246
251
|
"""
|
|
247
|
-
Print a warning message if string contains
|
|
252
|
+
Print a warning message if the string contains
|
|
253
|
+
a carriage return (\r\n).
|
|
248
254
|
|
|
249
255
|
Parameters
|
|
250
256
|
----------
|
|
@@ -256,22 +262,24 @@ def carriage_return_warn(string: str) -> None:
|
|
|
256
262
|
None
|
|
257
263
|
"""
|
|
258
264
|
if "\r\n" in string:
|
|
259
|
-
warn("String contains a carriage return.
|
|
265
|
+
warn("String contains a carriage return. "
|
|
266
|
+
"It may not be parsed correctly from remote runtimes.")
|
|
260
267
|
|
|
261
268
|
|
|
262
269
|
def read_source(path: str) -> str:
|
|
263
270
|
"""
|
|
264
|
-
Read a file
|
|
271
|
+
Read a file and encode its content in base64,
|
|
272
|
+
warning if carriage returns are present.
|
|
265
273
|
|
|
266
274
|
Parameters
|
|
267
275
|
----------
|
|
268
|
-
path :
|
|
276
|
+
path : str
|
|
269
277
|
Path to the file.
|
|
270
278
|
|
|
271
279
|
Returns
|
|
272
280
|
-------
|
|
273
281
|
str
|
|
274
|
-
|
|
282
|
+
Base64-encoded file content.
|
|
275
283
|
"""
|
|
276
284
|
text = read_text(path)
|
|
277
285
|
carriage_return_warn(text)
|
digitalhub/utils/git_utils.py
CHANGED
|
@@ -21,6 +21,15 @@ except ImportError as e:
|
|
|
21
21
|
class GitCredentialsType(Enum):
|
|
22
22
|
"""
|
|
23
23
|
Supported git credentials types.
|
|
24
|
+
|
|
25
|
+
Attributes
|
|
26
|
+
----------
|
|
27
|
+
USERNAME : str
|
|
28
|
+
Environment variable name for git username.
|
|
29
|
+
PASSWORD : str
|
|
30
|
+
Environment variable name for git password.
|
|
31
|
+
TOKEN : str
|
|
32
|
+
Environment variable name for git token.
|
|
24
33
|
"""
|
|
25
34
|
|
|
26
35
|
USERNAME = "GIT_USERNAME"
|
|
@@ -30,7 +39,7 @@ class GitCredentialsType(Enum):
|
|
|
30
39
|
|
|
31
40
|
def clone_repository(path: Path, url: str) -> None:
|
|
32
41
|
"""
|
|
33
|
-
Clone git repository.
|
|
42
|
+
Clone a git repository to a local path.
|
|
34
43
|
|
|
35
44
|
Parameters
|
|
36
45
|
----------
|
|
@@ -53,7 +62,7 @@ def clone_repository(path: Path, url: str) -> None:
|
|
|
53
62
|
|
|
54
63
|
def get_checkout_object(url: str) -> str:
|
|
55
64
|
"""
|
|
56
|
-
Get checkout object from
|
|
65
|
+
Get checkout object (branch, tag, commit) from URL fragment.
|
|
57
66
|
|
|
58
67
|
Parameters
|
|
59
68
|
----------
|
|
@@ -63,18 +72,19 @@ def get_checkout_object(url: str) -> str:
|
|
|
63
72
|
Returns
|
|
64
73
|
-------
|
|
65
74
|
str
|
|
66
|
-
Checkout object (branch, tag, commit).
|
|
75
|
+
Checkout object (branch, tag, commit) or empty string if not present.
|
|
67
76
|
"""
|
|
68
77
|
return urlparse(url).fragment
|
|
69
78
|
|
|
70
79
|
|
|
71
80
|
def clean_path(path: Path) -> None:
|
|
72
81
|
"""
|
|
73
|
-
|
|
82
|
+
Remove all files and directories at the given path.
|
|
74
83
|
|
|
75
84
|
Parameters
|
|
76
85
|
----------
|
|
77
86
|
path : Path
|
|
87
|
+
Path to clean.
|
|
78
88
|
|
|
79
89
|
Returns
|
|
80
90
|
-------
|
|
@@ -86,12 +96,12 @@ def clean_path(path: Path) -> None:
|
|
|
86
96
|
|
|
87
97
|
def get_git_username_password_from_token(token: str) -> tuple[str, str]:
|
|
88
98
|
"""
|
|
89
|
-
Parse token to get username and password
|
|
90
|
-
can be one of the following:
|
|
99
|
+
Parse a token to get username and password for git authentication.
|
|
91
100
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
101
|
+
The token can be one of the following:
|
|
102
|
+
- GitHub/GitLab personal access token (github_pat_.../glpat...)
|
|
103
|
+
- GitHub/GitLab access token
|
|
104
|
+
- Other generic token
|
|
95
105
|
|
|
96
106
|
Parameters
|
|
97
107
|
----------
|
|
@@ -101,7 +111,7 @@ def get_git_username_password_from_token(token: str) -> tuple[str, str]:
|
|
|
101
111
|
Returns
|
|
102
112
|
-------
|
|
103
113
|
tuple[str, str]
|
|
104
|
-
Username and password.
|
|
114
|
+
Username and password for git authentication.
|
|
105
115
|
"""
|
|
106
116
|
# Mutued from mlrun
|
|
107
117
|
if token.startswith("github_pat_") or token.startswith("glpat"):
|
|
@@ -111,7 +121,7 @@ def get_git_username_password_from_token(token: str) -> tuple[str, str]:
|
|
|
111
121
|
|
|
112
122
|
def add_credentials_git_remote_url(url: str) -> str:
|
|
113
123
|
"""
|
|
114
|
-
Add credentials to git remote
|
|
124
|
+
Add credentials to a git remote URL using environment variables or token.
|
|
115
125
|
|
|
116
126
|
Parameters
|
|
117
127
|
----------
|
|
@@ -121,7 +131,7 @@ def add_credentials_git_remote_url(url: str) -> str:
|
|
|
121
131
|
Returns
|
|
122
132
|
-------
|
|
123
133
|
str
|
|
124
|
-
URL with credentials.
|
|
134
|
+
URL with credentials included if available.
|
|
125
135
|
"""
|
|
126
136
|
url_obj = urlparse(url)
|
|
127
137
|
|
|
@@ -142,7 +152,7 @@ def add_credentials_git_remote_url(url: str) -> str:
|
|
|
142
152
|
|
|
143
153
|
def clone_from_url(url: str, path: Path) -> Repo:
|
|
144
154
|
"""
|
|
145
|
-
Clone repository from
|
|
155
|
+
Clone a git repository from a URL to a local path.
|
|
146
156
|
|
|
147
157
|
Parameters
|
|
148
158
|
----------
|
|
@@ -154,6 +164,6 @@ def clone_from_url(url: str, path: Path) -> Repo:
|
|
|
154
164
|
Returns
|
|
155
165
|
-------
|
|
156
166
|
Repo
|
|
157
|
-
|
|
167
|
+
The cloned git repository object.
|
|
158
168
|
"""
|
|
159
169
|
return Repo.clone_from(url=url, to_path=path)
|
digitalhub/utils/io_utils.py
CHANGED
|
@@ -15,14 +15,14 @@ import yaml
|
|
|
15
15
|
|
|
16
16
|
def write_yaml(filepath: str | Path, obj: dict | list[dict]) -> None:
|
|
17
17
|
"""
|
|
18
|
-
Write a dict or a list of
|
|
18
|
+
Write a dict or a list of dicts to a YAML file.
|
|
19
19
|
|
|
20
20
|
Parameters
|
|
21
21
|
----------
|
|
22
|
-
filepath : str
|
|
23
|
-
The
|
|
24
|
-
obj : dict
|
|
25
|
-
The dict to write.
|
|
22
|
+
filepath : str or Path
|
|
23
|
+
The YAML file path to write.
|
|
24
|
+
obj : dict or list of dict
|
|
25
|
+
The dict or list of dicts to write.
|
|
26
26
|
|
|
27
27
|
Returns
|
|
28
28
|
-------
|
|
@@ -61,7 +61,7 @@ def write_text(filepath: Path, text: str) -> None:
|
|
|
61
61
|
|
|
62
62
|
class NoDatesSafeLoader(yaml.SafeLoader):
|
|
63
63
|
"""
|
|
64
|
-
Loader implementation to exclude implicit resolvers.
|
|
64
|
+
Loader implementation to exclude implicit resolvers for YAML timestamps.
|
|
65
65
|
|
|
66
66
|
Taken from https://stackoverflow.com/a/37958106
|
|
67
67
|
"""
|
|
@@ -69,16 +69,17 @@ class NoDatesSafeLoader(yaml.SafeLoader):
|
|
|
69
69
|
@classmethod
|
|
70
70
|
def remove_implicit_resolver(cls, tag_to_remove: str) -> None:
|
|
71
71
|
"""
|
|
72
|
-
Remove implicit resolvers for a particular tag
|
|
72
|
+
Remove implicit resolvers for a particular tag.
|
|
73
|
+
|
|
73
74
|
Takes care not to modify resolvers in super classes.
|
|
74
75
|
We want to load datetimes as strings, not dates, because we
|
|
75
|
-
go on to
|
|
76
|
-
of
|
|
76
|
+
go on to serialize as JSON which doesn't have the advanced types
|
|
77
|
+
of YAML, and leads to incompatibilities down the track.
|
|
77
78
|
|
|
78
79
|
Parameters
|
|
79
80
|
----------
|
|
80
81
|
tag_to_remove : str
|
|
81
|
-
The tag to remove
|
|
82
|
+
The tag to remove.
|
|
82
83
|
|
|
83
84
|
Returns
|
|
84
85
|
-------
|
|
@@ -98,17 +99,17 @@ NoDatesSafeLoader.remove_implicit_resolver("tag:yaml.org,2002:timestamp")
|
|
|
98
99
|
|
|
99
100
|
def read_yaml(filepath: str | Path) -> dict | list[dict]:
|
|
100
101
|
"""
|
|
101
|
-
Read a
|
|
102
|
+
Read a YAML file and return its content as a dict or a list of dicts.
|
|
102
103
|
|
|
103
104
|
Parameters
|
|
104
105
|
----------
|
|
105
|
-
filepath : str
|
|
106
|
-
The
|
|
106
|
+
filepath : str or Path
|
|
107
|
+
The YAML file path to read.
|
|
107
108
|
|
|
108
109
|
Returns
|
|
109
110
|
-------
|
|
110
|
-
dict
|
|
111
|
-
The
|
|
111
|
+
dict or list of dict
|
|
112
|
+
The YAML file content.
|
|
112
113
|
"""
|
|
113
114
|
try:
|
|
114
115
|
with open(filepath, "r", encoding="utf-8") as in_file:
|
|
@@ -123,16 +124,16 @@ def read_yaml(filepath: str | Path) -> dict | list[dict]:
|
|
|
123
124
|
|
|
124
125
|
def read_text(filepath: str | Path) -> str:
|
|
125
126
|
"""
|
|
126
|
-
Read a file and return
|
|
127
|
+
Read a file and return its text content.
|
|
127
128
|
|
|
128
129
|
Parameters
|
|
129
130
|
----------
|
|
130
|
-
filepath : str
|
|
131
|
+
filepath : str or Path
|
|
131
132
|
The file path to read.
|
|
132
133
|
|
|
133
134
|
Returns
|
|
134
135
|
-------
|
|
135
136
|
str
|
|
136
|
-
The file content.
|
|
137
|
+
The file content as a string.
|
|
137
138
|
"""
|
|
138
139
|
return Path(filepath).read_text(encoding="utf-8")
|
digitalhub/utils/uri_utils.py
CHANGED
|
@@ -13,7 +13,7 @@ from digitalhub.utils.generic_utils import list_enum
|
|
|
13
13
|
|
|
14
14
|
class S3Schemes(Enum):
|
|
15
15
|
"""
|
|
16
|
-
S3 schemes.
|
|
16
|
+
S3 URI schemes.
|
|
17
17
|
"""
|
|
18
18
|
|
|
19
19
|
S3 = "s3"
|
|
@@ -24,7 +24,7 @@ class S3Schemes(Enum):
|
|
|
24
24
|
|
|
25
25
|
class LocalSchemes(Enum):
|
|
26
26
|
"""
|
|
27
|
-
Local schemes.
|
|
27
|
+
Local URI schemes.
|
|
28
28
|
"""
|
|
29
29
|
|
|
30
30
|
LOCAL = ""
|
|
@@ -32,7 +32,7 @@ class LocalSchemes(Enum):
|
|
|
32
32
|
|
|
33
33
|
class InvalidLocalSchemes(Enum):
|
|
34
34
|
"""
|
|
35
|
-
|
|
35
|
+
Invalid local URI schemes.
|
|
36
36
|
"""
|
|
37
37
|
|
|
38
38
|
FILE = "file"
|
|
@@ -41,7 +41,7 @@ class InvalidLocalSchemes(Enum):
|
|
|
41
41
|
|
|
42
42
|
class RemoteSchemes(Enum):
|
|
43
43
|
"""
|
|
44
|
-
Remote schemes.
|
|
44
|
+
Remote URI schemes.
|
|
45
45
|
"""
|
|
46
46
|
|
|
47
47
|
HTTP = "http"
|
|
@@ -52,7 +52,7 @@ class RemoteSchemes(Enum):
|
|
|
52
52
|
|
|
53
53
|
class SqlSchemes(Enum):
|
|
54
54
|
"""
|
|
55
|
-
|
|
55
|
+
SQL URI schemes.
|
|
56
56
|
"""
|
|
57
57
|
|
|
58
58
|
SQL = "sql"
|
|
@@ -61,7 +61,7 @@ class SqlSchemes(Enum):
|
|
|
61
61
|
|
|
62
62
|
class GitSchemes(Enum):
|
|
63
63
|
"""
|
|
64
|
-
Git schemes.
|
|
64
|
+
Git URI schemes.
|
|
65
65
|
"""
|
|
66
66
|
|
|
67
67
|
GIT = "git"
|
|
@@ -71,7 +71,7 @@ class GitSchemes(Enum):
|
|
|
71
71
|
|
|
72
72
|
class SchemeCategory(Enum):
|
|
73
73
|
"""
|
|
74
|
-
|
|
74
|
+
URI scheme categories.
|
|
75
75
|
"""
|
|
76
76
|
|
|
77
77
|
S3 = "s3"
|
|
@@ -83,17 +83,17 @@ class SchemeCategory(Enum):
|
|
|
83
83
|
|
|
84
84
|
def map_uri_scheme(uri: str) -> str:
|
|
85
85
|
"""
|
|
86
|
-
Map
|
|
86
|
+
Map a URI scheme to a common scheme category.
|
|
87
87
|
|
|
88
88
|
Parameters
|
|
89
89
|
----------
|
|
90
90
|
uri : str
|
|
91
|
-
URI.
|
|
91
|
+
URI string.
|
|
92
92
|
|
|
93
93
|
Returns
|
|
94
94
|
-------
|
|
95
95
|
str
|
|
96
|
-
Mapped scheme
|
|
96
|
+
Mapped scheme category (e.g., 'local', 'remote', 's3', 'sql', 'git').
|
|
97
97
|
|
|
98
98
|
Raises
|
|
99
99
|
------
|
|
@@ -122,118 +122,118 @@ def map_uri_scheme(uri: str) -> str:
|
|
|
122
122
|
|
|
123
123
|
def has_local_scheme(uri: str) -> bool:
|
|
124
124
|
"""
|
|
125
|
-
Check if
|
|
125
|
+
Check if a URI has a local scheme.
|
|
126
126
|
|
|
127
127
|
Parameters
|
|
128
128
|
----------
|
|
129
129
|
uri : str
|
|
130
|
-
|
|
130
|
+
URI string.
|
|
131
131
|
|
|
132
132
|
Returns
|
|
133
133
|
-------
|
|
134
134
|
bool
|
|
135
|
-
True if
|
|
135
|
+
True if the URI is local, False otherwise.
|
|
136
136
|
"""
|
|
137
137
|
return map_uri_scheme(uri) == SchemeCategory.LOCAL.value
|
|
138
138
|
|
|
139
139
|
|
|
140
140
|
def has_remote_scheme(uri: str) -> bool:
|
|
141
141
|
"""
|
|
142
|
-
Check if
|
|
142
|
+
Check if a URI has a remote scheme.
|
|
143
143
|
|
|
144
144
|
Parameters
|
|
145
145
|
----------
|
|
146
146
|
uri : str
|
|
147
|
-
|
|
147
|
+
URI string.
|
|
148
148
|
|
|
149
149
|
Returns
|
|
150
150
|
-------
|
|
151
151
|
bool
|
|
152
|
-
True if
|
|
152
|
+
True if the URI is remote, False otherwise.
|
|
153
153
|
"""
|
|
154
154
|
return map_uri_scheme(uri) == SchemeCategory.REMOTE.value
|
|
155
155
|
|
|
156
156
|
|
|
157
157
|
def has_s3_scheme(uri: str) -> bool:
|
|
158
158
|
"""
|
|
159
|
-
Check if
|
|
159
|
+
Check if a URI has an S3 scheme.
|
|
160
160
|
|
|
161
161
|
Parameters
|
|
162
162
|
----------
|
|
163
163
|
uri : str
|
|
164
|
-
|
|
164
|
+
URI string.
|
|
165
165
|
|
|
166
166
|
Returns
|
|
167
167
|
-------
|
|
168
168
|
bool
|
|
169
|
-
True if
|
|
169
|
+
True if the URI is S3, False otherwise.
|
|
170
170
|
"""
|
|
171
171
|
return map_uri_scheme(uri) == SchemeCategory.S3.value
|
|
172
172
|
|
|
173
173
|
|
|
174
174
|
def has_sql_scheme(uri: str) -> bool:
|
|
175
175
|
"""
|
|
176
|
-
Check if
|
|
176
|
+
Check if a URI has an SQL scheme.
|
|
177
177
|
|
|
178
178
|
Parameters
|
|
179
179
|
----------
|
|
180
180
|
uri : str
|
|
181
|
-
|
|
181
|
+
URI string.
|
|
182
182
|
|
|
183
183
|
Returns
|
|
184
184
|
-------
|
|
185
185
|
bool
|
|
186
|
-
True if
|
|
186
|
+
True if the URI is SQL, False otherwise.
|
|
187
187
|
"""
|
|
188
188
|
return map_uri_scheme(uri) == SchemeCategory.SQL.value
|
|
189
189
|
|
|
190
190
|
|
|
191
191
|
def has_git_scheme(uri: str) -> bool:
|
|
192
192
|
"""
|
|
193
|
-
Check if
|
|
193
|
+
Check if a URI has a git scheme.
|
|
194
194
|
|
|
195
195
|
Parameters
|
|
196
196
|
----------
|
|
197
197
|
uri : str
|
|
198
|
-
|
|
198
|
+
URI string.
|
|
199
199
|
|
|
200
200
|
Returns
|
|
201
201
|
-------
|
|
202
202
|
bool
|
|
203
|
-
True if
|
|
203
|
+
True if the URI is git, False otherwise.
|
|
204
204
|
"""
|
|
205
205
|
return map_uri_scheme(uri) == SchemeCategory.GIT.value
|
|
206
206
|
|
|
207
207
|
|
|
208
208
|
def has_zip_scheme(uri: str) -> bool:
|
|
209
209
|
"""
|
|
210
|
-
Check if
|
|
210
|
+
Check if a URI has a zip scheme.
|
|
211
211
|
|
|
212
212
|
Parameters
|
|
213
213
|
----------
|
|
214
214
|
uri : str
|
|
215
|
-
|
|
215
|
+
URI string.
|
|
216
216
|
|
|
217
217
|
Returns
|
|
218
218
|
-------
|
|
219
219
|
bool
|
|
220
|
-
True if
|
|
220
|
+
True if the URI is zip, False otherwise.
|
|
221
221
|
"""
|
|
222
222
|
return uri.startswith("zip+")
|
|
223
223
|
|
|
224
224
|
|
|
225
225
|
def get_filename_from_uri(uri: str) -> str:
|
|
226
226
|
"""
|
|
227
|
-
Get filename from
|
|
227
|
+
Get the filename from a URI.
|
|
228
228
|
|
|
229
229
|
Parameters
|
|
230
230
|
----------
|
|
231
231
|
uri : str
|
|
232
|
-
|
|
232
|
+
URI string.
|
|
233
233
|
|
|
234
234
|
Returns
|
|
235
235
|
-------
|
|
236
236
|
str
|
|
237
|
-
Filename.
|
|
237
|
+
Filename extracted from the URI.
|
|
238
238
|
"""
|
|
239
239
|
return unquote(urlparse(uri).path).split("/")[-1]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: digitalhub
|
|
3
|
-
Version: 0.13.
|
|
3
|
+
Version: 0.13.0b3
|
|
4
4
|
Summary: Python SDK for Digitalhub
|
|
5
5
|
Project-URL: Homepage, https://github.com/scc-digitalhub/digitalhub-sdk
|
|
6
6
|
Author-email: Fondazione Bruno Kessler <digitalhub@fbk.eu>, Matteo Martini <mmartini@fbk.eu>
|