trainwave-cli 0.2.1__tar.gz → 0.2.2__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.2.1
3
+ Version: 0.2.2
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.2.1"
3
+ version = "0.2.2"
4
4
  description = ""
5
5
  authors = ["Johan Backman <johan@trainwave.ai>"]
6
6
  readme = "README.md"
@@ -23,7 +23,9 @@ LOGIN_POLLING_SLEEP_TIME: Annotated[int, "seconds"] = 5
23
23
  @async_command
24
24
  async def login() -> None:
25
25
  """
26
- Login to Trainwave. This will open a browser window for you to authenticate.
26
+ Login to Trainwave.
27
+
28
+ This will open a browser window for you to authenticate.
27
29
  """
28
30
  api_client = Api(None, config.endpoint)
29
31
  session_url, session_token = await api_client.create_cli_auth_session()
@@ -72,7 +74,9 @@ async def login() -> None:
72
74
  @ensure_api_key
73
75
  async def logout() -> None:
74
76
  """
75
- Logout from Trainwave. This will remove the API key from the configuration.
77
+ Logout from Trainwave.
78
+
79
+ This will remove the API key from the configuration.
76
80
  """
77
81
  config_manager.delete()
78
82
  logger.info("Logged out")
@@ -82,9 +86,7 @@ async def logout() -> None:
82
86
  @async_command
83
87
  @ensure_api_key
84
88
  async def whoami() -> None:
85
- """
86
- Get the current user's information.
87
- """
89
+ """Get the current user's information."""
88
90
  api = Api(config.api_key, config.endpoint)
89
91
  res = await api.get_myself()
90
92
  typer.echo(res.email)
@@ -93,9 +95,7 @@ async def whoami() -> None:
93
95
  @app.command()
94
96
  @async_command
95
97
  async def set_token(api_key: str):
96
- """
97
- Manually set the API key for Trainwave.
98
- """
98
+ """Manually set the API key for Trainwave."""
99
99
  api = Api(api_key, config.endpoint)
100
100
  logger.info("Checking API key...")
101
101
  if await api.check_api_key():
@@ -111,17 +111,13 @@ async def set_token(api_key: str):
111
111
  @async_command
112
112
  @ensure_api_key
113
113
  async def token() -> None:
114
- """
115
- Print the current API key.
116
- """
114
+ """Print the current API key."""
117
115
  typer.echo(config.api_key)
118
116
 
119
117
 
120
118
  @app.command()
121
119
  @async_command
122
120
  async def set_endpoint(endpoint: str) -> None:
123
- """
124
- Set the endpoint for Trainwave.
125
- """
121
+ """Set the endpoint for Trainwave."""
126
122
  config.endpoint = endpoint
127
123
  config_manager.save()
@@ -78,9 +78,7 @@ async def launch( # noqa
78
78
  bool | None, typer.Option(help="Only use SOC2 compliant machines")
79
79
  ] = None,
80
80
  ) -> None:
81
- """
82
- Launch a job on Trainwave using the current configuration.
83
- """
81
+ """Launch a job on Trainwave using the current configuration."""
84
82
  api_client = Api(config.api_key, config.endpoint, project)
85
83
  # Interpolate environe variables
86
84
  env_vars = eval(env_vars)
@@ -167,9 +165,7 @@ async def list_jobs(
167
165
  organization: Annotated[str, typer.Option(help="Organization ID or RID")],
168
166
  project: Annotated[str, typer.Option(help="Project ID or RID")] = "",
169
167
  ) -> None:
170
- """
171
- List all jobs in the current project.
172
- """
168
+ """List all jobs in the current project."""
173
169
  api_client = Api(
174
170
  config.api_key, config.endpoint, project=project, organization=organization
175
171
  )
@@ -200,9 +196,7 @@ async def status(
200
196
  project: Annotated[str, typer.Option(help="Project ID or RID")],
201
197
  job_id: str,
202
198
  ) -> None:
203
- """
204
- Get the status of a job.
205
- """
199
+ """Get the status of a job."""
206
200
  api_client = Api(config.api_key, config.endpoint, project)
207
201
  typer.echo(await api_client.job_status(job_id))
208
202
 
@@ -215,9 +209,7 @@ async def cancel(
215
209
  project: Annotated[str, typer.Option(help="Project ID or RID")],
216
210
  job_id: str,
217
211
  ):
218
- """
219
- Cancel a job.
220
- """
212
+ """Cancel a job."""
221
213
  api_client = Api(config.api_key, config.endpoint, project)
222
214
  await api_client.cancel_job(job_id)
223
215
  typer.echo(f"Cancelled job: {job_id}")
