Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3.0.3: several improvements #1310

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cm/CHANGES.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion cm/cmind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 31 additions & 15 deletions cm/cmind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion cm/cmind/repo/automation/repo/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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']
Expand Down
18 changes: 14 additions & 4 deletions cm/cmind/repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cm/debugx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import cmind
r = cmind.x({'action':'wrong-action', 'automation':'core', 'control':{'raise':True}})
print (r)
Loading