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,198 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import math
|
|
5
|
+
import os
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from enum import Enum
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import typer
|
|
11
|
+
from rich.console import Console
|
|
12
|
+
from rich.table import Table
|
|
13
|
+
from rich.text import Text
|
|
14
|
+
|
|
15
|
+
from nufi import NuFi
|
|
16
|
+
from nufi import auth, config
|
|
17
|
+
from nufi.exceptions import AuthenticationError, NotFoundError, ValidationError
|
|
18
|
+
from nufi.models import Page
|
|
19
|
+
from nufi.transport import SyncTransport
|
|
20
|
+
|
|
21
|
+
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
|
|
22
|
+
|
|
23
|
+
console = Console()
|
|
24
|
+
error_console = Console(stderr=True)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class OutputChoice(str, Enum):
|
|
28
|
+
table = "table"
|
|
29
|
+
json = "json"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def validate_wait_options(timeout: float, interval: float) -> None:
|
|
33
|
+
for name, value in (("--timeout", timeout), ("--interval", interval)):
|
|
34
|
+
if not math.isfinite(value) or value <= 0:
|
|
35
|
+
raise typer.BadParameter(
|
|
36
|
+
"must be a finite number greater than 0",
|
|
37
|
+
param_hint=name,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def make_client(
|
|
42
|
+
profile_name: str | None,
|
|
43
|
+
*,
|
|
44
|
+
now: int | Callable[[], int] | None = None,
|
|
45
|
+
) -> NuFi:
|
|
46
|
+
try:
|
|
47
|
+
kwargs = {"now": now} if now is not None else {}
|
|
48
|
+
return NuFi.from_profile(profile_name, **kwargs)
|
|
49
|
+
except AuthenticationError:
|
|
50
|
+
resolved_name, profile = config.resolve_profile(profile_name)
|
|
51
|
+
if auth.TokenStore().path_for(resolved_name).exists():
|
|
52
|
+
raise
|
|
53
|
+
token = os.environ.get("NUFI_TOKEN", "").strip()
|
|
54
|
+
if not token:
|
|
55
|
+
raise
|
|
56
|
+
return NuFi(
|
|
57
|
+
base_url=profile.resolved_api_url,
|
|
58
|
+
access_token=token,
|
|
59
|
+
project=profile.active_project,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def make_profile_client(profile_name: str | None) -> NuFi:
|
|
64
|
+
"""Create a human-login client without the NUFI_TOKEN fallback."""
|
|
65
|
+
return NuFi.from_profile(profile_name)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def resolve_cli_project(
|
|
69
|
+
project: str | None,
|
|
70
|
+
project_id: int | None,
|
|
71
|
+
*,
|
|
72
|
+
profile_name: str | None,
|
|
73
|
+
) -> str | int:
|
|
74
|
+
if project is not None and project_id is not None:
|
|
75
|
+
raise typer.BadParameter("Use either --project or --project-id, not both.")
|
|
76
|
+
if project_id is not None:
|
|
77
|
+
return project_id
|
|
78
|
+
return config.resolve_project(project, profile_name=profile_name)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def show_help_if_no_subcommand(ctx: typer.Context) -> None:
|
|
82
|
+
if ctx.invoked_subcommand is not None:
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
typer.echo(ctx.get_help())
|
|
86
|
+
raise typer.Exit(code=0)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def serialize(value: Any) -> Any:
|
|
90
|
+
if hasattr(value, "model_dump"):
|
|
91
|
+
return value.model_dump(mode="json", by_alias=True)
|
|
92
|
+
if isinstance(value, list):
|
|
93
|
+
return [serialize(item) for item in value]
|
|
94
|
+
if isinstance(value, dict):
|
|
95
|
+
return {key: serialize(item) for key, item in value.items()}
|
|
96
|
+
return value
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def print_json(value: Any) -> None:
|
|
100
|
+
console.print(json.dumps(serialize(value), indent=2), markup=False, soft_wrap=True)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def bounded_error(value: str | None) -> str:
|
|
104
|
+
text = value or ""
|
|
105
|
+
try:
|
|
106
|
+
payload = json.loads(text)
|
|
107
|
+
except (json.JSONDecodeError, TypeError):
|
|
108
|
+
redacted = SyncTransport._redact_text(text)
|
|
109
|
+
else:
|
|
110
|
+
payload = SyncTransport._redact_value(payload)
|
|
111
|
+
redacted = (
|
|
112
|
+
payload
|
|
113
|
+
if isinstance(payload, str)
|
|
114
|
+
else json.dumps(payload, ensure_ascii=False)
|
|
115
|
+
)
|
|
116
|
+
return SyncTransport._bound_text(redacted)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def print_table(
|
|
120
|
+
columns: list[str],
|
|
121
|
+
rows: list[list[str]],
|
|
122
|
+
*,
|
|
123
|
+
width: int | None = None,
|
|
124
|
+
show_lines: bool = False,
|
|
125
|
+
) -> None:
|
|
126
|
+
table = Table(*columns, width=width, show_lines=show_lines)
|
|
127
|
+
for row in rows:
|
|
128
|
+
table.add_row(*(Text(str(value)) for value in row))
|
|
129
|
+
console.print(table, width=width, crop=False)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def print_page_table(
|
|
133
|
+
page: Page[Any],
|
|
134
|
+
columns: list[str],
|
|
135
|
+
rows: list[list[str]],
|
|
136
|
+
*,
|
|
137
|
+
width: int | None = None,
|
|
138
|
+
show_lines: bool = False,
|
|
139
|
+
) -> None:
|
|
140
|
+
print_table(columns, rows, width=width, show_lines=show_lines)
|
|
141
|
+
first = (page.page - 1) * page.limit + 1 if page.items else 0
|
|
142
|
+
last = first + len(page.items) - 1 if page.items else 0
|
|
143
|
+
console.print(f"Showing {first}-{last} of {page.total}")
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def resolve_named_resource(
|
|
147
|
+
items: Any,
|
|
148
|
+
target: str,
|
|
149
|
+
*,
|
|
150
|
+
resource: str,
|
|
151
|
+
id_attribute: str = "id",
|
|
152
|
+
name_attribute: str = "name",
|
|
153
|
+
) -> Any:
|
|
154
|
+
matches = []
|
|
155
|
+
for item in items:
|
|
156
|
+
if str(getattr(item, id_attribute)) == target:
|
|
157
|
+
return item
|
|
158
|
+
if getattr(item, name_attribute) == target:
|
|
159
|
+
matches.append(item)
|
|
160
|
+
if len(matches) == 1:
|
|
161
|
+
return matches[0]
|
|
162
|
+
if matches:
|
|
163
|
+
ids = ", ".join(str(getattr(item, id_attribute)) for item in matches[:5])
|
|
164
|
+
suffix = ", ..." if len(matches) > 5 else ""
|
|
165
|
+
raise ValidationError(
|
|
166
|
+
f"Multiple {resource}s named '{target}'; matching IDs: {ids}{suffix}."
|
|
167
|
+
)
|
|
168
|
+
raise NotFoundError(f"{resource.capitalize()} not found: {target}")
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def confirm_delete(
|
|
172
|
+
*, resource: str, target: str, profile_name: str | None, yes: bool
|
|
173
|
+
) -> None:
|
|
174
|
+
if yes:
|
|
175
|
+
return
|
|
176
|
+
|
|
177
|
+
profile_label = profile_name or "active profile"
|
|
178
|
+
if typer.confirm(
|
|
179
|
+
f"Delete {resource} '{target}' from {profile_label}?",
|
|
180
|
+
default=False,
|
|
181
|
+
):
|
|
182
|
+
return
|
|
183
|
+
|
|
184
|
+
console.print("Aborted.")
|
|
185
|
+
raise typer.Exit(code=0)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def handle_cli_error(exc: Exception, *, verbose: bool) -> None:
|
|
189
|
+
if verbose:
|
|
190
|
+
details = [f"{type(exc).__name__}: {exc}"]
|
|
191
|
+
for field in ("status_code", "request_id", "response_body"):
|
|
192
|
+
if value := getattr(exc, field, None):
|
|
193
|
+
details.append(f"{field}={value}")
|
|
194
|
+
detail = "; ".join(details)
|
|
195
|
+
else:
|
|
196
|
+
detail = str(exc)
|
|
197
|
+
error_console.print(f"Error: {detail}", style="bold red", markup=False)
|
|
198
|
+
raise typer.Exit(code=124 if isinstance(exc, TimeoutError) else 1) from exc
|
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from nufi.cli.commands import common
|
|
6
|
+
|
|
7
|
+
app = typer.Typer(
|
|
8
|
+
help="Manage NuFi compile runs.",
|
|
9
|
+
invoke_without_command=True,
|
|
10
|
+
context_settings=common.CONTEXT_SETTINGS,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@app.callback()
|
|
15
|
+
def compiles(ctx: typer.Context):
|
|
16
|
+
common.show_help_if_no_subcommand(ctx)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def _print_run(run, output: common.OutputChoice) -> None:
|
|
20
|
+
if output == common.OutputChoice.json:
|
|
21
|
+
payload = common.serialize(run)
|
|
22
|
+
for key in ("errorMessage", "registrationError"):
|
|
23
|
+
if payload.get(key):
|
|
24
|
+
payload[key] = common.bounded_error(payload[key])
|
|
25
|
+
common.print_json(payload)
|
|
26
|
+
return
|
|
27
|
+
common.print_table(
|
|
28
|
+
[
|
|
29
|
+
"ID",
|
|
30
|
+
"CR Name",
|
|
31
|
+
"Model",
|
|
32
|
+
"Version",
|
|
33
|
+
"Platform",
|
|
34
|
+
"Phase",
|
|
35
|
+
"Artifact",
|
|
36
|
+
"Failure",
|
|
37
|
+
"Created",
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
[
|
|
41
|
+
str(run.id),
|
|
42
|
+
run.cr_name,
|
|
43
|
+
run.model_name,
|
|
44
|
+
run.version,
|
|
45
|
+
run.platform,
|
|
46
|
+
run.phase,
|
|
47
|
+
run.artifact_name,
|
|
48
|
+
common.bounded_error(run.error_message or run.registration_error),
|
|
49
|
+
run.created_at.isoformat(),
|
|
50
|
+
]
|
|
51
|
+
],
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@app.command("list")
|
|
56
|
+
def list_compiles(
|
|
57
|
+
project: str | None = typer.Option(
|
|
58
|
+
None,
|
|
59
|
+
"--project",
|
|
60
|
+
help="Project name.",
|
|
61
|
+
show_default=False,
|
|
62
|
+
),
|
|
63
|
+
project_id: int | None = typer.Option(
|
|
64
|
+
None,
|
|
65
|
+
"--project-id",
|
|
66
|
+
min=1,
|
|
67
|
+
help="Project ID.",
|
|
68
|
+
show_default=False,
|
|
69
|
+
),
|
|
70
|
+
model_name: str | None = typer.Option(
|
|
71
|
+
None,
|
|
72
|
+
"--model",
|
|
73
|
+
help="Model name.",
|
|
74
|
+
show_default=False,
|
|
75
|
+
),
|
|
76
|
+
version: str | None = typer.Option(
|
|
77
|
+
None,
|
|
78
|
+
"--version",
|
|
79
|
+
help="Model version.",
|
|
80
|
+
show_default=False,
|
|
81
|
+
),
|
|
82
|
+
phase: list[str] | None = typer.Option(
|
|
83
|
+
None,
|
|
84
|
+
"--phase",
|
|
85
|
+
help="Compile phase filter.",
|
|
86
|
+
show_default=False,
|
|
87
|
+
),
|
|
88
|
+
page: int | None = typer.Option(
|
|
89
|
+
None,
|
|
90
|
+
"--page",
|
|
91
|
+
min=1,
|
|
92
|
+
help="Page number.",
|
|
93
|
+
show_default=False,
|
|
94
|
+
),
|
|
95
|
+
limit: int | None = typer.Option(
|
|
96
|
+
None,
|
|
97
|
+
"--limit",
|
|
98
|
+
min=1,
|
|
99
|
+
max=100,
|
|
100
|
+
help="Runs per page.",
|
|
101
|
+
show_default=False,
|
|
102
|
+
),
|
|
103
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
104
|
+
output: common.OutputChoice = typer.Option(
|
|
105
|
+
common.OutputChoice.table,
|
|
106
|
+
"--output",
|
|
107
|
+
help="Output format.",
|
|
108
|
+
),
|
|
109
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
110
|
+
):
|
|
111
|
+
client = None
|
|
112
|
+
try:
|
|
113
|
+
resolved_project = common.resolve_cli_project(
|
|
114
|
+
project,
|
|
115
|
+
project_id,
|
|
116
|
+
profile_name=profile_name,
|
|
117
|
+
)
|
|
118
|
+
client = common.make_client(profile_name)
|
|
119
|
+
result_page = client.compiles.list_page(
|
|
120
|
+
project=resolved_project,
|
|
121
|
+
model_name=model_name,
|
|
122
|
+
version=version,
|
|
123
|
+
phase=phase,
|
|
124
|
+
page=page,
|
|
125
|
+
limit=limit,
|
|
126
|
+
)
|
|
127
|
+
except Exception as exc:
|
|
128
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
129
|
+
finally:
|
|
130
|
+
if client is not None:
|
|
131
|
+
client.close()
|
|
132
|
+
|
|
133
|
+
if output == common.OutputChoice.json:
|
|
134
|
+
common.print_json(result_page)
|
|
135
|
+
return
|
|
136
|
+
|
|
137
|
+
common.print_page_table(
|
|
138
|
+
result_page,
|
|
139
|
+
[
|
|
140
|
+
"ID",
|
|
141
|
+
"CR Name",
|
|
142
|
+
"Model",
|
|
143
|
+
"Version",
|
|
144
|
+
"Platform",
|
|
145
|
+
"Phase",
|
|
146
|
+
"Artifact",
|
|
147
|
+
"Created",
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
[
|
|
151
|
+
str(run.id),
|
|
152
|
+
run.cr_name,
|
|
153
|
+
run.model_name,
|
|
154
|
+
run.version,
|
|
155
|
+
run.platform,
|
|
156
|
+
run.phase,
|
|
157
|
+
run.artifact_name,
|
|
158
|
+
run.created_at.isoformat(),
|
|
159
|
+
]
|
|
160
|
+
for run in result_page.items
|
|
161
|
+
],
|
|
162
|
+
)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@app.command("create")
|
|
166
|
+
def create_compile(
|
|
167
|
+
model_name: str = typer.Argument(..., help="Model name."),
|
|
168
|
+
project: str | None = typer.Option(
|
|
169
|
+
None,
|
|
170
|
+
"--project",
|
|
171
|
+
help="Project name.",
|
|
172
|
+
show_default=False,
|
|
173
|
+
),
|
|
174
|
+
project_id: int | None = typer.Option(
|
|
175
|
+
None,
|
|
176
|
+
"--project-id",
|
|
177
|
+
min=1,
|
|
178
|
+
help="Project ID.",
|
|
179
|
+
show_default=False,
|
|
180
|
+
),
|
|
181
|
+
version: str = typer.Option(..., "--version", "-v", help="Model version."),
|
|
182
|
+
tensor_parallel_size: int | None = typer.Option(
|
|
183
|
+
None,
|
|
184
|
+
"--tensor-parallel-size",
|
|
185
|
+
"-tp",
|
|
186
|
+
min=1,
|
|
187
|
+
help="Tensor parallel size.",
|
|
188
|
+
show_default=False,
|
|
189
|
+
),
|
|
190
|
+
pipeline_parallel_size: int | None = typer.Option(
|
|
191
|
+
None,
|
|
192
|
+
"--pipeline-parallel-size",
|
|
193
|
+
"-pp",
|
|
194
|
+
min=1,
|
|
195
|
+
help="Pipeline parallel size.",
|
|
196
|
+
show_default=False,
|
|
197
|
+
),
|
|
198
|
+
max_model_len: int | None = typer.Option(
|
|
199
|
+
None,
|
|
200
|
+
"--max-model-len",
|
|
201
|
+
min=1,
|
|
202
|
+
help="Maximum model length.",
|
|
203
|
+
show_default=False,
|
|
204
|
+
),
|
|
205
|
+
optim_level: str | None = typer.Option(
|
|
206
|
+
None,
|
|
207
|
+
"--optim-level",
|
|
208
|
+
"-O",
|
|
209
|
+
help="FXB optimization level.",
|
|
210
|
+
show_default=False,
|
|
211
|
+
),
|
|
212
|
+
cpu_request: str | None = typer.Option(
|
|
213
|
+
None,
|
|
214
|
+
"--cpu",
|
|
215
|
+
help="Requested CPU.",
|
|
216
|
+
show_default=False,
|
|
217
|
+
),
|
|
218
|
+
memory_request: str | None = typer.Option(
|
|
219
|
+
None,
|
|
220
|
+
"--memory",
|
|
221
|
+
help="Requested memory.",
|
|
222
|
+
show_default=False,
|
|
223
|
+
),
|
|
224
|
+
extra_args: str | None = typer.Option(
|
|
225
|
+
None,
|
|
226
|
+
"--extra-args",
|
|
227
|
+
help="Additional fxb build args.",
|
|
228
|
+
show_default=False,
|
|
229
|
+
),
|
|
230
|
+
env: list[str] | None = typer.Option(
|
|
231
|
+
None,
|
|
232
|
+
"--env",
|
|
233
|
+
help="Environment variable as NAME=VALUE.",
|
|
234
|
+
show_default=False,
|
|
235
|
+
),
|
|
236
|
+
wait: bool = typer.Option(False, "--wait", help="Wait for terminal state."),
|
|
237
|
+
timeout: float = typer.Option(
|
|
238
|
+
1800, "--timeout", min=0.001, help="Wait timeout in seconds."
|
|
239
|
+
),
|
|
240
|
+
interval: float = typer.Option(
|
|
241
|
+
5, "--interval", min=0.001, help="Polling interval in seconds."
|
|
242
|
+
),
|
|
243
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
244
|
+
output: common.OutputChoice = typer.Option(
|
|
245
|
+
common.OutputChoice.table,
|
|
246
|
+
"--output",
|
|
247
|
+
help="Output format.",
|
|
248
|
+
),
|
|
249
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
250
|
+
):
|
|
251
|
+
common.validate_wait_options(timeout, interval)
|
|
252
|
+
client = None
|
|
253
|
+
try:
|
|
254
|
+
resolved_project = common.resolve_cli_project(
|
|
255
|
+
project,
|
|
256
|
+
project_id,
|
|
257
|
+
profile_name=profile_name,
|
|
258
|
+
)
|
|
259
|
+
client = common.make_client(profile_name)
|
|
260
|
+
run = client.compiles.create(
|
|
261
|
+
project=resolved_project,
|
|
262
|
+
model_name=model_name,
|
|
263
|
+
version=version,
|
|
264
|
+
tensor_parallel_size=tensor_parallel_size,
|
|
265
|
+
pipeline_parallel_size=pipeline_parallel_size,
|
|
266
|
+
max_model_len=max_model_len,
|
|
267
|
+
optim_level=optim_level,
|
|
268
|
+
cpu_request=cpu_request,
|
|
269
|
+
memory_request=memory_request,
|
|
270
|
+
extra_args=extra_args,
|
|
271
|
+
env=_parse_env(env),
|
|
272
|
+
)
|
|
273
|
+
if wait:
|
|
274
|
+
typer.echo(
|
|
275
|
+
f"Compile created: {run.cr_name} (ID: {run.id}); resume with "
|
|
276
|
+
f"'nufi compile wait {run.cr_name}'",
|
|
277
|
+
err=True,
|
|
278
|
+
)
|
|
279
|
+
run = client.compiles.wait(
|
|
280
|
+
run.cr_name,
|
|
281
|
+
project=resolved_project,
|
|
282
|
+
timeout=timeout,
|
|
283
|
+
interval=interval,
|
|
284
|
+
)
|
|
285
|
+
except Exception as exc:
|
|
286
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
287
|
+
finally:
|
|
288
|
+
if client is not None:
|
|
289
|
+
client.close()
|
|
290
|
+
|
|
291
|
+
if wait or output == common.OutputChoice.json:
|
|
292
|
+
_print_run(run, output)
|
|
293
|
+
else:
|
|
294
|
+
common.console.print(
|
|
295
|
+
f"[bold green]Compile created:[/] {run.cr_name} (ID: {run.id})"
|
|
296
|
+
)
|
|
297
|
+
if run.phase == "Failed" or run.registration_error:
|
|
298
|
+
raise typer.Exit(code=1)
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
@app.command("get")
|
|
302
|
+
def get_compile(
|
|
303
|
+
name: str | None = typer.Argument(None, help="Compile CR name."),
|
|
304
|
+
run_id: int | None = typer.Option(
|
|
305
|
+
None,
|
|
306
|
+
"--run-id",
|
|
307
|
+
min=1,
|
|
308
|
+
help="Compile run ID.",
|
|
309
|
+
show_default=False,
|
|
310
|
+
),
|
|
311
|
+
project: str | None = typer.Option(
|
|
312
|
+
None,
|
|
313
|
+
"--project",
|
|
314
|
+
help="Project name.",
|
|
315
|
+
show_default=False,
|
|
316
|
+
),
|
|
317
|
+
project_id: int | None = typer.Option(
|
|
318
|
+
None,
|
|
319
|
+
"--project-id",
|
|
320
|
+
min=1,
|
|
321
|
+
help="Project ID.",
|
|
322
|
+
show_default=False,
|
|
323
|
+
),
|
|
324
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
325
|
+
output: common.OutputChoice = typer.Option(
|
|
326
|
+
common.OutputChoice.json,
|
|
327
|
+
"--output",
|
|
328
|
+
help="Output format.",
|
|
329
|
+
),
|
|
330
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
331
|
+
):
|
|
332
|
+
client = None
|
|
333
|
+
try:
|
|
334
|
+
if (name is None) == (run_id is None):
|
|
335
|
+
raise typer.BadParameter("Provide either NAME or --run-id.")
|
|
336
|
+
resolved_project = common.resolve_cli_project(
|
|
337
|
+
project,
|
|
338
|
+
project_id,
|
|
339
|
+
profile_name=profile_name,
|
|
340
|
+
)
|
|
341
|
+
client = common.make_client(profile_name)
|
|
342
|
+
run = (
|
|
343
|
+
client.compiles.get_by_id(run_id, project=resolved_project)
|
|
344
|
+
if run_id is not None
|
|
345
|
+
else client.compiles.get(name, project=resolved_project)
|
|
346
|
+
)
|
|
347
|
+
except Exception as exc:
|
|
348
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
349
|
+
finally:
|
|
350
|
+
if client is not None:
|
|
351
|
+
client.close()
|
|
352
|
+
|
|
353
|
+
_print_run(run, output)
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
@app.command("wait")
|
|
357
|
+
def wait_compile(
|
|
358
|
+
target: str = typer.Argument(..., help="Compile CR name or numeric run ID."),
|
|
359
|
+
project: str | None = typer.Option(
|
|
360
|
+
None,
|
|
361
|
+
"--project",
|
|
362
|
+
help="Project name.",
|
|
363
|
+
show_default=False,
|
|
364
|
+
),
|
|
365
|
+
project_id: int | None = typer.Option(
|
|
366
|
+
None,
|
|
367
|
+
"--project-id",
|
|
368
|
+
min=1,
|
|
369
|
+
help="Project ID.",
|
|
370
|
+
show_default=False,
|
|
371
|
+
),
|
|
372
|
+
timeout: float = typer.Option(
|
|
373
|
+
1800, "--timeout", min=0.001, help="Wait timeout in seconds."
|
|
374
|
+
),
|
|
375
|
+
interval: float = typer.Option(
|
|
376
|
+
5, "--interval", min=0.001, help="Polling interval in seconds."
|
|
377
|
+
),
|
|
378
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
379
|
+
output: common.OutputChoice = typer.Option(
|
|
380
|
+
common.OutputChoice.table,
|
|
381
|
+
"--output",
|
|
382
|
+
help="Output format.",
|
|
383
|
+
),
|
|
384
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
385
|
+
):
|
|
386
|
+
common.validate_wait_options(timeout, interval)
|
|
387
|
+
client = None
|
|
388
|
+
try:
|
|
389
|
+
resolved_project = common.resolve_cli_project(
|
|
390
|
+
project,
|
|
391
|
+
project_id,
|
|
392
|
+
profile_name=profile_name,
|
|
393
|
+
)
|
|
394
|
+
client = common.make_client(profile_name)
|
|
395
|
+
run = client.compiles.wait(
|
|
396
|
+
int(target) if target.isdecimal() else target,
|
|
397
|
+
project=resolved_project,
|
|
398
|
+
timeout=timeout,
|
|
399
|
+
interval=interval,
|
|
400
|
+
)
|
|
401
|
+
except Exception as exc:
|
|
402
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
403
|
+
finally:
|
|
404
|
+
if client is not None:
|
|
405
|
+
client.close()
|
|
406
|
+
|
|
407
|
+
_print_run(run, output)
|
|
408
|
+
if run.phase == "Failed" or run.registration_error:
|
|
409
|
+
raise typer.Exit(code=1)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
@app.command("retry")
|
|
413
|
+
def retry_compile(
|
|
414
|
+
name: str = typer.Argument(..., help="Compile CR name."),
|
|
415
|
+
step_name: str = typer.Argument(..., help="Step name."),
|
|
416
|
+
project: str | None = typer.Option(
|
|
417
|
+
None,
|
|
418
|
+
"--project",
|
|
419
|
+
help="Project name.",
|
|
420
|
+
show_default=False,
|
|
421
|
+
),
|
|
422
|
+
project_id: int | None = typer.Option(
|
|
423
|
+
None,
|
|
424
|
+
"--project-id",
|
|
425
|
+
min=1,
|
|
426
|
+
help="Project ID.",
|
|
427
|
+
show_default=False,
|
|
428
|
+
),
|
|
429
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
430
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
431
|
+
):
|
|
432
|
+
client = None
|
|
433
|
+
try:
|
|
434
|
+
resolved_project = common.resolve_cli_project(
|
|
435
|
+
project,
|
|
436
|
+
project_id,
|
|
437
|
+
profile_name=profile_name,
|
|
438
|
+
)
|
|
439
|
+
client = common.make_client(profile_name)
|
|
440
|
+
client.compiles.retry(name, step_name, project=resolved_project)
|
|
441
|
+
except Exception as exc:
|
|
442
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
443
|
+
finally:
|
|
444
|
+
if client is not None:
|
|
445
|
+
client.close()
|
|
446
|
+
|
|
447
|
+
common.console.print(f"[bold green]Compile step retried:[/] {name}/{step_name}")
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
@app.command("delete")
|
|
451
|
+
def delete_compile(
|
|
452
|
+
name: str = typer.Argument(..., help="Compile CR name."),
|
|
453
|
+
project: str | None = typer.Option(
|
|
454
|
+
None,
|
|
455
|
+
"--project",
|
|
456
|
+
help="Project name.",
|
|
457
|
+
show_default=False,
|
|
458
|
+
),
|
|
459
|
+
project_id: int | None = typer.Option(
|
|
460
|
+
None,
|
|
461
|
+
"--project-id",
|
|
462
|
+
min=1,
|
|
463
|
+
help="Project ID.",
|
|
464
|
+
show_default=False,
|
|
465
|
+
),
|
|
466
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
467
|
+
yes: bool = typer.Option(False, "--yes", help="Skip delete confirmation."),
|
|
468
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
469
|
+
):
|
|
470
|
+
try:
|
|
471
|
+
resolved_project = common.resolve_cli_project(
|
|
472
|
+
project,
|
|
473
|
+
project_id,
|
|
474
|
+
profile_name=profile_name,
|
|
475
|
+
)
|
|
476
|
+
except Exception as exc:
|
|
477
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
478
|
+
|
|
479
|
+
common.confirm_delete(
|
|
480
|
+
resource="compile",
|
|
481
|
+
target=f"{resolved_project}/{name}",
|
|
482
|
+
profile_name=profile_name,
|
|
483
|
+
yes=yes,
|
|
484
|
+
)
|
|
485
|
+
client = None
|
|
486
|
+
try:
|
|
487
|
+
client = common.make_client(profile_name)
|
|
488
|
+
client.compiles.delete(name, project=resolved_project)
|
|
489
|
+
except Exception as exc:
|
|
490
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
491
|
+
finally:
|
|
492
|
+
if client is not None:
|
|
493
|
+
client.close()
|
|
494
|
+
|
|
495
|
+
common.console.print(f"[bold green]Compile deleted:[/] {name}")
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
def _parse_env(entries: list[str] | None) -> list[dict[str, str]] | None:
|
|
499
|
+
if not entries:
|
|
500
|
+
return None
|
|
501
|
+
parsed = []
|
|
502
|
+
for entry in entries:
|
|
503
|
+
name, sep, value = entry.partition("=")
|
|
504
|
+
if not sep or not name:
|
|
505
|
+
raise typer.BadParameter("--env must use NAME=VALUE.")
|
|
506
|
+
parsed.append({"name": name, "value": value})
|
|
507
|
+
return parsed
|