diff --git a/.github/workflows/test-mlc-core-actions.yaml b/.github/workflows/test-mlc-core-actions.yaml index 5fd846dc4..31b7c73e7 100644 --- a/.github/workflows/test-mlc-core-actions.yaml +++ b/.github/workflows/test-mlc-core-actions.yaml @@ -121,6 +121,7 @@ jobs: - name: Test 7 - run script - Output being used for testing mlc cache run: | mlc run script --tags=get,imagenet-aux --quiet + mlc run script bb2c6dd8c8c64217 --quiet mlc run script --tags=get,imagenet-aux,_from.dropbox --quiet - name: Test 8 - find cache - More than one cache present diff --git a/VERSION b/VERSION index af0b7ddbf..b0f3d96f8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.6 +1.0.8 diff --git a/docs/targets/script/native-script.md b/docs/targets/script/native-script.md new file mode 100644 index 000000000..bd4b9c6a0 --- /dev/null +++ b/docs/targets/script/native-script.md @@ -0,0 +1,111 @@ + +## ** Native Script Execution & Automatic Script Selection** + +In MLC script execution, the default native script filename is **`run`**, with the extension **`.sh`** on Unix platforms and **`.bat`** on Windows. Users can customize this by providing a different script name using the `script_name` parameter. + +Once the script name is specified, **MLC automatically selects the most suitable script variant** based on the **OS and platform** where it is being executed. + +### **Behavior** + +The following explanation assumes the **`.sh`** extension for Unix-based systems, but the same logic applies to **`.bat`** files on Windows. + +1. **Checks Available Scripts**: + - If no script in the directory starts with `"script_name-"`, the function **skips unnecessary checks** and returns the default `"script_name.sh"`. + - If matching scripts exist, it proceeds to find the best match. + +2. **Priority Order for Script Selection**: + The function checks for files in the following order: + 1. `{script_name}-{MLC_HOST_OS_FLAVOR}-{MLC_HOST_OS_VERSION}-{MLC_HOST_PLATFORM_FLAVOR}.sh` + 2. `{script_name}-{MLC_HOST_OS_FLAVOR}-{MLC_HOST_OS_VERSION}.sh` + 3. `{script_name}-{MLC_HOST_OS_FLAVOR}-{MLC_HOST_PLATFORM_FLAVOR}.sh` + 4. `{script_name}-{MLC_HOST_OS_FLAVOR}.sh` + 5. `{script_name}-{MLC_HOST_OS_FLAVOR_LIKE}-{MLC_HOST_PLATFORM_FLAVOR}.sh` + 6. `{script_name}-{MLC_HOST_OS_FLAVOR_LIKE}.sh` + 7. `{script_name}-{MLC_HOST_OS_TYPE}-{MLC_HOST_PLATFORM_FLAVOR}.sh` + 8. `{script_name}-{MLC_HOST_OS_TYPE}.sh` + 9. `{script_name}-{MLC_HOST_PLATFORM_FLAVOR}.sh` + 10. `{script_name}.sh` (fallback) + +3. **Returns the First Matching File** + - If a file is found in the given priority order, it returns the full path. + - If no prefixed script exists, it returns `{path}/{script_name}.sh`. + +--- + +### **Example Usage** +#### **Example 1: Finding the Most Specific Script** +📌 **Environment Variables** +```python +env = { + 'MLC_HOST_OS_FLAVOR': 'ubuntu', + 'MLC_HOST_OS_FLAVOR_LIKE': 'debian', + 'MLC_HOST_OS_TYPE': 'linux', + 'MLC_HOST_OS_VERSION': '20.04', + 'MLC_HOST_PLATFORM_FLAVOR': 'x86_64' +} +``` +📂 **Available Files in `/scripts/`** +``` +run-ubuntu-20.04-x86_64.sh +run-ubuntu-20.04.sh +run.sh +``` +🔍 **Function Call** +```python +get_script_name(env, "/scripts") +``` +✅ **Output** +```python +"/scripts/run-ubuntu-20.04-x86_64.sh" +``` +✔ **Explanation**: The function finds `"run-ubuntu-20.04-x86_64.sh"` as it has the highest priority. + +--- + +#### **Example 2: Fallback When Some Variables Are Missing** +📌 **Environment Variables** +```python +env = { + 'MLC_HOST_OS_FLAVOR_LIKE': 'debian', + 'MLC_HOST_OS_TYPE': 'linux', + 'MLC_HOST_PLATFORM_FLAVOR': 'arm64' +} +``` +📂 **Available Files in `/scripts/`** +``` +run-debian-arm64.sh +run.sh +``` +🔍 **Function Call** +```python +get_script_name(env, "/scripts") +``` +✅ **Output** +```python +"/scripts/run-debian-arm64.sh" +``` +✔ **Explanation**: Since `MLC_HOST_OS_FLAVOR` is missing, the function falls back to `MLC_HOST_OS_FLAVOR_LIKE` and selects `"run-debian-arm64.sh"`. + +--- + +#### **Example 3: No Prefixed Scripts Exist** +📌 **Environment Variables** +```python +env = { + 'MLC_HOST_OS_TYPE': 'linux' +} +``` +📂 **Available Files in `/scripts/`** +``` +run.sh +``` +🔍 **Function Call** +```python +get_script_name(env, "/scripts") +``` +✅ **Output** +```python +"/scripts/run.sh" +``` +✔ **Explanation**: Since no prefixed scripts exist, the function returns the default `"run.sh"`. + diff --git a/mlc/main.py b/mlc/main.py index 228e362a8..95e2af53d 100644 --- a/mlc/main.py +++ b/mlc/main.py @@ -47,13 +47,26 @@ def search(self, i): target_index = indices.get(self.automation_type) result = [] if target_index: - tags= i.get("tags") - tags_split = tags.split(",") + tags = i.get("tags") + if tags == '': + tags_split = [] + else: + tags_split = tags.split(",") n_tags = [p for p in tags_split if p.startswith("-")] p_tags = list(set(tags_split) - set(n_tags)) + uid = None + alias = None + if not tags: + if i.get('details'): + item_split = i['details'].split(",") + if len(item_split) > 1: + alias = item_split[0] + uid = item_split[1] + else: + uid = item_split[0] for res in target_index: c_tags = res["tags"] - if set(p_tags).issubset(set(c_tags)) and set(n_tags).isdisjoint(set(c_tags)): + if set(p_tags).issubset(set(c_tags)) and set(n_tags).isdisjoint(set(c_tags)) and (not uid or uid == res['uid']) and (not alias or alias == res['alias']): it = Item(res['path'], res['repo']) result.append(it) #logger.info(result) diff --git a/pyproject.toml b/pyproject.toml index 620d12cbc..feab26f96 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "mlcflow" -version = "1.0.7" +version = "1.0.8" description = "An automation interface for ML applications" authors = [