trainwave-cli 0.1.7__tar.gz → 0.1.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trainwave-cli
3
- Version: 0.1.7
3
+ Version: 0.1.9
4
4
  Summary:
5
5
  Author: Johan Backman
6
6
  Author-email: johan@trainwave.ai
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "trainwave-cli"
3
- version = "0.1.7"
3
+ version = "0.1.9"
4
4
  description = ""
5
5
  authors = ["Johan Backman <johan@trainwave.ai>"]
6
6
  readme = "README.md"
@@ -22,6 +22,9 @@ LOGIN_POLLING_SLEEP_TIME: Annotated[int, "seconds"] = 5
22
22
  @app.command()
23
23
  @async_command
24
24
  async def login() -> None:
25
+ """
26
+ Login to Trainwave. This will open a browser window for you to authenticate.
27
+ """
25
28
  api_client = Api(None, config.endpoint)
26
29
  session_url, session_token = await api_client.create_cli_auth_session()
27
30
 
@@ -68,6 +71,9 @@ async def login() -> None:
68
71
  @async_command
69
72
  @ensure_api_key
70
73
  async def logout() -> None:
74
+ """
75
+ Logout from Trainwave. This will remove the API key from the configuration.
76
+ """
71
77
  config_manager.delete()
72
78
  logger.info("Logged out")
73
79
 
@@ -76,6 +82,9 @@ async def logout() -> None:
76
82
  @async_command
77
83
  @ensure_api_key
78
84
  async def whoami() -> None:
85
+ """
86
+ Get the current user's information.
87
+ """
79
88
  api = Api(config.api_key, config.endpoint)
80
89
  res = await api.get_myself()
81
90
  typer.echo(res.email)
@@ -84,6 +93,9 @@ async def whoami() -> None:
84
93
  @app.command()
85
94
  @async_command
86
95
  async def set_token(api_key: str):
96
+ """
97
+ Manually set the API key for Trainwave.
98
+ """
87
99
  api = Api(api_key, config.endpoint)
88
100
  logger.info("Checking API key...")
89
101
  if await api.check_api_key():
@@ -99,11 +111,17 @@ async def set_token(api_key: str):
99
111
  @async_command
100
112
  @ensure_api_key
101
113
  async def token() -> None:
114
+ """
115
+ Print the current API key.
116
+ """
102
117
  typer.echo(config.api_key)
103
118
 
104
119
 
105
120
  @app.command()
106
121
  @async_command
107
122
  async def set_endpoint(endpoint: str) -> None:
123
+ """
124
+ Set the endpoint for Trainwave.
125
+ """
108
126
  config.endpoint = endpoint
109
127
  config_manager.save()
@@ -2,6 +2,7 @@ import json
2
2
  import os
3
3
  import sys
4
4
  import traceback
5
+ from typing import Optional
5
6
  from dataclasses import asdict
6
7
  from datetime import datetime, timezone
7
8
  from pathlib import Path
@@ -32,25 +33,28 @@ app = typer.Typer()
32
33
  @ensure_api_key
33
34
  async def launch( # noqa
34
35
  # Basic job parameters
35
- name: Annotated[str, typer.Option()],
36
- project: Annotated[str, typer.Option()],
37
- setup_command: Annotated[str, typer.Option()],
38
- run_command: Annotated[str, typer.Option()],
36
+ name: Annotated[str, typer.Option(help="The name of the job")],
37
+ project: Annotated[str, typer.Option(help="The project ID or RID")],
38
+ setup_command: Annotated[str, typer.Option(help="The command to run before the job")],
39
+ run_command: Annotated[str, typer.Option(help="The command to run the job")],
39
40
  # Optional params
40
- organization: Annotated[str, typer.Option()] | None = None,
41
- expires: Annotated[str, typer.Option()] = "",
41
+ organization: Annotated[Optional[str], typer.Option(help="ID or RID of organization")] = None,
42
+ expires: Annotated[str, typer.Option(help="Time til' the job will be automatically terminated. Example `1d`, `2h`` etc.")] = "",
42
43
  env_vars={}, # dict[str, str] not supported by typer yet
43
- exclude_gitignore: Annotated[bool, typer.Option()] = True,
44
- exclude_regex: Annotated[str, typer.Option()] | None = None,
44
+ exclude_gitignore: Annotated[bool, typer.Option(help="If set the gitignore file will be used to ignore files when packaging the job")] = True,
45
+ exclude_regex: Annotated[Optional[str], typer.Option(help="Files matching this pattern will be ignored when packaging up the job")] = None,
45
46
  # Harware parameters
46
- image: Annotated[str, typer.Option()] = "",
47
- hdd_size_mb: Annotated[int, typer.Option()] = 20,
48
- memory_mb: Annotated[int, typer.Option()] = 0,
49
- cpus: Annotated[int, typer.Option()] = 0,
50
- gpus: Annotated[int, typer.Option()] = 0,
51
- gpu_type: Annotated[str, typer.Option()] = "",
52
- compliance_soc2: Annotated[bool, typer.Option()] | None = None,
47
+ image: Annotated[str, typer.Option(help="The docker image to use as base for the job")] = "",
48
+ hdd_size_mb: Annotated[int, typer.Option(help="Hard drive size in MB")] = 20,
49
+ memory_mb: Annotated[int, typer.Option(help="Memory in MB")] = 0,
50
+ cpus: Annotated[int, typer.Option(help="Number of CPUs")] = 0,
51
+ gpus: Annotated[int, typer.Option(help="Number of GPUs to allocate of the `gpu_type`")] = 0,
52
+ gpu_type: Annotated[str, typer.Option(help="Canonical name of the GPU to use")] = "",
53
+ compliance_soc2: Annotated[Optional[bool], typer.Option(help="Only use SOC2 compliant machines")] = None,
53
54
  ) -> None:
