Skip to content

Commit

Permalink
check "min_cm_version" in CM automations and CM scripts (use _cm.yaml…
Browse files Browse the repository at this point in the history
… or _cm.json)
  • Loading branch information
gfursin committed Apr 23, 2024
1 parent a241eae commit 948358d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
4 changes: 3 additions & 1 deletion cm/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
## V2.1.2.1
## V2.1.3
- fixed detection of a CM artifact using 'cm info .' when inside virtual env entries.
- added "cmind.utils.debug_here" function to attach remote Python debugger
and tested with Visual Studio Code.
- added test to avoid checking out CM repo that was not pulled
- added utils.safe_load_json to return empty dict if file doesn't exist
- added utils.compare_versions to check min version requirements for automations and entries
- removed outdated convert_path (https://github.com/mlcommons/ck/issues/1219)
- added utils.check_if_true_yes_on (https://github.com/mlcommons/ck/issues/1216)
- check "min_cm_version" in CM automations and CM scripts (use _cm.yaml or _cm.json)

## V2.1.2
- added support for deps on other CM repos
Expand Down
2 changes: 1 addition & 1 deletion cm/cmind/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.1.2.1"
__version__ = "2.1.3"

from cmind.core import access
from cmind.core import error
Expand Down
10 changes: 10 additions & 0 deletions cm/cmind/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,16 @@ def access(self, i, out = None):

i['parsed_artifact'] = r['cm_object']

# Check min CM version requirement
min_cm_version = automation_meta.get('min_cm_version','').strip()
if min_cm_version != '':
from cmind import __version__ as current_cm_version
comparison = utils.compare_versions(current_cm_version, min_cm_version)
if comparison < 0:
return {'return':1, 'error':'CM automation requires CM version >= {} while current CM version is {} - please update using "pip install cmind -U"'.format(min_cm_version, current_cm_version)}



# Call automation action
action_addr=getattr(initialized_automation, action)

Expand Down
40 changes: 35 additions & 5 deletions cm/cmind/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def safe_load_json(path, file_name='', encoding='utf8'):

meta = {}

r = load_json(path_to_file, check_if_exists, encoding)
r = load_json(path_to_file, check_if_exists=True, encoding=encoding)
if r['return'] == 0:
meta = r['meta']

Expand Down Expand Up @@ -1726,9 +1726,6 @@ def compare_versions(version1, version2):
-1 - version 1 < version 2
"""

version1 = i['version1']
version2 = i['version2']

l_version1 = version1.split('.')
l_version2 = version2.split('.')

Expand All @@ -1751,4 +1748,37 @@ def compare_versions(version1, version2):
comparison = -1
break

return {'return':0, 'comparison': comparison}
return comparison

##############################################################################
def check_if_true_yes_on(env, key):
"""
Universal check if str(env.get(key, '')).lower() in ['true', 'yes', 'on']:
Args:
env (dict): dictionary
key (str): key
Returns:
True if str(env.get(key, '')).lower() in ['true', 'yes', 'on']:
"""

return str(env.get(key, '')).lower() in ['true', 'yes', 'on']

##############################################################################
def check_if_none_false_no_off(env, key):
"""
Universal check if str(env.get(key, '')).lower() in ['false', 'no', 'off']:
Args:
env (dict): dictionary
key (str): key
Returns:
True if str(env.get(key, '')).lower() in ['false', 'no', 'off']:
"""

return str(env.get(key, '')).lower() in ['none', 'false', 'no', 'off']

0 comments on commit 948358d

Please sign in to comment.