diff --git a/cm/CHANGES.md b/cm/CHANGES.md index 6979a6a56..6937b477c 100644 --- a/cm/CHANGES.md +++ b/cm/CHANGES.md @@ -1,3 +1,8 @@ +## V3.0.3 + - added -raise for https://github.com/mlcommons/ck/issues/1309 + - added --extra_cmd_git and --extra_cmd_pip to cm/cmx pull repo + https://github.com/mlcommons/ck/issues/1308 + ## V3.0.2 - fixed cmx init diff --git a/cm/cmind/__init__.py b/cm/cmind/__init__.py index 4aaa743ea..a217b2d0e 100644 --- a/cm/cmind/__init__.py +++ b/cm/cmind/__init__.py @@ -2,7 +2,7 @@ # # Written by Grigori Fursin -__version__ = "3.0.2" +__version__ = "3.0.3" from cmind.core import access from cmind.core import x diff --git a/cm/cmind/core.py b/cm/cmind/core.py index d4831d5ac..7dfb30fa8 100644 --- a/cm/cmind/core.py +++ b/cm/cmind/core.py @@ -657,7 +657,7 @@ def x(self, i, out = None): * Output from a CM automation action """ - # Check if first access call + # Check if very first access call x_was_called = self.x_was_called self.x_was_called = True @@ -699,6 +699,36 @@ def x(self, i, out = None): if 'out' not in control and out is not None: control['out'] = out + use_raise = control.get('raise', False) + + # Call access helper + r = self._x(i, control) + + if not x_was_called: + # Very first call (not recursive) + # Check if output to json and save file + + if self.output == 'json': + utils.dump_safe_json(r) + + # Check if save to json + if control.get('save_to_json_file', '') != '': + utils.save_json(control['save_to_json_file'], meta = r) + + if control.get('save_to_yaml_file', '') != '': + utils.save_yaml(control['save_to_yaml_file'], meta = r) + + if use_raise and r['return']>0: + raise Exception(r['error']) + + return r + + ############################################################ + def _x(self, i, control): + """ + CMX access helper + """ + output = control.get('out', '') # Check and force json console output @@ -1122,20 +1152,6 @@ def x(self, i, out = None): print (delayed_help_api_prefix) print ('') print (delayed_help_api) - - if not x_was_called: - # Very first call (not recursive) - # Check if output to json and save file - - if self.output == 'json': - utils.dump_safe_json(r) - - # Check if save to json - if control.get('save_to_json_file', '') != '': - utils.save_json(control['save_to_json_file'], meta = r) - - if control.get('save_to_yaml_file', '') != '': - utils.save_yaml(control['save_to_yaml_file'], meta = r) return r diff --git a/cm/cmind/repo/automation/repo/module.py b/cm/cmind/repo/automation/repo/module.py index 494eb2e5e..48c4bec5e 100644 --- a/cm/cmind/repo/automation/repo/module.py +++ b/cm/cmind/repo/automation/repo/module.py @@ -38,6 +38,9 @@ def pull(self, i): (prefix) (str): extra directory to keep CM artifacts (skip_zip_parent_dir) (bool): skip parent dir in CM ZIP repo (useful when downloading CM repo archives from GitHub) + (extra_cmd_git) (str): add this string to git clone + (extra_cmd_pip) (str): add this string to pip install when installing + requirements from CM repositories Returns: (CM return dict): @@ -56,6 +59,9 @@ def pull(self, i): prefix = i.get('prefix','') pat = i.get('pat','') + extra_cmd_git = i.get('extra_cmd_git', '') + extra_cmd_pip = i.get('extra_cmd_pip', '') + checkout_only = i.get('checkout_only', False) skip_zip_parent_dir = i.get('skip_zip_parent_dir', False) @@ -181,7 +187,9 @@ def pull(self, i): depth=depth, path_to_repo=path_to_repo, checkout_only=checkout_only, - skip_zip_parent_dir=skip_zip_parent_dir) + skip_zip_parent_dir=skip_zip_parent_dir, + extra_cmd_git = extra_cmd_git, + extra_cmd_pip = extra_cmd_pip) if r['return']>0: return r repo_meta = r['meta'] diff --git a/cm/cmind/repos.py b/cm/cmind/repos.py index 4300f5f6f..dd6c95aab 100644 --- a/cm/cmind/repos.py +++ b/cm/cmind/repos.py @@ -293,7 +293,8 @@ def process(self, repo_path, mode='add'): ############################################################ def pull(self, alias, url = '', branch = '', checkout = '', console = False, desc = '', prefix = '', depth = None, - path_to_repo = None, checkout_only = False, skip_zip_parent_dir = False): + path_to_repo = None, checkout_only = False, skip_zip_parent_dir = False, + extra_cmd_git = '', extra_cmd_pip = ''): """ Clone or pull CM repository @@ -311,6 +312,9 @@ def pull(self, alias, url = '', branch = '', checkout = '', console = False, des (checkout_only) (bool): only checkout Git repository but don't pull (skip_zip_parent_dir) (bool): skip parent dir in CM ZIP repo (useful when downloading CM repo archives from GitHub) + (extra_cmd_git) (str): add this string to git clone + (extra_cmd_pip) (str): add this string to pip install when installing + requirements from CM repositories Returns: (CM return dict): @@ -384,11 +388,14 @@ def pull(self, alias, url = '', branch = '', checkout = '', console = False, des os.chdir(self.full_path_to_repos) - cmd = 'git clone '+url+' '+alias + cmd = 'git clone ' + url + ' ' + alias # Check if depth is set - if depth!=None and depth!='': - cmd+=' --depth '+str(depth) + if depth != None and depth != '': + cmd += ' --depth ' + str(depth) + + if extra_cmd_git !='' : + cmd +=' ' + extra_cmd_git if console: print (cmd) @@ -565,6 +572,9 @@ def pull(self, alias, url = '', branch = '', checkout = '', console = False, des cmd = python_exec + ' -m pip install -r requirements.txt' + if extra_cmd_pip !='' : + cmd +=' ' + extra_cmd_pip + if console: print ('') print (cmd) diff --git a/cm/debugx.py b/cm/debugx.py new file mode 100644 index 000000000..a4b117f21 --- /dev/null +++ b/cm/debugx.py @@ -0,0 +1,3 @@ +import cmind +r = cmind.x({'action':'wrong-action', 'automation':'core', 'control':{'raise':True}}) +print (r)