1414
1515from cmind .automation import Automation
1616from cmind import utils
17+ from cmind import __version__ as current_cm_version
1718
1819class CAutomation (Automation ):
1920 """
@@ -150,6 +151,8 @@ def run(self, i):
150151 inside a script specified by these tags
151152
152153 (debug_script) (bool): if True, debug current script (set debug_script_tags to the tags of a current script)
154+ (debug_uid) (str): if True, set CM_TMP_DEBUG_UID to this number to enable
155+ remote python debugging of scripts and wrapped apps/tools
153156 (detected_versions) (dict): All the used scripts and their detected_versions
154157
155158 (verbose) (bool): if True, prints all tech. info about script execution (False by default)
@@ -180,6 +183,9 @@ def run(self, i):
180183 (skip_sudo) (bool): if True, set env['CM_TMP_SKIP_SUDO']='yes'
181184 to let scripts deal with that
182185
186+ (silent) (bool): if True, attempt to suppress all info if supported
187+ (sets CM_TMP_SILENT=yes)
188+ (s) (bool): the same as 'silent'
183189 ...
184190
185191 Returns:
@@ -309,14 +315,6 @@ def _run(self, i):
309315
310316 print_env = i .get ('print_env' , False )
311317
312- verbose = False
313-
314- if 'verbose' in i : verbose = i ['verbose' ]
315- elif 'v' in i : verbose = i ['v' ]
316-
317- if verbose :
318- env ['CM_VERBOSE' ]= 'yes'
319-
320318 show_time = i .get ('time' , False )
321319 show_space = i .get ('space' , False )
322320
@@ -331,6 +329,10 @@ def _run(self, i):
331329 fake_run = i .get ('fake_run' , False )
332330 fake_run = i .get ('fake_run' , False ) if 'fake_run' in i else i .get ('prepare' , False )
333331 if fake_run : env ['CM_TMP_FAKE_RUN' ]= 'yes'
332+
333+ debug_uid = i .get ('debug_uid' , '' )
334+ if debug_uid != '' :
335+ env ['CM_TMP_DEBUG_UID' ] = debug_uid
334336
335337 fake_deps = i .get ('fake_deps' , False )
336338 if fake_deps : env ['CM_TMP_FAKE_DEPS' ]= 'yes'
@@ -348,6 +350,28 @@ def _run(self, i):
348350 if fake_deps :
349351 run_state ['fake_deps' ] = True
350352
353+ # Check verbose and silent
354+ verbose = False
355+
356+ silent = True if str (i .get ('silent' , '' )).lower () in ['true' , 'yes' , 'on' ] else False
357+
358+ if not silent :
359+ silent = True if str (i .get ('s' , '' )).lower () in ['true' , 'yes' , 'on' ] else False
360+
361+ if silent :
362+ if 'verbose' in i : del (i ['verbose' ])
363+ if 'v' in i : del (i ['v' ])
364+ env ['CM_TMP_SILENT' ]= 'yes'
365+ run_state ['tmp_silent' ]= True
366+
367+ if 'verbose' in i : verbose = i ['verbose' ]
368+ elif 'v' in i : verbose = i ['v' ]
369+
370+ if verbose :
371+ env ['CM_VERBOSE' ]= 'yes'
372+ run_state ['tmp_verbose' ]= True
373+
374+
351375 print_deps = i .get ('print_deps' , False )
352376 print_readme = i .get ('print_readme' , False )
353377
@@ -517,8 +541,9 @@ def _run(self, i):
517541# if verbose:
518542# print ('')
519543
520- print ('' )
521- print (recursion_spaces + '* ' + cm_script_info )
544+ if not run_state .get ('tmp_silent' , False ):
545+ print ('' )
546+ print (recursion_spaces + '* ' + cm_script_info )
522547
523548
524549 #############################################################################
@@ -703,6 +728,15 @@ def _run(self, i):
703728 meta = script_artifact .meta
704729 path = script_artifact .path
705730
731+ # Check min CM version requirement
732+ min_cm_version = meta .get ('min_cm_version' ,'' ).strip ()
733+ if min_cm_version != '' :
734+ # Check compare version while avoiding craches for older version
735+ if 'compare_versions' in dir (utils ):
736+ comparison = utils .compare_versions (current_cm_version , min_cm_version )
737+ if comparison < 0 :
738+ return {'return' :1 , 'error' :'CM script requires CM version >= {} while current CM version is {} - please update using "pip install cmind -U"' .format (min_cm_version , current_cm_version )}
739+
706740 # Check path to repo
707741 script_repo_path = script_artifact .repo_path
708742
@@ -1081,7 +1115,8 @@ def _run(self, i):
10811115 if r ['return' ]> 0 : return r
10821116 version = r ['meta' ].get ('version' )
10831117
1084- print (recursion_spaces + ' ! load {}' .format (path_to_cached_state_file ))
1118+ if not run_state .get ('tmp_silent' , False ):
1119+ print (recursion_spaces + ' ! load {}' .format (path_to_cached_state_file ))
10851120
10861121
10871122 ################################################################################################
@@ -1763,19 +1798,20 @@ def _run(self, i):
17631798 input ('Press Enter to continue ...' )
17641799
17651800 # Check if need to print some final info such as path to model, etc
1766- print_env_at_the_end = meta .get ('print_env_at_the_end' ,{})
1767- if len (print_env_at_the_end )> 0 :
1768- print ('' )
1801+ if not run_state .get ('tmp_silent' , False ):
1802+ print_env_at_the_end = meta .get ('print_env_at_the_end' ,{})
1803+ if len (print_env_at_the_end )> 0 :
1804+ print ('' )
17691805
1770- for p in sorted (print_env_at_the_end ):
1771- t = print_env_at_the_end [p ]
1772- if t == '' : t = 'ENV[{}]' .format (p )
1806+ for p in sorted (print_env_at_the_end ):
1807+ t = print_env_at_the_end [p ]
1808+ if t == '' : t = 'ENV[{}]' .format (p )
17731809
1774- v = new_env .get (p , None )
1810+ v = new_env .get (p , None )
17751811
1776- print ('{}: {}' .format (t , str (v )))
1812+ print ('{}: {}' .format (t , str (v )))
17771813
1778- print ('' )
1814+ print ('' )
17791815
17801816 return rr
17811817
@@ -2887,6 +2923,7 @@ def _run_deps(self, deps, clean_env_keys_deps, env, state, const, const_state, a
28872923
28882924 # Run collective script via CM API:
28892925 # Not very efficient but allows logging - can be optimized later
2926+
28902927 ii = {
28912928 'action' :'run' ,
28922929 'automation' :utils .assemble_cm_object (self .meta ['alias' ], self .meta ['uid' ]),
@@ -2900,6 +2937,7 @@ def _run_deps(self, deps, clean_env_keys_deps, env, state, const, const_state, a
29002937 'add_deps_recursive' :add_deps_recursive ,
29012938 'debug_script_tags' :debug_script_tags ,
29022939 'verbose' :verbose ,
2940+ 'silent' :run_state .get ('tmp_silent' , False ),
29032941 'time' :show_time ,
29042942 'run_state' :run_state
29052943
@@ -4295,8 +4333,9 @@ def prepare_and_run_script_with_postprocessing(i, postprocess="postprocess"):
42954333 print (recursion_spaces + ' - Running native script "{}" from temporal script "{}" in "{}" ...' .format (path_to_run_script , run_script , cur_dir ))
42964334 print ('' )
42974335
4298- print (recursion_spaces + ' ! cd {}' .format (cur_dir ))
4299- print (recursion_spaces + ' ! call {} from {}' .format (path_to_run_script , run_script ))
4336+ if not run_state .get ('tmp_silent' , False ):
4337+ print (recursion_spaces + ' ! cd {}' .format (cur_dir ))
4338+ print (recursion_spaces + ' ! call {} from {}' .format (path_to_run_script , run_script ))
43004339
43014340
43024341 # Prepare env variables
@@ -4388,7 +4427,8 @@ def prepare_and_run_script_with_postprocessing(i, postprocess="postprocess"):
43884427
43894428
43904429 if postprocess != '' and customize_code is not None and postprocess in dir (customize_code ):
4391- print (recursion_spaces + ' ! call "{}" from {}' .format (postprocess , customize_code .__file__ ))
4430+ if not run_state .get ('tmp_silent' , False ):
4431+ print (recursion_spaces + ' ! call "{}" from {}' .format (postprocess , customize_code .__file__ ))
43924432
43934433 if len (posthook_deps )> 0 and (postprocess == "postprocess" ):
43944434 r = script_automation ._call_run_deps (posthook_deps , local_env_keys , local_env_keys_from_meta , env , state , const , const_state ,
0 commit comments