@@ -38,21 +38,31 @@ def optional_windows_and_pane(
38
38
if isinstance (if_cond , (str , bool )):
39
39
# treat this as shell variable
40
40
if_cond = {"shell_var" : if_cond }
41
- if not isinstance (if_cond , dict ) or not any (predicate in if_cond for predicate in ("python" , "shell" , "shell_var" )):
42
- raise ValueError (f"if conditions does not contains valid expression: { if_cond } " )
41
+ if not isinstance (if_cond , dict ) or not any (
42
+ predicate in if_cond for predicate in ("python" , "shell" , "shell_var" )
43
+ ):
44
+ msg = f"if conditions does not contains valid expression: { if_cond } "
45
+ raise ValueError (msg )
43
46
if "shell_var" in if_cond :
44
- if expandshell (str (if_cond ["shell_var" ])).lower () not in ("y" , "yes" , "1" , "on" , "true" , "t" ):
47
+ if expandshell (str (if_cond ["shell_var" ])).lower () not in {
48
+ "y" ,
49
+ "yes" ,
50
+ "1" ,
51
+ "on" ,
52
+ "true" ,
53
+ "t" ,
54
+ }:
45
55
return False
46
56
if "shell" in if_cond :
47
- if subprocess .run (if_cond ["shell" ], shell = True ).returncode != 0 :
57
+ if subprocess .run (if_cond ["shell" ], shell = True , check = False ).returncode != 0 :
48
58
return False
49
59
if "python" in if_cond :
50
60
# assign the result of the last statement from the python snippet
51
61
py_statements = if_cond ["python" ].split (";" )
52
62
py_statements [- 1 ] = f"ret={ py_statements [- 1 ]} "
53
63
locals = {}
54
64
exec (";" .join (py_statements ), {}, locals )
55
- if not locals [' ret' ]:
65
+ if not locals [" ret" ]:
56
66
return False
57
67
return True
58
68
@@ -224,7 +234,7 @@ def expand(
224
234
if "windows" in workspace_dict :
225
235
window_dicts = workspace_dict ["windows" ]
226
236
window_dicts = filter (optional_windows_and_pane , window_dicts )
227
- window_dicts = map ( lambda x : expand (x , parent = workspace_dict ), window_dicts )
237
+ window_dicts = ( expand (x , parent = workspace_dict ) for x in window_dicts )
228
238
# remove windows that has no panels (e.g. due to if conditions)
229
239
window_dicts = filter (lambda x : len (x ["panes" ]), window_dicts )
230
240
workspace_dict ["windows" ] = list (window_dicts )
@@ -235,7 +245,7 @@ def expand(
235
245
pane_dicts [pane_idx ] = {}
236
246
pane_dicts [pane_idx ].update (expand_cmd (pane_dict ))
237
247
pane_dicts = filter (optional_windows_and_pane , pane_dicts )
238
- pane_dicts = map ( lambda x : expand (x , parent = workspace_dict ), pane_dicts )
248
+ pane_dicts = ( expand (x , parent = workspace_dict ) for x in pane_dicts )
239
249
workspace_dict ["panes" ] = list (pane_dicts )
240
250
241
251
return workspace_dict
0 commit comments