55
+ """
56
+ Launch a job on Trainwave using the current configuration.
57
+ """
54
58
  api_client = Api(config.api_key, config.endpoint, project)
55
59
  # Interpolate environe variables
56
60
  env_vars = eval(env_vars)
@@ -102,8 +106,8 @@ async def launch( # noqa
102
106
  "name": tab_keys,
103
107
  "value": [render(k, conf[k]) for k in tab_keys],
104
108
  }
105
- logger.info(tabulate(tab_values, headers="keys"))
106
- logger.info("\n")
109
+ typer.echo(tabulate(tab_values, headers="keys"))
110
+ typer.echo("\n")
107
111
 
108
112
  tarball = None
109
113
  try:
@@ -118,9 +122,9 @@ async def launch( # noqa
118
122
  "name": tab_keys,
119
123
  "value": [truncate_string(str(co[k]), 50) for k in tab_keys],
120
124
  }
121
- logger.info("\nMatched machine\n" + tabulate(tab_values, headers="keys") + "\n")
122
- logger.info(f"Cost per hour for this job: ${job.cost_per_hour:.2f}")
123
- logger.info(f"Job created: {job.rid} ({job.id}) -> {job.url}")
125
+ typer.echo("\nMatched machine\n" + tabulate(tab_values, headers="keys") + "\n")
126
+ typer.echo(f"Cost per hour for this job: ${job.cost_per_hour:.2f}")
127
+ typer.echo(f"Job created: {job.rid} ({job.id}) -> {job.url}")
124
128
  except Exception as e:
125
129
  traceback.print_exc()
126
130
  logger.error(f"An error occurred: {e}")
@@ -134,9 +138,12 @@ async def launch( # noqa
134
138
  @use_toml_config(default_value="trainwave.toml")
135
139
  @ensure_api_key
136
140
  async def list_jobs(
137
- organization: Annotated[str, typer.Option()],
138
- project: Annotated[str, typer.Option()] = "",
141
+ organization: Annotated[str, typer.Option(help="Organization ID or RID")],
142
+ project: Annotated[str, typer.Option(help="Project ID or RID")] = "",
139
143
  ) -> None:
144
+ """
145
+ List all jobs in the current project.
146
+ """
140
147
  api_client = Api(
141
148
  config.api_key, config.endpoint, project=project, organization=organization
142
149
  )
@@ -164,11 +171,14 @@ async def list_jobs(
164
171
  @use_toml_config(default_value="trainwave.toml")
165
172
  @ensure_api_key
166
173
  async def status(
167
- project: Annotated[str, typer.Option()],
174
+ project: Annotated[str, typer.Option(help="Project ID or RID")],
168
175
  job_id: str,
169
176
  ) -> None:
177
+ """
178
+ Get the status of a job.
179
+ """
170
180
  api_client = Api(config.api_key, config.endpoint, project)
171
- logger.info(await api_client.job_status(job_id))
181
+ typer.echo(await api_client.job_status(job_id))
172
182
 
173
183
 
174
184
  @app.command()
@@ -176,12 +186,15 @@ async def status(
176
186
  @use_toml_config(default_value="trainwave.toml")
177
187
  @ensure_api_key
178
188
  async def cancel(
179
- project: Annotated[str, typer.Option()],
189
+ project: Annotated[str, typer.Option(help="Project ID or RID")],
180
190
  job_id: str,
181
191
  ):
192
+ """
193
+ Cancel a job.
194
+ """
182
195
  api_client = Api(config.api_key, config.endpoint, project)
183
196
  await api_client.cancel_job(job_id)
184
- logger.info(f"Cancelled job: {job_id}")
197
+ typer.echo(f"Cancelled job: {job_id}")
185
198
 
186
199
 
187
200
  @app.command()
@@ -190,6 +203,9 @@ async def cancel(
190
203
  async def logs(
191
204
  job_id: str,
192
205
  ) -> None:
206
+ """
207
+ Get the logs of a job.
208
+ """
193
209
  logger.remove()
194
210
  logger.add(
195
211
  sys.stdout,
@@ -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, Optional, cast
5
5
 
6
6
  import toml
7
7
  import typer
@@ -60,13 +60,20 @@ async def _run_setup_guide(existing_config: dict[str, Any]) -> dict[str, Any]:
60
60
  @async_command
61
61
  @ensure_api_key
62
62
  async def default(
63
- config: Annotated[str | None, typer.Argument()] = None,
64
- accept: Annotated[bool, "Accept overwrite of config"] = False,
63
+ config: Annotated[Optional[str], typer.Option(help="Provide a config path")] = "trainwave.toml",
64
+ accept: Annotated[bool, typer.Option(help="Accept overwrite of config without prompt")] = False,
65
65
  ) -> None:
66
- config_path = "trainwave.toml"
67
- if config:
68
- config_path = config
66
+ """
67
+ Runs a configuration guide in the browser to create or update a config file.
69
68
 
69
+ If a config file already exists, it will be merged with the new config. Otherwise, a
70
+ new one will be created. The config file will be saved to the provided path.
71
+
72
+ If no path is provided, the default path is `trainwave.toml`.
73
+
74
+ You can run this command over-and-over to re-configure the config before launching a job.
75
+ """
76
+ config_path = cast(str, config)
70
77
  try:
71
78
  existing_config = toml_loader(config_path)
72
79
  except FileNotFoundError:
File without changes