From b8380915163dc4efd7e9aec82f9c6eaefed67358 Mon Sep 17 00:00:00 2001 From: Grigori Fursin Date: Tue, 23 Apr 2024 20:10:01 +0200 Subject: [PATCH] various improvements to CM script (check min_cm_version in scripts) and create-custom-cache-entry --- automation/script/_cm.json | 3 ++- automation/script/module.py | 10 ++++++++++ cmr.yaml | 2 ++ script/create-custom-cache-entry/_cm.yaml | 1 + script/create-custom-cache-entry/customize.py | 8 +++++++- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/automation/script/_cm.json b/automation/script/_cm.json index 140662bfa1..d1b8275262 100644 --- a/automation/script/_cm.json +++ b/automation/script/_cm.json @@ -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": [ diff --git a/automation/script/module.py b/automation/script/module.py index 86cbdfcaad..44286bbe44 100644 --- a/automation/script/module.py +++ b/automation/script/module.py @@ -14,6 +14,7 @@ from cmind.automation import Automation from cmind import utils +from cmind import __version__ as current_cm_version class CAutomation(Automation): """ @@ -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 diff --git a/cmr.yaml b/cmr.yaml index c22c97047c..9765b5f423 100644 --- a/cmr.yaml +++ b/cmr.yaml @@ -3,6 +3,8 @@ uid: 9e97bb72b0474657 git: true +version: 2.2.0 + deps: - alias: mlcommons@ck uid: a4705959af8e447a diff --git a/script/create-custom-cache-entry/_cm.yaml b/script/create-custom-cache-entry/_cm.yaml index bdd20f39ca..7272bb99af 100644 --- a/script/create-custom-cache-entry/_cm.yaml +++ b/script/create-custom-cache-entry/_cm.yaml @@ -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 diff --git a/script/create-custom-cache-entry/customize.py b/script/create-custom-cache-entry/customize.py index 785081038d..8d2d31db32 100644 --- a/script/create-custom-cache-entry/customize.py +++ b/script/create-custom-cache-entry/customize.py @@ -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}