Skip to content

Commit

Permalink
various improvements to CM script (check min_cm_version in scripts) a…
Browse files Browse the repository at this point in the history
…nd create-custom-cache-entry
  • Loading branch information
gfursin committed Apr 23, 2024
1 parent 9b83411 commit b838091
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion automation/script/_cm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"alias": "script",
"automation_alias": "automation",
"automation_uid": "bbeb15d8f0a944a4",
"min_cm_version": "2.2.0",
"deps": {
"cache": "cache,541d6f712a6b464e"
},
"desc": "Making native scripts more portable, interoperable and deterministic",
"developers": "[Arjun Suresh](https://www.linkedin.com/in/arjunsuresh), [Grigori Fursin](https://cKnowledge.org/gfursin)",
"developers": "Arjun Suresh and Grigori Fursin",
"actions_with_help":["run", "docker"],
"sort": 1000,
"tags": [
Expand Down
10 changes: 10 additions & 0 deletions automation/script/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from cmind.automation import Automation
from cmind import utils
from cmind import __version__ as current_cm_version

class CAutomation(Automation):
"""
Expand Down Expand Up @@ -727,6 +728,15 @@ def _run(self, i):
meta = script_artifact.meta
path = script_artifact.path

# Check min CM version requirement
min_cm_version = meta.get('min_cm_version','').strip()
if min_cm_version != '':
# Check compare version while avoiding craches for older version
if 'compare_versions' in dir(utils):
comparison = utils.compare_versions(current_cm_version, min_cm_version)
if comparison < 0:
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)}

# Check path to repo
script_repo_path = script_artifact.repo_path

Expand Down
2 changes: 2 additions & 0 deletions cmr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ uid: 9e97bb72b0474657

git: true

version: 2.2.0

deps:
- alias: mlcommons@ck
uid: a4705959af8e447a
Expand Down
1 change: 1 addition & 0 deletions script/create-custom-cache-entry/_cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cache: true

input_mapping:
env_key: CM_CUSTOM_CACHE_ENTRY_ENV_KEY
env_key2: CM_CUSTOM_CACHE_ENTRY_ENV_KEY2
path: CM_CUSTOM_CACHE_ENTRY_PATH
to: CM_CUSTOM_CACHE_ENTRY_PATH

Expand Down
8 changes: 7 additions & 1 deletion script/create-custom-cache-entry/customize.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ def postprocess(i):
x = ''
env_key = env.get('CM_CUSTOM_CACHE_ENTRY_ENV_KEY', '')
if env_key != '': x = env_key+'_'

env['CM_CUSTOM_CACHE_ENTRY_{}PATH'.format(x)] = path
env['CM_CUSTOM_CACHE_ENTRY_PATH'] = path

env_key2 = env.get('CM_CUSTOM_CACHE_ENTRY_ENV_KEY2', '')
v = env.get(env_key2, '')
real_path = v if v != '' else path

env['CM_CUSTOM_CACHE_ENTRY_{}REAL_PATH'.format(x)] = real_path

return {'return': 0}

0 comments on commit b838091

Please sign in to comment.