@@ -229,9 +221,7 @@ async def cancel(
229
221
  async def logs(
230
222
  job_id: str,
231
223
  ) -> None:
232
- """
233
- Get the logs of a job.
234
- """
224
+ """Get the logs of a job."""
235
225
  logger.remove()
236
226
  logger.add(
237
227
  sys.stdout,
@@ -1,21 +1,11 @@
1
- import json
2
- import os
3
- from typing import List
4
- import sys
5
- import traceback
6
- from dataclasses import asdict
1
+ import builtins
7
2
  from datetime import datetime, timezone
8
- from pathlib import Path
3
+ from operator import itemgetter
9
4
  from typing import Annotated
10
- from urllib.parse import urlparse
11
5
 
12
- from operator import itemgetter
13
6
  import human_readable
14
- import pytimeparse
15
7
  import typer
16
- import websockets
17
8
  from dateutil import parser
18
- from loguru import logger
19
9
  from tabulate import tabulate
20
10
  from typer_config.decorators import use_toml_config
21
11
 
@@ -73,15 +63,17 @@ async def list(
73
63
  @ensure_api_key
74
64
  async def set(
75
65
  organization: Annotated[str, typer.Option(help="The organization ID or RID")],
76
- secrets: List[str],
66
+ secrets: builtins.list[str],
77
67
  project: Annotated[str | None, typer.Option(help="Project ID or RID")] = None,
78
68
  ) -> None:
79
69
  secret_dict: dict[str, str] = {}
70
+
80
71
  for secret in secrets:
72
+ _KV_PARTS = 2
81
73
  splitted = secret.split("=")
82
74
 
83
75
  # Validate format
84
- if len(splitted) != 2:
76
+ if len(splitted) != _KV_PARTS:
85
77
  typer.echo(
86
78
  f"Error: Invalid format '{secret}'. Expected format is KEY=VALUE.",
87
79
  err=True,
@@ -102,7 +94,7 @@ async def set(
102
94
  @ensure_api_key
103
95
  async def unset(
104
96
  organization: Annotated[str, typer.Option(help="The organization ID or RID")],
105
- secrets: List[str],
97
+ secrets: builtins.list[str],
106
98
  ) -> None:
107
99
  api_client = Api(config.api_key, config.endpoint)
108
100
  await api_client.unset_secrets(organization, secrets)
@@ -75,7 +75,7 @@ async def default(
75
75
  ] = False,
76
76
  ) -> None:
77
77
  """
78
- Runs a configuration guide in the browser to create or update a config file.
78
+ Run a configuration guide in the browser to create or update a config file.
79
79
 
80
80
  If a config file already exists, it will be merged with the new config. Otherwise, a
81
81
  new one will be created. The config file will be saved to the provided path.
@@ -0,0 +1,79 @@
1
+ import inspect
2
+ import sys
3
+
4
+ import typer
5
+ from loguru import logger
6
+
7
+ from trainwave_cli.cli import auth, jobs, secrets, setup
8
+
9
+ app = typer.Typer()
10
+ app.add_typer(jobs.app, name="jobs", help="Manage training jobs")
11
+ app.add_typer(auth.app, name="auth", help="Authenticate with Trainwave")
12
+ app.add_typer(setup.app, name="config")
13
+ app.add_typer(secrets.app, name="secrets", help="Manage job secrets")
14
+
15
+
16
+ def get_package_name() -> str:
17
+ frame = inspect.currentframe()
18
+ f_back = frame.f_back if frame is not None else None
19
+ f_globals = f_back.f_globals if f_back is not None else None
20
+ # break reference cycle
21
+ # https://docs.python.org/3/library/inspect.html#the-interpreter-stack
22
+ del frame
23
+
24
+ package_name: str | None = None
25
+ if f_globals is not None:
26
+ package_name = f_globals.get("__name__")
27
+
28
+ if package_name == "__main__":
29
+ package_name = f_globals.get("__package__")
30
+
31
+ if package_name:
32
+ package_name = package_name.partition(".")[0]
33
+
34
+ if package_name is None:
35
+ raise RuntimeError("Could not determine the package name automatically.")
36
+
37
+ return package_name
38
+
39
+
40
+ def get_version(*, package_name: str) -> str:
41
+ import importlib.metadata
42
+
43
+ version: str | None = None
44
+ try:
45
+ version = importlib.metadata.version(package_name)
46
+ except importlib.metadata.PackageNotFoundError:
47
+ raise RuntimeError(f"{package_name!r} is not installed.") from None
48
+
49
+ if version is None:
50
+ raise RuntimeError(
51
+ f"Could not determine the version for {package_name!r} automatically."
52
+ )
53
+
54
+ return version
55
+
56
+
57
+ def version_callback(*, value: bool):
58
+ if value:
59
+ package_name = get_package_name()
60
+ version = get_version(package_name=package_name)
61
+ typer.echo(f"{package_name}, {version}")
62
+ raise typer.Exit()
63
+
64
+
65
+ @app.callback()
66
+ def callback(
67
+ version: bool = typer.Option(None, callback=version_callback, is_eager=True),
68
+ ) -> None:
69
+ pass
70
+
71
+
72
+ def entrypoint() -> None:
73
+ logger.remove()
74
+ logger.add(sys.stdout, colorize=True, format="<level>{message}</level>")
75
+ app()
76
+
77
+
78
+ if __name__ == "__main__":
79
+ app()
@@ -1,22 +0,0 @@
1
- import sys
2
-
3
- import typer
4
- from loguru import logger
5
-
6
- from trainwave_cli.cli import auth, jobs, setup, secrets
7
-
8
- app = typer.Typer()
9
- app.add_typer(jobs.app, name="jobs", help="Manage training jobs")
10
- app.add_typer(auth.app, name="auth", help="Authenticate with Trainwave")
11
- app.add_typer(setup.app, name="config")
12
- app.add_typer(secrets.app, name="secrets", help="Manage job secrets")
13
-
14
-
15
- def entrypoint() -> None:
16
- logger.remove()
17
- logger.add(sys.stdout, colorize=True, format="<level>{message}</level>")
18
- app()
19
-
20
-
21
- if __name__ == "__main__":
22
- app()
File without changes