8
8
9
9
10
10
@click .group ()
11
- def cli ():
11
+ def cli (): # pragma: no cover
12
12
pass
13
13
14
14
@@ -17,7 +17,9 @@ def cli():
17
17
@click .argument ('dox_fn' )
18
18
@click .option ('--skip-existing/--no-skip-existing' , default = True )
19
19
@click .option ('--catch/--no-catch' , default = True )
20
- def run (dox_fn , skip_existing , catch ):
20
+ @click .option ('--clean-failed/--no-clean-failed' , default = False )
21
+ @click .option ('--yes' , '-y' , is_flag = True )
22
+ def run (dox_fn , skip_existing , catch , clean_failed , yes ):
21
23
click .echo ('Running {}...' .format (dox_fn ))
22
24
23
25
wdir = os .path .splitext (dox_fn )[0 ]
@@ -29,36 +31,62 @@ def run(dox_fn, skip_existing, catch):
29
31
}
30
32
31
33
with push_context (Context (wdir , config )) as ctx :
34
+ if clean_failed :
35
+ selected = {trial_id : trial for trial_id ,
36
+ trial in ctx .store .items () if trial .is_failed }
37
+
38
+ click .echo (
39
+ "The following {} trials will be deleted:" .format (len (selected )))
40
+ list_trials (selected )
41
+ if yes or click .confirm ('Continue?' ):
42
+ ctx .store .delete_all (selected .keys ())
43
+
32
44
load_dox (dox_fn )
33
45
ctx .run ()
34
46
35
47
36
48
@cli .command ()
37
49
@click .argument ('dox_fn' )
38
50
@click .argument ('experiment_id' , default = None , required = False )
39
- @click .option ('--failed' , is_flag = True )
40
51
@click .option ('--all' , is_flag = True )
41
- @click .option ('--dry-run' , '-n' , is_flag = True )
42
- def clean (dox_fn , experiment_id = None , failed = True , all = False , empty = False , successful = False , dry_run = False ):
43
- click .echo ('Cleaning failed results from {}...' .format (dox_fn ))
52
+ @click .option ('--yes' , '-y' , is_flag = True )
53
+ def clean (dox_fn , experiment_id , all , yes ):
54
+ """Clean failed experiments."""
55
+ click .echo ('Cleaning results from {}...' .format (dox_fn ))
56
+
57
+ wdir = os .path .splitext (dox_fn )[0 ]
58
+ with push_context (Context (wdir )) as ctx :
59
+ selected = {trial_id : trial for trial_id ,
60
+ trial in ctx .store .items () if trial .is_failed or all }
61
+
62
+ click .echo (
63
+ "The following {} trials will be deleted:" .format (len (selected )))
64
+ list_trials (selected )
65
+
66
+ if yes or click .confirm ('Continue?' ):
67
+ ctx .store .delete_all (selected .keys ())
44
68
45
- if all :
46
- click .confirm ('Do you really want to permanently delete all results of {}?' .format (
47
- dox_fn ), abort = True )
48
69
49
- failed = failed or all
50
- empty = empty or all
51
- successful = successful or all
70
+ def list_trials (trials ):
71
+ """Show a sorted list of trials with a status signifier.
52
72
53
- if not any ((failed , empty , successful )):
54
- print ("Nothing to do. Did you mean --failed?" )
55
- return
73
+ ! Failed
74
+ """
75
+ for trial_id , trial in sorted (trials .items ()):
76
+ status = "!" if trial .is_failed else " "
77
+
78
+ print ("{} {}" .format (status , trial_id ))
79
+
80
+
81
+ @cli .command ()
82
+ @click .argument ('dox_fn' )
83
+ @click .argument ('experiment_id' , default = None , required = False )
84
+ def show (dox_fn , experiment_id = None ):
85
+ """List the trials of this DOX."""
56
86
57
87
wdir = os .path .splitext (dox_fn )[0 ]
58
88
with push_context (Context (wdir )) as ctx :
59
- load_dox (dox_fn )
60
- ctx .clean (failed = failed , dry_run = dry_run ,
61
- experiment_id = experiment_id )
89
+ list_trials (ctx .store )
62
90
63
91
64
92
@cli .command ()
0 commit comments