28
28
import simvue as simvue_client
29
29
30
30
import simvue_cli .config
31
- import simvue_cli .run
31
+ import simvue_cli .actions
32
32
import simvue_cli .server
33
33
34
- from simvue_cli .cli .display import create_runs_display , SIMVUE_LOGO
34
+ from simvue_cli .cli .display import create_objects_display , SIMVUE_LOGO
35
35
from simvue_cli .validation import SimvueName , SimvueFolder , JSONType
36
36
37
37
from click_params import PUBLIC_URL
@@ -70,7 +70,7 @@ def ping_server(timeout: int | None) -> None:
70
70
return
71
71
start_time = time .time ()
72
72
try :
73
- server_version : int | str = simvue_cli .run .get_server_version ()
73
+ server_version : int | str = simvue_cli .actions .get_server_version ()
74
74
if (status_code := 200 if isinstance (server_version , str ) else server_version ) != 200 :
75
75
raise RuntimeError
76
76
successful_pings += 1
@@ -92,7 +92,7 @@ def whoami(user: bool, tenant: bool) -> None:
92
92
if user and tenant :
93
93
click .secho ("cannot print 'only' with more than one choice" )
94
94
raise click .Abort
95
- user_info = simvue_cli .run .user_info ()
95
+ user_info = simvue_cli .actions .user_info ()
96
96
user_name = user_info .get ("username" )
97
97
tenant_info = user_info .get ("tenant" )
98
98
if user :
@@ -114,14 +114,16 @@ def about_simvue(ctx) -> None:
114
114
)
115
115
click .echo (f"\n { width * '=' } \n " )
116
116
click .echo (f"\n { '\t ' * int (0.04 * width )} Provided under the Apache-2.0 License" )
117
- click .echo (f"{ '\t ' * int (0.04 * width )} © Copyright { datetime .datetime .today ().strftime ('%Y' )} Simvue Development Team\n " )
117
+ click .echo (
118
+ f"{ '\t ' * int (0.04 * width )} © Copyright { datetime .datetime .now ().strftime ('%Y' )} Simvue Development Team\n "
119
+ )
118
120
out_table : list [list [str ]] = []
119
121
with contextlib .suppress (importlib .metadata .PackageNotFoundError ):
120
122
out_table .append (["CLI Version: " , importlib .metadata .version (simvue_cli .__name__ )])
121
123
with contextlib .suppress (importlib .metadata .PackageNotFoundError ):
122
124
out_table .append (["Python API Version: " , importlib .metadata .version (simvue_client .__name__ )])
123
125
with contextlib .suppress (Exception ):
124
- server_version : int | str = simvue_cli .run .get_server_version ()
126
+ server_version : int | str = simvue_cli .actions .get_server_version ()
125
127
if isinstance (server_version , int ):
126
128
raise RuntimeError
127
129
out_table .append (["Server Version: " , server_version ])
@@ -210,9 +212,9 @@ def create_run(
210
212
) -> None :
211
213
"""Initialise a new Simvue run"""
212
214
run_params |= {"running" : not create_only , "tags" : list (tag ) if tag else None }
213
- run_id : str = simvue_cli .run .create_simvue_run (** run_params )
215
+ run_id : str = simvue_cli .actions .create_simvue_run (** run_params )
214
216
215
- click .echo (click . style ( run_id ) if not ctx .obj ["plain" ] else run_id )
217
+ click .echo (run_id if ctx .obj ["plain" ] else click . style ( run_id ) )
216
218
217
219
218
220
@simvue_run .command ("remove" )
@@ -226,7 +228,7 @@ def delete_run(ctx, run_ids: list[str] | None, interactive: bool) -> None:
226
228
run_ids = run_ids_str .split (" " )
227
229
228
230
for run_id in run_ids :
229
- if not (simvue_cli .run .get_run (run_id )):
231
+ if not (simvue_cli .actions .get_run (run_id )):
230
232
error_msg = f"Run '{ run_id } ' not found"
231
233
if ctx .obj ["plain" ]:
232
234
print (error_msg )
@@ -240,12 +242,10 @@ def delete_run(ctx, run_ids: list[str] | None, interactive: bool) -> None:
240
242
continue
241
243
242
244
try :
243
- simvue_cli .run .delete_run (run_id )
245
+ simvue_cli .actions .delete_run (run_id )
244
246
except ValueError as e :
245
247
click .echo (
246
- click .style (e .args [0 ], fg = "red" , bold = True )
247
- if not ctx .obj ["plain" ]
248
- else e .args [0 ]
248
+ e .args [0 ] if ctx .obj ["plain" ] else click .style (e .args [0 ], fg = "red" , bold = True )
249
249
)
250
250
sys .exit (1 )
251
251
@@ -262,20 +262,18 @@ def delete_run(ctx, run_ids: list[str] | None, interactive: bool) -> None:
262
262
@click .argument ("run_id" , type = str )
263
263
def close_run (ctx , run_id : str ) -> None :
264
264
"""Mark an active run as completed"""
265
- if not (simvue_cli .run .get_run (run_id )):
265
+ if not (simvue_cli .actions .get_run (run_id )):
266
266
error_msg = f"Run '{ run_id } ' not found"
267
267
if ctx .obj ["plain" ]:
268
268
print (error_msg )
269
269
else :
270
270
click .secho (error_msg , fg = "red" , bold = True )
271
271
sys .exit (1 )
272
272
try :
273
- simvue_cli .run .set_run_status (run_id , "completed" )
273
+ simvue_cli .actions .set_run_status (run_id , "completed" )
274
274
except ValueError as e :
275
275
click .echo (
276
- click .style (e .args [0 ], fg = "red" , bold = True )
277
- if not ctx .obj ["plain" ]
278
- else e .args [0 ]
276
+ e .args [0 ] if ctx .obj ["plain" ] else click .style (e .args [0 ], fg = "red" , bold = True )
279
277
)
280
278
sys .exit (1 )
281
279
@@ -292,38 +290,38 @@ def close_run(ctx, run_id: str) -> None:
292
290
)
293
291
def abort_run (ctx , run_id : str , reason : str ) -> None :
294
292
"""Abort an active run"""
295
- if not (simvue_cli .run .get_run (run_id )):
293
+ if not (simvue_cli .actions .get_run (run_id )):
296
294
error_msg = f"Run '{ run_id } ' not found"
297
295
if ctx .obj ["plain" ]:
298
296
print (error_msg )
299
297
else :
300
298
click .secho (error_msg , fg = "red" , bold = True )
301
299
sys .exit (1 )
302
- simvue_cli .run .set_run_status (run_id , "terminated" , reason = reason )
300
+ simvue_cli .actions .set_run_status (run_id , "terminated" , reason = reason )
303
301
304
302
305
303
@simvue_run .command ("log.metrics" )
306
304
@click .argument ("run_id" , type = str )
307
305
@click .argument ("metrics" , type = JSONType )
308
306
def log_metrics (run_id : str , metrics : dict ) -> None :
309
307
"""Log metrics to Simvue server"""
310
- simvue_cli .run .log_metrics (run_id , metrics )
308
+ simvue_cli .actions .log_metrics (run_id , metrics )
311
309
312
310
313
311
@simvue_run .command ("log.event" )
314
312
@click .argument ("run_id" , type = str )
315
313
@click .argument ("event_message" , type = str )
316
314
def log_event (run_id : str , event_message : str ) -> None :
317
315
"""Log event to Simvue server"""
318
- simvue_cli .run .log_event (run_id , event_message )
316
+ simvue_cli .actions .log_event (run_id , event_message )
319
317
320
318
321
319
@simvue_run .command ("metadata" )
322
320
@click .argument ("run_id" , type = str )
323
321
@click .argument ("metadata" , type = JSONType )
324
322
def update_metadata (run_id : str , metadata : dict ) -> None :
325
323
"""Update metadata for a run on the Simvue server"""
326
- simvue_cli .run .update_metadata (run_id , metadata )
324
+ simvue_cli .actions .update_metadata (run_id , metadata )
327
325
328
326
329
327
@simvue_run .command ("list" )
@@ -372,7 +370,7 @@ def list_runs(
372
370
) -> None :
373
371
"""Retrieve runs list from Simvue server"""
374
372
kwargs |= {"filters" : kwargs .get ("filters" or [])}
375
- runs = simvue_cli .run .get_runs_list (** kwargs )
373
+ runs = simvue_cli .actions .get_runs_list (** kwargs )
376
374
columns = ["id" ]
377
375
378
376
if created :
@@ -390,7 +388,7 @@ def list_runs(
390
388
if status :
391
389
columns .append ("status" )
392
390
393
- table = create_runs_display (columns , runs , plain_text = ctx .obj ["plain" ], enumerate_ = enumerate_ , format = format )
391
+ table = create_objects_display (columns , runs , plain_text = ctx .obj ["plain" ], enumerate_ = enumerate_ , format = format )
394
392
click .echo (table )
395
393
396
394
@@ -405,7 +403,7 @@ def get_run_json(run_id: str) -> None:
405
403
run_id = input ()
406
404
407
405
try :
408
- run_info = simvue_cli .run .get_run (run_id )
406
+ run_info = simvue_cli .actions .get_run (run_id )
409
407
except RuntimeError as e :
410
408
error_msg = f"Failed to retrieve run '{ run_id } ': { e .args [0 ]} "
411
409
click .echo (error_msg , fg = "red" , bold = True )
@@ -451,9 +449,9 @@ def simvue_alert(ctx) -> None:
451
449
@click .option ("--email" , is_flag = True , help = "Notify by email if triggered" , show_default = True )
452
450
def create_alert (ctx , name : str , abort : bool = False , email : bool = False ) -> None :
453
451
"""Create a User alert"""
454
- result = simvue_cli .run .create_user_alert (name , abort , email )
452
+ result = simvue_cli .actions .create_user_alert (name , abort , email )
455
453
alert_id = result ["id" ]
456
- click .echo (click . style ( alert_id ) if not ctx .obj ["plain" ] else alert_id )
454
+ click .echo (alert_id if ctx .obj ["plain" ] else click . style ( alert_id ) )
457
455
458
456
459
457
@simvue .command ("monitor" )
@@ -490,7 +488,7 @@ def monitor(ctx, tag: tuple[str, ...] | None, delimiter: str, **run_params) -> N
490
488
metric_labels : list [str ] = []
491
489
run_params |= {"tags" : list (tag ) if tag else None }
492
490
493
- run_id : str | None = simvue_cli .run .create_simvue_run (timeout = None , running = True , ** run_params )
491
+ run_id : str | None = simvue_cli .actions .create_simvue_run (timeout = None , running = True , ** run_params )
494
492
495
493
if not run_id :
496
494
raise click .Abort ("Failed to created run" )
@@ -502,7 +500,7 @@ def monitor(ctx, tag: tuple[str, ...] | None, delimiter: str, **run_params) -> N
502
500
metric_labels = line
503
501
continue
504
502
try :
505
- simvue_cli .run .log_metrics (run_id , dict (zip (metric_labels , [float (i ) for i in line ])))
503
+ simvue_cli .actions .log_metrics (run_id , dict (zip (metric_labels , [float (i ) for i in line ])))
506
504
except (RuntimeError , ValueError ) as e :
507
505
if ctx .obj ["plain" ]:
508
506
click .echo (e )
@@ -511,9 +509,9 @@ def monitor(ctx, tag: tuple[str, ...] | None, delimiter: str, **run_params) -> N
511
509
sys .exit (1 )
512
510
click .echo (run_id )
513
511
except KeyboardInterrupt as e :
514
- simvue_cli .run .set_run_status (run_id , "terminated" )
512
+ simvue_cli .actions .set_run_status (run_id , "terminated" )
515
513
raise click .Abort from e
516
- simvue_cli .run .set_run_status (run_id , "completed" )
514
+ simvue_cli .actions .set_run_status (run_id , "completed" )
517
515
518
516
519
517
@simvue .group ("folder" )
@@ -563,7 +561,7 @@ def folder_list(
563
561
) -> None :
564
562
"""Retrieve folders list from Simvue server"""
565
563
kwargs |= {"filters" : kwargs .get ("filters" or [])}
566
- runs = simvue_cli .run .get_folders_list (** kwargs )
564
+ runs = simvue_cli .actions .get_folders_list (** kwargs )
567
565
if not runs :
568
566
return
569
567
columns = ["id" ]
@@ -578,9 +576,60 @@ def folder_list(
578
576
if description :
579
577
columns .append ("description" )
580
578
581
- table = create_runs_display (columns , runs , plain_text = ctx .obj ["plain" ], enumerate_ = enumerate_ , format = table_format )
579
+ table = create_objects_display (columns , runs , plain_text = ctx .obj ["plain" ], enumerate_ = enumerate_ , format = table_format )
580
+ click .echo (table )
581
+
582
+
583
+ @simvue .group ("tag" )
584
+ @click .pass_context
585
+ def simvue_tag (ctx ) -> None :
586
+ """Create or retrieve Simvue runs"""
587
+ pass
588
+
589
+
590
+ @simvue_tag .command ("list" )
591
+ @click .pass_context
592
+ @click .option (
593
+ "--format" ,
594
+ "table_format" ,
595
+ type = click .Choice (list (tabulate ._table_formats .keys ())),
596
+ help = "Display as table with output format" ,
597
+ default = None ,
598
+ )
599
+ @click .option (
600
+ "--enumerate" ,
601
+ "enumerate_" ,
602
+ is_flag = True ,
603
+ help = "Show counter next to runs" ,
604
+ default = False ,
605
+ show_default = True ,
606
+ )
607
+ @click .option (
608
+ "--count" ,
609
+ type = int ,
610
+ help = "Maximum number of runs to retrieve" ,
611
+ default = 20 ,
612
+ show_default = True ,
613
+ )
614
+ @click .option ("--name" , is_flag = True , help = "Show names" )
615
+ @click .option ("--color" , is_flag = True , help = "Show hex colors" )
616
+ def tag_list (ctx , count : int , enumerate_ : bool , table_format : str | None , name : bool , color : bool , ** kwargs ) -> None :
617
+ tags = simvue_cli .actions .get_tag_list (** kwargs )
618
+ if not tags :
619
+ return
620
+ columns = ["id" ]
621
+
622
+ if name :
623
+ columns .append ("name" )
624
+
625
+ if color :
626
+ columns .append ("colour" )
627
+
628
+
629
+ table = create_objects_display (columns , tags , plain_text = ctx .obj ["plain" ], enumerate_ = enumerate_ , format = table_format )
582
630
click .echo (table )
583
631
584
632
585
633
if __name__ in "__main__" :
586
634
simvue ()
635
+
0 commit comments