trainwave-cli 0.1.11__tar.gz → 0.2.0__tar.gz
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.
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/PKG-INFO +1 -1
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/pyproject.toml +1 -1
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/api.py +36 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/cli/jobs.py +36 -10
- trainwave_cli-0.2.0/trainwave_cli/cli/secrets.py +108 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/cli/setup.py +7 -3
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/main.py +2 -1
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/README.md +0 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/__init__.py +0 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/cli/auth.py +0 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/cli/offers.py +0 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/config/config.py +0 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/format_utils.py +0 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/io.py +0 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/utils.py +0 -0
- {trainwave_cli-0.1.11 → trainwave_cli-0.2.0}/trainwave_cli/xceptions.py +0 -0
|
@@ -75,6 +75,17 @@ class TrainwaveProject:
|
|
|
75
75
|
name: str
|
|
76
76
|
|
|
77
77
|
|
|
78
|
+
@dataclass(frozen=True)
|
|
79
|
+
class Secret:
|
|
80
|
+
id: str
|
|
81
|
+
rid: str
|
|
82
|
+
name: str
|
|
83
|
+
organization: str
|
|
84
|
+
project: str | None
|
|
85
|
+
digest: str
|
|
86
|
+
created_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
|
|
87
|
+
|
|
88
|
+
|
|
78
89
|
@dataclass(frozen=True)
|
|
79
90
|
class DjangoPagination:
|
|
80
91
|
count: int
|
|
@@ -243,6 +254,31 @@ class Api:
|
|
|
243
254
|
async def cancel_job(self, job_id: str) -> None:
|
|
244
255
|
await self.request("POST", f"/api/v1/jobs/{job_id}/cancel/", json={})
|
|
245
256
|
|
|
257
|
+
async def list_secrets(self, org_id: str) -> list[Secret]:
|
|
258
|
+
res = await self.request("GET", f"/api/v1/organizations/{org_id}/secrets/")
|
|
259
|
+
res_json = res.json()
|
|
260
|
+
values = res_json.get("results", [])
|
|
261
|
+
return [from_dict(Secret, v) for v in values]
|
|
262
|
+
|
|
263
|
+
async def set_secrets(
|
|
264
|
+
self, org_id: str, secrets: dict[str, str], project: str | None = None
|
|
265
|
+
) -> None:
|
|
266
|
+
data: dict[str, Any] = {
|
|
267
|
+
"secrets": [{"name": k, "value": v} for k, v in secrets.items()]
|
|
268
|
+
}
|
|
269
|
+
if project:
|
|
270
|
+
data["project"] = project
|
|
271
|
+
|
|
272
|
+
await self.request(
|
|
273
|
+
"POST", f"/api/v1/organizations/{org_id}/secrets/", json=data
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
async def unset_secrets(self, org_id: str, secrets: list[str]) -> None:
|
|
277
|
+
for secret in secrets:
|
|
278
|
+
await self.request(
|
|
279
|
+
"DELETE", f"/api/v1/organizations/{org_id}/secrets/{secret}/"
|
|
280
|
+
)
|
|
281
|
+
|
|
246
282
|
async def code_submission(self, job: Job) -> None:
|
|
247
283
|
await self.request("POST", f"/api/v1/jobs/{job.id}/code_submission/")
|
|
248
284
|
|
|
@@ -2,7 +2,6 @@ import json
|
|
|
2
2
|
import os
|
|
3
3
|
import sys
|
|
4
4
|
import traceback
|
|
5
|
-
from typing import Optional
|
|
6
5
|
from dataclasses import asdict
|
|
7
6
|
from datetime import datetime, timezone
|
|
8
7
|
from pathlib import Path
|
|
@@ -35,22 +34,49 @@ async def launch( # noqa
|
|
|
35
34
|
# Basic job parameters
|
|
36
35
|
name: Annotated[str, typer.Option(help="The name of the job")],
|
|
37
36
|
project: Annotated[str, typer.Option(help="The project ID or RID")],
|
|
38
|
-
setup_command: Annotated[
|
|
37
|
+
setup_command: Annotated[
|
|
38
|
+
str, typer.Option(help="The command to run before the job")
|
|
39
|
+
],
|
|
39
40
|
run_command: Annotated[str, typer.Option(help="The command to run the job")],
|
|
40
41
|
# Optional params
|
|
41
|
-
organization: Annotated[
|
|
42
|
-
|
|
42
|
+
organization: Annotated[
|
|
43
|
+
str | None, typer.Option(help="ID or RID of organization")
|
|
44
|
+
] = None,
|
|
45
|
+
expires: Annotated[
|
|
46
|
+
str,
|
|
47
|
+
typer.Option(
|
|
48
|
+
help="Time til' the job will be automatically terminated. Example `1d`, `2h`` etc."
|
|
49
|
+
),
|
|
50
|
+
] = "",
|
|
43
51
|
env_vars={}, # dict[str, str] not supported by typer yet
|
|
44
|
-
exclude_gitignore: Annotated[
|
|
45
|
-
|
|
52
|
+
exclude_gitignore: Annotated[
|
|
53
|
+
bool,
|
|
54
|
+
typer.Option(
|
|
55
|
+
help="If set the gitignore file will be used to ignore files when packaging the job"
|
|
56
|
+
),
|
|
57
|
+
] = True,
|
|
58
|
+
exclude_regex: Annotated[
|
|
59
|
+
str | None,
|
|
60
|
+
typer.Option(
|
|
61
|
+
help="Files matching this pattern will be ignored when packaging up the job"
|
|
62
|
+
),
|
|
63
|
+
] = None,
|
|
46
64
|
# Harware parameters
|
|
47
|
-
image: Annotated[
|
|
65
|
+
image: Annotated[
|
|
66
|
+
str, typer.Option(help="The docker image to use as base for the job")
|
|
67
|
+
] = "",
|
|
48
68
|
hdd_size_mb: Annotated[int, typer.Option(help="Hard drive size in MB")] = 20,
|
|
49
69
|
memory_mb: Annotated[int, typer.Option(help="Memory in MB")] = 0,
|
|
50
70
|
cpus: Annotated[int, typer.Option(help="Number of CPUs")] = 0,
|
|
51
|
-
gpus: Annotated[
|
|
52
|
-
|
|
53
|
-
|
|
71
|
+
gpus: Annotated[
|
|
72
|
+
int, typer.Option(help="Number of GPUs to allocate of the `gpu_type`")
|
|
73
|
+
] = 0,
|
|
74
|
+
gpu_type: Annotated[
|
|
75
|
+
str, typer.Option(help="Canonical name of the GPU to use")
|
|
76
|
+
] = "",
|
|
77
|
+
compliance_soc2: Annotated[
|
|
78
|
+
bool | None, typer.Option(help="Only use SOC2 compliant machines")
|
|
79
|
+
] = None,
|
|
54
80
|
) -> None:
|
|
55
81
|
"""
|
|
56
82
|
Launch a job on Trainwave using the current configuration.
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from typing import List
|
|
4
|
+
import sys
|
|
5
|
+
import traceback
|
|
6
|
+
from dataclasses import asdict
|
|
7
|
+
from datetime import datetime, timezone
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Annotated
|
|
10
|
+
from urllib.parse import urlparse
|
|
11
|
+
|
|
12
|
+
from operator import itemgetter
|
|
13
|
+
import human_readable
|
|
14
|
+
import pytimeparse
|
|
15
|
+
import typer
|
|
16
|
+
import websockets
|
|
17
|
+
from dateutil import parser
|
|
18
|
+
from loguru import logger
|
|
19
|
+
from tabulate import tabulate
|
|
20
|
+
from typer_config.decorators import use_toml_config
|
|
21
|
+
|
|
22
|
+
from trainwave_cli.api import Api, Secret
|
|
23
|
+
from trainwave_cli.config.config import config
|
|
24
|
+
from trainwave_cli.utils import async_command, ensure_api_key
|
|
25
|
+
|
|
26
|
+
app = typer.Typer()
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@app.command()
|
|
30
|
+
@async_command
|
|
31
|
+
@use_toml_config(default_value="trainwave.toml")
|
|
32
|
+
@ensure_api_key
|
|
33
|
+
async def list(
|
|
34
|
+
organization: Annotated[str, typer.Option(help="The organization ID or RID")],
|
|
35
|
+
) -> None:
|
|
36
|
+
api_client = Api(config.api_key, config.endpoint)
|
|
37
|
+
secrets = await api_client.list_secrets(organization)
|
|
38
|
+
|
|
39
|
+
project_scoped = [secret for secret in secrets if secret.project]
|
|
40
|
+
org_scoped = [secret for secret in secrets if not secret.project]
|
|
41
|
+
unique: dict[str, tuple[bool, Secret]] = {}
|
|
42
|
+
|
|
43
|
+
for org_secret in org_scoped:
|
|
44
|
+
unique[org_secret.name] = (False, org_secret)
|
|
45
|
+
|
|
46
|
+
for project_secret in project_scoped:
|
|
47
|
+
if project_secret.name in unique:
|
|
48
|
+
unique[project_secret.name] = (True, project_secret)
|
|
49
|
+
else:
|
|
50
|
+
unique[project_secret.name] = (False, project_secret)
|
|
51
|
+
|
|
52
|
+
sorted_secrets = dict(sorted(unique.items(), key=itemgetter(0)))
|
|
53
|
+
|
|
54
|
+
headers = ["ID", "NAME", "SCOPE", "DIGEST", "CREATED"]
|
|
55
|
+
table = [
|
|
56
|
+
[
|
|
57
|
+
secret.rid,
|
|
58
|
+
secret.name if not overridden else f"{secret.name} (*)",
|
|
59
|
+
"PROJECT" if secret.project else "ORG",
|
|
60
|
+
secret.digest[:16],
|
|
61
|
+
human_readable.date_time(
|
|
62
|
+
datetime.now(timezone.utc) - parser.parse(secret.created_at)
|
|
63
|
+
),
|
|
64
|
+
]
|
|
65
|
+
for (overridden, secret) in sorted_secrets.values()
|
|
66
|
+
]
|
|
67
|
+
typer.echo(tabulate(table, headers=headers, tablefmt="simple"))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@app.command()
|
|
71
|
+
@async_command
|
|
72
|
+
@use_toml_config(default_value="trainwave.toml")
|
|
73
|
+
@ensure_api_key
|
|
74
|
+
async def set(
|
|
75
|
+
organization: Annotated[str, typer.Option(help="The organization ID or RID")],
|
|
76
|
+
secrets: List[str],
|
|
77
|
+
project: Annotated[str | None, typer.Option(help="Project ID or RID")] = None,
|
|
78
|
+
) -> None:
|
|
79
|
+
secret_dict: dict[str, str] = {}
|
|
80
|
+
for secret in secrets:
|
|
81
|
+
splitted = secret.split("=")
|
|
82
|
+
|
|
83
|
+
# Validate format
|
|
84
|
+
if len(splitted) != 2:
|
|
85
|
+
typer.echo(
|
|
86
|
+
f"Error: Invalid format '{secret}'. Expected format is KEY=VALUE.",
|
|
87
|
+
err=True,
|
|
88
|
+
)
|
|
89
|
+
raise typer.Exit(code=1)
|
|
90
|
+
|
|
91
|
+
secret_name, secret_value = splitted
|
|
92
|
+
secret_dict[secret_name] = secret_value
|
|
93
|
+
|
|
94
|
+
# Now call API and insert
|
|
95
|
+
api_client = Api(config.api_key, config.endpoint)
|
|
96
|
+
await api_client.set_secrets(organization, secret_dict, project)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@app.command()
|
|
100
|
+
@async_command
|
|
101
|
+
@use_toml_config(default_value="trainwave.toml")
|
|
102
|
+
@ensure_api_key
|
|
103
|
+
async def unset(
|
|
104
|
+
organization: Annotated[str, typer.Option(help="The organization ID or RID")],
|
|
105
|
+
secrets: List[str],
|
|
106
|
+
) -> None:
|
|
107
|
+
api_client = Api(config.api_key, config.endpoint)
|
|
108
|
+
await api_client.unset_secrets(organization, secrets)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import copy
|
|
2
2
|
import time
|
|
3
3
|
import webbrowser
|
|
4
|
-
from typing import Annotated, Any,
|
|
4
|
+
from typing import Annotated, Any, cast
|
|
5
5
|
|
|
6
6
|
import toml
|
|
7
7
|
import typer
|
|
@@ -67,8 +67,12 @@ async def _run_setup_guide(existing_config: dict[str, Any]) -> dict[str, Any]:
|
|
|
67
67
|
@async_command
|
|
68
68
|
@ensure_api_key
|
|
69
69
|
async def default(
|
|
70
|
-
config: Annotated[
|
|
71
|
-
|
|
70
|
+
config: Annotated[
|
|
71
|
+
str | None, typer.Option(help="Provide a config path")
|
|
72
|
+
] = "trainwave.toml",
|
|
73
|
+
accept: Annotated[
|
|
74
|
+
bool, typer.Option(help="Accept overwrite of config without prompt")
|
|
75
|
+
] = False,
|
|
72
76
|
) -> None:
|
|
73
77
|
"""
|
|
74
78
|
Runs a configuration guide in the browser to create or update a config file.
|
|
@@ -3,12 +3,13 @@ import sys
|
|
|
3
3
|
import typer
|
|
4
4
|
from loguru import logger
|
|
5
5
|
|
|
6
|
-
from trainwave_cli.cli import auth, jobs, setup
|
|
6
|
+
from trainwave_cli.cli import auth, jobs, setup, secrets
|
|
7
7
|
|
|
8
8
|
app = typer.Typer()
|
|
9
9
|
app.add_typer(jobs.app, name="jobs", help="Manage training jobs")
|
|
10
10
|
app.add_typer(auth.app, name="auth", help="Authenticate with Trainwave")
|
|
11
11
|
app.add_typer(setup.app, name="config")
|
|
12
|
+
app.add_typer(secrets.app, name="secrets", help="Manage job secrets")
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
def entrypoint() -> None:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|