nufi-python 1.0.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.
- nufi/__init__.py +52 -0
- nufi/auth.py +364 -0
- nufi/cli/__init__.py +0 -0
- nufi/cli/commands/__init__.py +1 -0
- nufi/cli/commands/auth.py +113 -0
- nufi/cli/commands/common.py +198 -0
- nufi/cli/commands/compiles.py +507 -0
- nufi/cli/commands/custom_evaluation_templates.py +206 -0
- nufi/cli/commands/datasets.py +697 -0
- nufi/cli/commands/evaluations.py +854 -0
- nufi/cli/commands/leaderboards.py +763 -0
- nufi/cli/commands/models.py +1347 -0
- nufi/cli/commands/monitoring.py +350 -0
- nufi/cli/commands/profile.py +123 -0
- nufi/cli/commands/projects.py +308 -0
- nufi/cli/commands/servings.py +306 -0
- nufi/cli/main.py +66 -0
- nufi/client.py +103 -0
- nufi/config.py +281 -0
- nufi/evaluator.py +559 -0
- nufi/exceptions.py +58 -0
- nufi/http_utils.py +51 -0
- nufi/models/__init__.py +185 -0
- nufi/models/compiles.py +79 -0
- nufi/models/custom_evaluation_templates.py +111 -0
- nufi/models/datasets.py +94 -0
- nufi/models/evaluations.py +253 -0
- nufi/models/leaderboards.py +178 -0
- nufi/models/monitoring.py +179 -0
- nufi/models/pagination.py +33 -0
- nufi/models/projects.py +32 -0
- nufi/models/registry.py +138 -0
- nufi/models/servings.py +27 -0
- nufi/py.typed +1 -0
- nufi/resources/__init__.py +34 -0
- nufi/resources/base.py +190 -0
- nufi/resources/compiles.py +193 -0
- nufi/resources/custom_evaluation_templates.py +126 -0
- nufi/resources/datasets.py +786 -0
- nufi/resources/evaluations.py +428 -0
- nufi/resources/leaderboards.py +413 -0
- nufi/resources/models.py +726 -0
- nufi/resources/monitoring.py +82 -0
- nufi/resources/projects.py +114 -0
- nufi/resources/servings.py +80 -0
- nufi/transport.py +248 -0
- nufi_python-1.0.0.dist-info/METADATA +228 -0
- nufi_python-1.0.0.dist-info/RECORD +52 -0
- nufi_python-1.0.0.dist-info/WHEEL +5 -0
- nufi_python-1.0.0.dist-info/entry_points.txt +2 -0
- nufi_python-1.0.0.dist-info/licenses/LICENSE +21 -0
- nufi_python-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,697 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from uuid import UUID
|
|
6
|
+
|
|
7
|
+
import typer
|
|
8
|
+
from rich.markup import escape
|
|
9
|
+
|
|
10
|
+
from nufi.cli.commands import common
|
|
11
|
+
from nufi.exceptions import ValidationError
|
|
12
|
+
|
|
13
|
+
app = typer.Typer(
|
|
14
|
+
help="Manage NuFi datasets.",
|
|
15
|
+
invoke_without_command=True,
|
|
16
|
+
context_settings=common.CONTEXT_SETTINGS,
|
|
17
|
+
)
|
|
18
|
+
version_app = typer.Typer(
|
|
19
|
+
help="Manage NuFi dataset versions.",
|
|
20
|
+
invoke_without_command=True,
|
|
21
|
+
context_settings=common.CONTEXT_SETTINGS,
|
|
22
|
+
)
|
|
23
|
+
app.add_typer(version_app, name="version")
|
|
24
|
+
|
|
25
|
+
IMPORT_POLL_INTERVAL_SECONDS = 5
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@app.callback()
|
|
29
|
+
def datasets(ctx: typer.Context):
|
|
30
|
+
common.show_help_if_no_subcommand(ctx)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@version_app.callback()
|
|
34
|
+
def dataset_versions(ctx: typer.Context):
|
|
35
|
+
common.show_help_if_no_subcommand(ctx)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _is_uuid(value: str) -> bool:
|
|
39
|
+
try:
|
|
40
|
+
UUID(value)
|
|
41
|
+
except ValueError:
|
|
42
|
+
return False
|
|
43
|
+
return True
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _resolve_dataset_id(client, dataset: str, *, project: str | int) -> str:
|
|
47
|
+
if _is_uuid(dataset):
|
|
48
|
+
return dataset
|
|
49
|
+
return common.resolve_named_resource(
|
|
50
|
+
client.datasets.iter_all(project=project),
|
|
51
|
+
dataset,
|
|
52
|
+
resource="dataset",
|
|
53
|
+
).id
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _resolve_version_id(
|
|
57
|
+
client, dataset_id: str, version: str, *, project: str | int
|
|
58
|
+
) -> str:
|
|
59
|
+
if _is_uuid(version):
|
|
60
|
+
return version
|
|
61
|
+
return common.resolve_named_resource(
|
|
62
|
+
client.datasets.versions.iter_all(dataset_id, project=project),
|
|
63
|
+
version,
|
|
64
|
+
resource="dataset version",
|
|
65
|
+
).id
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _project_ref(
|
|
69
|
+
project: str | None,
|
|
70
|
+
project_id: int | None,
|
|
71
|
+
profile_name: str | None,
|
|
72
|
+
) -> str | int:
|
|
73
|
+
return common.resolve_cli_project(project, project_id, profile_name=profile_name)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _version_rows(versions):
|
|
77
|
+
return [
|
|
78
|
+
[
|
|
79
|
+
version.id,
|
|
80
|
+
version.name,
|
|
81
|
+
version.description or "",
|
|
82
|
+
version.source_kind,
|
|
83
|
+
version.storage_format,
|
|
84
|
+
str(version.ready_at),
|
|
85
|
+
]
|
|
86
|
+
for version in versions
|
|
87
|
+
]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _print_dataset_detail(dataset) -> None:
|
|
91
|
+
common.print_table(
|
|
92
|
+
["Field", "Value"],
|
|
93
|
+
[
|
|
94
|
+
["ID", dataset.id],
|
|
95
|
+
["Project ID", dataset.project_id],
|
|
96
|
+
["Name", dataset.name],
|
|
97
|
+
["Description", dataset.description or ""],
|
|
98
|
+
["Archived At", dataset.archived_at or ""],
|
|
99
|
+
["Created", dataset.created_at],
|
|
100
|
+
["Updated", dataset.updated_at],
|
|
101
|
+
],
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _print_version_detail(version) -> None:
|
|
106
|
+
common.print_table(
|
|
107
|
+
["Field", "Value"],
|
|
108
|
+
[
|
|
109
|
+
["ID", version.id],
|
|
110
|
+
["Project ID", version.project_id],
|
|
111
|
+
["Dataset ID", version.dataset_id],
|
|
112
|
+
["Name", version.name],
|
|
113
|
+
["Description", version.description or ""],
|
|
114
|
+
["Source", version.source_kind],
|
|
115
|
+
["Source Config", json.dumps(version.source_config, ensure_ascii=False)],
|
|
116
|
+
["Storage Format", version.storage_format],
|
|
117
|
+
["Data URI", version.data_uri],
|
|
118
|
+
["Schema Hash", version.source_schema_hash],
|
|
119
|
+
["Schema Version", version.source_schema_version],
|
|
120
|
+
["Ready At", version.ready_at],
|
|
121
|
+
["Archived At", version.archived_at or ""],
|
|
122
|
+
["Created By", version.created_by],
|
|
123
|
+
["Created", version.created_at],
|
|
124
|
+
["Updated", version.updated_at],
|
|
125
|
+
],
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@app.command("list")
|
|
130
|
+
def list_datasets(
|
|
131
|
+
project: str | None = typer.Option(
|
|
132
|
+
None,
|
|
133
|
+
"--project",
|
|
134
|
+
help="Project name.",
|
|
135
|
+
show_default=False,
|
|
136
|
+
),
|
|
137
|
+
project_id: int | None = typer.Option(
|
|
138
|
+
None,
|
|
139
|
+
"--project-id",
|
|
140
|
+
min=1,
|
|
141
|
+
help="Project ID.",
|
|
142
|
+
show_default=False,
|
|
143
|
+
),
|
|
144
|
+
page: int | None = typer.Option(
|
|
145
|
+
None,
|
|
146
|
+
"--page",
|
|
147
|
+
min=1,
|
|
148
|
+
help="Page number.",
|
|
149
|
+
show_default=False,
|
|
150
|
+
),
|
|
151
|
+
limit: int | None = typer.Option(
|
|
152
|
+
None,
|
|
153
|
+
"--limit",
|
|
154
|
+
min=1,
|
|
155
|
+
max=100,
|
|
156
|
+
help="Datasets per page.",
|
|
157
|
+
show_default=False,
|
|
158
|
+
),
|
|
159
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
160
|
+
output: common.OutputChoice = typer.Option(
|
|
161
|
+
common.OutputChoice.table,
|
|
162
|
+
"--output",
|
|
163
|
+
help="Output format.",
|
|
164
|
+
),
|
|
165
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
166
|
+
):
|
|
167
|
+
client = None
|
|
168
|
+
try:
|
|
169
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
170
|
+
client = common.make_client(profile_name)
|
|
171
|
+
result_page = client.datasets.list_page(
|
|
172
|
+
project=resolved_project,
|
|
173
|
+
page=page,
|
|
174
|
+
limit=limit,
|
|
175
|
+
)
|
|
176
|
+
except Exception as exc:
|
|
177
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
178
|
+
finally:
|
|
179
|
+
if client is not None:
|
|
180
|
+
client.close()
|
|
181
|
+
|
|
182
|
+
if output == common.OutputChoice.json:
|
|
183
|
+
common.print_json(result_page)
|
|
184
|
+
return
|
|
185
|
+
|
|
186
|
+
common.print_page_table(
|
|
187
|
+
result_page,
|
|
188
|
+
["ID", "Name", "Description", "Created"],
|
|
189
|
+
[
|
|
190
|
+
[
|
|
191
|
+
dataset.id,
|
|
192
|
+
dataset.name,
|
|
193
|
+
dataset.description or "",
|
|
194
|
+
str(dataset.created_at),
|
|
195
|
+
]
|
|
196
|
+
for dataset in result_page.items
|
|
197
|
+
],
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
@app.command("get")
|
|
202
|
+
def get_dataset(
|
|
203
|
+
dataset: str = typer.Argument(..., help="Dataset name or UUID."),
|
|
204
|
+
project: str | None = typer.Option(
|
|
205
|
+
None,
|
|
206
|
+
"--project",
|
|
207
|
+
help="Project name.",
|
|
208
|
+
show_default=False,
|
|
209
|
+
),
|
|
210
|
+
project_id: int | None = typer.Option(
|
|
211
|
+
None,
|
|
212
|
+
"--project-id",
|
|
213
|
+
min=1,
|
|
214
|
+
help="Project ID.",
|
|
215
|
+
show_default=False,
|
|
216
|
+
),
|
|
217
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
218
|
+
output: common.OutputChoice = typer.Option(
|
|
219
|
+
common.OutputChoice.table,
|
|
220
|
+
"--output",
|
|
221
|
+
help="Output format.",
|
|
222
|
+
),
|
|
223
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
224
|
+
):
|
|
225
|
+
client = None
|
|
226
|
+
try:
|
|
227
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
228
|
+
client = common.make_client(profile_name)
|
|
229
|
+
dataset_id = _resolve_dataset_id(client, dataset, project=resolved_project)
|
|
230
|
+
result = client.datasets.get(dataset_id, project=resolved_project)
|
|
231
|
+
except Exception as exc:
|
|
232
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
233
|
+
finally:
|
|
234
|
+
if client is not None:
|
|
235
|
+
client.close()
|
|
236
|
+
|
|
237
|
+
if output == common.OutputChoice.json:
|
|
238
|
+
common.print_json(result)
|
|
239
|
+
return
|
|
240
|
+
|
|
241
|
+
_print_dataset_detail(result)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@app.command("create")
|
|
245
|
+
def create_dataset(
|
|
246
|
+
name: str = typer.Argument(..., help="Dataset name."),
|
|
247
|
+
project: str | None = typer.Option(
|
|
248
|
+
None,
|
|
249
|
+
"--project",
|
|
250
|
+
help="Project name.",
|
|
251
|
+
show_default=False,
|
|
252
|
+
),
|
|
253
|
+
project_id: int | None = typer.Option(
|
|
254
|
+
None,
|
|
255
|
+
"--project-id",
|
|
256
|
+
min=1,
|
|
257
|
+
help="Project ID.",
|
|
258
|
+
show_default=False,
|
|
259
|
+
),
|
|
260
|
+
description: str | None = typer.Option(
|
|
261
|
+
None, "--description", help="Dataset description."
|
|
262
|
+
),
|
|
263
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
264
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
265
|
+
):
|
|
266
|
+
client = None
|
|
267
|
+
try:
|
|
268
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
269
|
+
client = common.make_client(profile_name)
|
|
270
|
+
dataset = client.datasets.create(
|
|
271
|
+
name,
|
|
272
|
+
project=resolved_project,
|
|
273
|
+
description=description,
|
|
274
|
+
)
|
|
275
|
+
except Exception as exc:
|
|
276
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
277
|
+
finally:
|
|
278
|
+
if client is not None:
|
|
279
|
+
client.close()
|
|
280
|
+
|
|
281
|
+
common.console.print(f"[bold green]Dataset created:[/] {escape(dataset.name)}")
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
@app.command("archive")
|
|
285
|
+
def archive_dataset(
|
|
286
|
+
dataset: str = typer.Argument(..., help="Dataset name or UUID."),
|
|
287
|
+
project: str | None = typer.Option(
|
|
288
|
+
None,
|
|
289
|
+
"--project",
|
|
290
|
+
help="Project name.",
|
|
291
|
+
show_default=False,
|
|
292
|
+
),
|
|
293
|
+
project_id: int | None = typer.Option(
|
|
294
|
+
None,
|
|
295
|
+
"--project-id",
|
|
296
|
+
min=1,
|
|
297
|
+
help="Project ID.",
|
|
298
|
+
show_default=False,
|
|
299
|
+
),
|
|
300
|
+
reason: str | None = typer.Option(None, "--reason", help="Archive reason."),
|
|
301
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
302
|
+
yes: bool = typer.Option(False, "--yes", help="Skip archive confirmation."),
|
|
303
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
304
|
+
):
|
|
305
|
+
try:
|
|
306
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
307
|
+
except Exception as exc:
|
|
308
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
309
|
+
|
|
310
|
+
common.confirm_delete(
|
|
311
|
+
resource="dataset",
|
|
312
|
+
target=f"{resolved_project}/{dataset}",
|
|
313
|
+
profile_name=profile_name,
|
|
314
|
+
yes=yes,
|
|
315
|
+
)
|
|
316
|
+
client = None
|
|
317
|
+
try:
|
|
318
|
+
client = common.make_client(profile_name)
|
|
319
|
+
dataset_id = _resolve_dataset_id(client, dataset, project=resolved_project)
|
|
320
|
+
client.datasets.archive(dataset_id, project=resolved_project, reason=reason)
|
|
321
|
+
except Exception as exc:
|
|
322
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
323
|
+
finally:
|
|
324
|
+
if client is not None:
|
|
325
|
+
client.close()
|
|
326
|
+
|
|
327
|
+
common.console.print(f"[bold green]Dataset archived:[/] {escape(dataset)}")
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
@app.command("restore")
|
|
331
|
+
def restore_dataset(
|
|
332
|
+
dataset: str = typer.Argument(..., help="Dataset name or UUID."),
|
|
333
|
+
project: str | None = typer.Option(
|
|
334
|
+
None,
|
|
335
|
+
"--project",
|
|
336
|
+
help="Project name.",
|
|
337
|
+
show_default=False,
|
|
338
|
+
),
|
|
339
|
+
project_id: int | None = typer.Option(
|
|
340
|
+
None,
|
|
341
|
+
"--project-id",
|
|
342
|
+
min=1,
|
|
343
|
+
help="Project ID.",
|
|
344
|
+
show_default=False,
|
|
345
|
+
),
|
|
346
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
347
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
348
|
+
):
|
|
349
|
+
client = None
|
|
350
|
+
try:
|
|
351
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
352
|
+
client = common.make_client(profile_name)
|
|
353
|
+
dataset_id = _resolve_dataset_id(client, dataset, project=resolved_project)
|
|
354
|
+
client.datasets.restore(dataset_id, project=resolved_project)
|
|
355
|
+
except Exception as exc:
|
|
356
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
357
|
+
finally:
|
|
358
|
+
if client is not None:
|
|
359
|
+
client.close()
|
|
360
|
+
|
|
361
|
+
common.console.print(f"[bold green]Dataset restored:[/] {escape(dataset)}")
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
@version_app.command("list")
|
|
365
|
+
def list_versions(
|
|
366
|
+
dataset: str = typer.Argument(..., help="Dataset name or UUID."),
|
|
367
|
+
project: str | None = typer.Option(
|
|
368
|
+
None,
|
|
369
|
+
"--project",
|
|
370
|
+
help="Project name.",
|
|
371
|
+
show_default=False,
|
|
372
|
+
),
|
|
373
|
+
project_id: int | None = typer.Option(
|
|
374
|
+
None,
|
|
375
|
+
"--project-id",
|
|
376
|
+
min=1,
|
|
377
|
+
help="Project ID.",
|
|
378
|
+
show_default=False,
|
|
379
|
+
),
|
|
380
|
+
page: int | None = typer.Option(
|
|
381
|
+
None,
|
|
382
|
+
"--page",
|
|
383
|
+
min=1,
|
|
384
|
+
help="Page number.",
|
|
385
|
+
show_default=False,
|
|
386
|
+
),
|
|
387
|
+
limit: int | None = typer.Option(
|
|
388
|
+
None,
|
|
389
|
+
"--limit",
|
|
390
|
+
min=1,
|
|
391
|
+
max=100,
|
|
392
|
+
help="Versions per page.",
|
|
393
|
+
show_default=False,
|
|
394
|
+
),
|
|
395
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
396
|
+
output: common.OutputChoice = typer.Option(
|
|
397
|
+
common.OutputChoice.table,
|
|
398
|
+
"--output",
|
|
399
|
+
help="Output format.",
|
|
400
|
+
),
|
|
401
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
402
|
+
):
|
|
403
|
+
client = None
|
|
404
|
+
try:
|
|
405
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
406
|
+
client = common.make_client(profile_name)
|
|
407
|
+
dataset_id = _resolve_dataset_id(client, dataset, project=resolved_project)
|
|
408
|
+
result_page = client.datasets.versions.list_page(
|
|
409
|
+
dataset_id,
|
|
410
|
+
project=resolved_project,
|
|
411
|
+
page=page,
|
|
412
|
+
limit=limit,
|
|
413
|
+
)
|
|
414
|
+
except Exception as exc:
|
|
415
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
416
|
+
finally:
|
|
417
|
+
if client is not None:
|
|
418
|
+
client.close()
|
|
419
|
+
|
|
420
|
+
if output == common.OutputChoice.json:
|
|
421
|
+
common.print_json(result_page)
|
|
422
|
+
return
|
|
423
|
+
|
|
424
|
+
common.print_page_table(
|
|
425
|
+
result_page,
|
|
426
|
+
["ID", "Name", "Description", "Source", "Format", "Ready"],
|
|
427
|
+
_version_rows(result_page.items),
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
@version_app.command("get")
|
|
432
|
+
def get_version(
|
|
433
|
+
dataset: str = typer.Argument(..., help="Dataset name or UUID."),
|
|
434
|
+
version: str = typer.Argument(..., help="Dataset version name or UUID."),
|
|
435
|
+
project: str | None = typer.Option(
|
|
436
|
+
None,
|
|
437
|
+
"--project",
|
|
438
|
+
help="Project name.",
|
|
439
|
+
show_default=False,
|
|
440
|
+
),
|
|
441
|
+
project_id: int | None = typer.Option(
|
|
442
|
+
None,
|
|
443
|
+
"--project-id",
|
|
444
|
+
min=1,
|
|
445
|
+
help="Project ID.",
|
|
446
|
+
show_default=False,
|
|
447
|
+
),
|
|
448
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
449
|
+
output: common.OutputChoice = typer.Option(
|
|
450
|
+
common.OutputChoice.table,
|
|
451
|
+
"--output",
|
|
452
|
+
help="Output format.",
|
|
453
|
+
),
|
|
454
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
455
|
+
):
|
|
456
|
+
client = None
|
|
457
|
+
try:
|
|
458
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
459
|
+
client = common.make_client(profile_name)
|
|
460
|
+
dataset_id = _resolve_dataset_id(client, dataset, project=resolved_project)
|
|
461
|
+
version_id = _resolve_version_id(
|
|
462
|
+
client, dataset_id, version, project=resolved_project
|
|
463
|
+
)
|
|
464
|
+
result = client.datasets.versions.get(
|
|
465
|
+
dataset_id, version_id, project=resolved_project
|
|
466
|
+
)
|
|
467
|
+
except Exception as exc:
|
|
468
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
469
|
+
finally:
|
|
470
|
+
if client is not None:
|
|
471
|
+
client.close()
|
|
472
|
+
|
|
473
|
+
if output == common.OutputChoice.json:
|
|
474
|
+
common.print_json(result)
|
|
475
|
+
return
|
|
476
|
+
|
|
477
|
+
_print_version_detail(result)
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
@version_app.command("create")
|
|
481
|
+
def create_version(
|
|
482
|
+
dataset: str = typer.Argument(..., help="Dataset name or UUID."),
|
|
483
|
+
name: str = typer.Argument(..., help="Dataset version name."),
|
|
484
|
+
project: str | None = typer.Option(
|
|
485
|
+
None,
|
|
486
|
+
"--project",
|
|
487
|
+
help="Project name.",
|
|
488
|
+
show_default=False,
|
|
489
|
+
),
|
|
490
|
+
project_id: int | None = typer.Option(
|
|
491
|
+
None,
|
|
492
|
+
"--project-id",
|
|
493
|
+
min=1,
|
|
494
|
+
help="Project ID.",
|
|
495
|
+
show_default=False,
|
|
496
|
+
),
|
|
497
|
+
source: str = typer.Option(..., "--source", help="pvc, file, or huggingface."),
|
|
498
|
+
data_uri: str | None = typer.Option(None, "--data-uri", help="PVC data URI."),
|
|
499
|
+
file: Path | None = typer.Option(None, "--file", help="Local file to upload."),
|
|
500
|
+
repository: str | None = typer.Option(
|
|
501
|
+
None, "--repository", help="Hugging Face repository ID."
|
|
502
|
+
),
|
|
503
|
+
description: str | None = typer.Option(
|
|
504
|
+
None, "--description", help="Version description."
|
|
505
|
+
),
|
|
506
|
+
subset: str | None = typer.Option(None, "--subset", help="Hugging Face subset."),
|
|
507
|
+
split: str | None = typer.Option(None, "--split", help="Hugging Face split."),
|
|
508
|
+
revision: str | None = typer.Option(
|
|
509
|
+
None, "--revision", help="Hugging Face revision."
|
|
510
|
+
),
|
|
511
|
+
storage_pvc: str | None = typer.Option(
|
|
512
|
+
None, "--storage-pvc", help="Storage PVC name."
|
|
513
|
+
),
|
|
514
|
+
wait: bool = typer.Option(False, "--wait", help="Wait for import completion."),
|
|
515
|
+
timeout: int = typer.Option(1800, "--timeout", min=1, help="Wait timeout seconds."),
|
|
516
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
517
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
518
|
+
):
|
|
519
|
+
client = None
|
|
520
|
+
try:
|
|
521
|
+
if source == "pvc":
|
|
522
|
+
if data_uri is None:
|
|
523
|
+
raise ValidationError("--source pvc requires --data-uri.")
|
|
524
|
+
if file or repository or subset or split or revision or storage_pvc:
|
|
525
|
+
raise ValidationError(
|
|
526
|
+
"--source pvc does not accept file or Hugging Face options."
|
|
527
|
+
)
|
|
528
|
+
if source == "file":
|
|
529
|
+
if file is None:
|
|
530
|
+
raise ValidationError("--source file requires --file.")
|
|
531
|
+
if not file.is_file():
|
|
532
|
+
raise ValidationError(f"File not found: {file}")
|
|
533
|
+
if data_uri or repository or subset or split or revision:
|
|
534
|
+
raise ValidationError(
|
|
535
|
+
"--source file does not accept PVC or Hugging Face options."
|
|
536
|
+
)
|
|
537
|
+
if source == "huggingface":
|
|
538
|
+
if repository is None:
|
|
539
|
+
raise ValidationError("--source huggingface requires --repository.")
|
|
540
|
+
if data_uri or file:
|
|
541
|
+
raise ValidationError(
|
|
542
|
+
"--source huggingface does not accept --data-uri or --file."
|
|
543
|
+
)
|
|
544
|
+
if source not in {"pvc", "file", "huggingface"}:
|
|
545
|
+
raise ValidationError("--source must be pvc, file, or huggingface.")
|
|
546
|
+
|
|
547
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
548
|
+
client = common.make_client(profile_name)
|
|
549
|
+
dataset_id = _resolve_dataset_id(client, dataset, project=resolved_project)
|
|
550
|
+
if source == "pvc":
|
|
551
|
+
result = client.datasets.versions.create_from_pvc(
|
|
552
|
+
dataset_id,
|
|
553
|
+
name,
|
|
554
|
+
project=resolved_project,
|
|
555
|
+
data_uri=data_uri,
|
|
556
|
+
description=description,
|
|
557
|
+
)
|
|
558
|
+
elif source == "file":
|
|
559
|
+
result = client.datasets.versions.create_from_file(
|
|
560
|
+
dataset_id,
|
|
561
|
+
name,
|
|
562
|
+
project=resolved_project,
|
|
563
|
+
file=file,
|
|
564
|
+
description=description,
|
|
565
|
+
storage_pvc=storage_pvc,
|
|
566
|
+
wait=wait,
|
|
567
|
+
timeout=timeout,
|
|
568
|
+
interval=IMPORT_POLL_INTERVAL_SECONDS,
|
|
569
|
+
)
|
|
570
|
+
else:
|
|
571
|
+
result = client.datasets.versions.create_from_huggingface(
|
|
572
|
+
dataset_id,
|
|
573
|
+
name,
|
|
574
|
+
project=resolved_project,
|
|
575
|
+
repository=repository,
|
|
576
|
+
description=description,
|
|
577
|
+
subset=subset,
|
|
578
|
+
split=split,
|
|
579
|
+
revision=revision,
|
|
580
|
+
storage_pvc=storage_pvc,
|
|
581
|
+
wait=wait,
|
|
582
|
+
timeout=timeout,
|
|
583
|
+
interval=IMPORT_POLL_INTERVAL_SECONDS,
|
|
584
|
+
)
|
|
585
|
+
if getattr(result, "state", None) == "failed":
|
|
586
|
+
message = result.error_message or "unknown error"
|
|
587
|
+
raise ValidationError(f"Dataset import failed: {message}")
|
|
588
|
+
except Exception as exc:
|
|
589
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
590
|
+
finally:
|
|
591
|
+
if client is not None:
|
|
592
|
+
client.close()
|
|
593
|
+
|
|
594
|
+
if source == "pvc":
|
|
595
|
+
common.console.print(f"[bold green]Dataset version created:[/] {escape(name)}")
|
|
596
|
+
return
|
|
597
|
+
|
|
598
|
+
if wait and getattr(result, "dataset_version_id", None):
|
|
599
|
+
common.console.print(
|
|
600
|
+
"[bold green]Dataset import ready:[/] "
|
|
601
|
+
f"{escape(result.id)} datasetVersionId={escape(result.dataset_version_id)}"
|
|
602
|
+
)
|
|
603
|
+
return
|
|
604
|
+
|
|
605
|
+
common.console.print(f"[bold green]Import started:[/] {escape(result.id)}")
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
@version_app.command("archive")
|
|
609
|
+
def archive_version(
|
|
610
|
+
dataset: str = typer.Argument(..., help="Dataset name or UUID."),
|
|
611
|
+
version: str = typer.Argument(..., help="Dataset version name or UUID."),
|
|
612
|
+
project: str | None = typer.Option(
|
|
613
|
+
None,
|
|
614
|
+
"--project",
|
|
615
|
+
help="Project name.",
|
|
616
|
+
show_default=False,
|
|
617
|
+
),
|
|
618
|
+
project_id: int | None = typer.Option(
|
|
619
|
+
None,
|
|
620
|
+
"--project-id",
|
|
621
|
+
min=1,
|
|
622
|
+
help="Project ID.",
|
|
623
|
+
show_default=False,
|
|
624
|
+
),
|
|
625
|
+
reason: str | None = typer.Option(None, "--reason", help="Archive reason."),
|
|
626
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
627
|
+
yes: bool = typer.Option(False, "--yes", help="Skip archive confirmation."),
|
|
628
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
629
|
+
):
|
|
630
|
+
try:
|
|
631
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
632
|
+
except Exception as exc:
|
|
633
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
634
|
+
|
|
635
|
+
common.confirm_delete(
|
|
636
|
+
resource="dataset version",
|
|
637
|
+
target=f"{resolved_project}/{dataset}/{version}",
|
|
638
|
+
profile_name=profile_name,
|
|
639
|
+
yes=yes,
|
|
640
|
+
)
|
|
641
|
+
client = None
|
|
642
|
+
try:
|
|
643
|
+
client = common.make_client(profile_name)
|
|
644
|
+
dataset_id = _resolve_dataset_id(client, dataset, project=resolved_project)
|
|
645
|
+
version_id = _resolve_version_id(
|
|
646
|
+
client, dataset_id, version, project=resolved_project
|
|
647
|
+
)
|
|
648
|
+
client.datasets.versions.archive(
|
|
649
|
+
dataset_id, version_id, project=resolved_project, reason=reason
|
|
650
|
+
)
|
|
651
|
+
except Exception as exc:
|
|
652
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
653
|
+
finally:
|
|
654
|
+
if client is not None:
|
|
655
|
+
client.close()
|
|
656
|
+
|
|
657
|
+
common.console.print(f"[bold green]Dataset version archived:[/] {escape(version)}")
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
@version_app.command("restore")
|
|
661
|
+
def restore_version(
|
|
662
|
+
dataset: str = typer.Argument(..., help="Dataset name or UUID."),
|
|
663
|
+
version: str = typer.Argument(..., help="Dataset version name or UUID."),
|
|
664
|
+
project: str | None = typer.Option(
|
|
665
|
+
None,
|
|
666
|
+
"--project",
|
|
667
|
+
help="Project name.",
|
|
668
|
+
show_default=False,
|
|
669
|
+
),
|
|
670
|
+
project_id: int | None = typer.Option(
|
|
671
|
+
None,
|
|
672
|
+
"--project-id",
|
|
673
|
+
min=1,
|
|
674
|
+
help="Project ID.",
|
|
675
|
+
show_default=False,
|
|
676
|
+
),
|
|
677
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
678
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
679
|
+
):
|
|
680
|
+
client = None
|
|
681
|
+
try:
|
|
682
|
+
resolved_project = _project_ref(project, project_id, profile_name)
|
|
683
|
+
client = common.make_client(profile_name)
|
|
684
|
+
dataset_id = _resolve_dataset_id(client, dataset, project=resolved_project)
|
|
685
|
+
version_id = _resolve_version_id(
|
|
686
|
+
client, dataset_id, version, project=resolved_project
|
|
687
|
+
)
|
|
688
|
+
client.datasets.versions.restore(
|
|
689
|
+
dataset_id, version_id, project=resolved_project
|
|
690
|
+
)
|
|
691
|
+
except Exception as exc:
|
|
692
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
693
|
+
finally:
|
|
694
|
+
if client is not None:
|
|
695
|
+
client.close()
|
|
696
|
+
|
|
697
|
+
common.console.print(f"[bold green]Dataset version restored:[/] {escape(version)}")
|