Skip to content
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
1 change: 1 addition & 0 deletions .github/workflows/test-mlc-core-actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.6
1.0.8
111 changes: 111 additions & 0 deletions docs/targets/script/native-script.md
Original file line number Diff line number Diff line change
@@ -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"`.

19 changes: 16 additions & 3 deletions mlc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
Loading