Skip to content

Commit b4e0feb

Browse files
authored
Merge pull request #60 from GATEOverflow/dev
Merge from GO
2 parents 0515895 + 9eb7a03 commit b4e0feb

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

mlc/main.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def is_curdir_inside_path(base_path):
147147

148148
# Iterate through the list of repository paths
149149
for repo_path in repo_paths:
150+
if not os.path.exists(repo_path):
151+
logger.warning(f"""Warning: {repo_path} not found. Consider doing `mlc rm repo {repo_path}`. Skipping...""")
152+
continue
153+
150154
if is_curdir_inside_path(repo_path):
151155
self.current_repo_path = repo_path
152156
repo_path = repo_path.strip() # Remove any extra whitespace or newlines
@@ -289,10 +293,13 @@ def add(self, i):
289293
if res["return"] > 0:
290294
return res
291295

296+
if len(res["list"]) == 0:
297+
return {'return': 1, 'error': f"""The given repo {item_repo} is not registered in MLC"""}
298+
292299
# Determine paths and metadata format
293300
repo = res["list"][0]
294301
repo_path = repo.path
295-
302+
296303
target_name = i.get('target_name', self.action_type)
297304
target_path = os.path.join(repo_path, target_name)
298305
if target_name == "cache":
@@ -393,7 +400,7 @@ def rm(self, i):
393400

394401
def save_new_meta(self, i, item_id, item_name, target_name, item_path, repo):
395402
# Prepare metadata
396-
item_meta = i.get('meta')
403+
item_meta = i.get('meta', {})
397404
item_meta.update({
398405
"alias": item_name,
399406
"uid": item_id,
@@ -505,6 +512,7 @@ def is_uid(self, name):
505512
# Check if the name matches the pattern
506513
return bool(re.fullmatch(hex_uid_pattern, name))
507514

515+
508516
def cp(self, run_args):
509517
action_target = run_args['target']
510518
src_item = run_args['src']
@@ -1187,6 +1195,46 @@ def rm(self, i):
11871195
logger.debug(f"Removing script with input: {i}")
11881196
return self.parent.rm(i)
11891197

1198+
def add(self, i):
1199+
"""
1200+
Adds a new script to the repository.
1201+
1202+
Args:
1203+
i (dict): Input dictionary with the following keys:
1204+
- item_repo (tuple): Repository alias and UID (default: local repo).
1205+
- item (str): Item alias and optional UID in "alias,uid" format.
1206+
- tags (str): Comma-separated tags.
1207+
- new_tags (str): Additional comma-separated tags to add.
1208+
- yaml (bool): Whether to save metadata in YAML format. Defaults to JSON.
1209+
1210+
Returns:
1211+
dict: Result of the operation with 'return' code and error/message if applicable.
1212+
"""
1213+
# Determine repository
1214+
if i.get('details'):
1215+
item = i['details']
1216+
else:
1217+
item = i.get('item')
1218+
if not item:
1219+
return {'return': 1, 'error': f"""No script item given to add. Please use mlc add script <repo_name>:<script_name> --tags=<script_tags> format to add a script to a given repo"""}
1220+
1221+
if ":" in item:
1222+
item_split = item.split(":")
1223+
item_repo = item_split[0]
1224+
item = item_split[1]
1225+
else:
1226+
item_repo = i.get("item_repo", self.local_repo)
1227+
1228+
i['item_repo'] = item_repo
1229+
i['item'] = item
1230+
i['target_name'] = "script"
1231+
i['yaml'] = True
1232+
res = self.parent.add(i)
1233+
if res['return'] > 0:
1234+
return res
1235+
#Todo post processing to update the script meta
1236+
return res
1237+
11901238
def dynamic_import_module(self, script_path):
11911239
# Validate the script_path
11921240
if not os.path.exists(script_path):
@@ -1472,6 +1520,9 @@ def main():
14721520
if hasattr(args, 'details') and args.details and "," in args.details and not run_args.get("tags") and args.target in ["script", "cache"]:
14731521
run_args['tags'] = args.details
14741522

1523+
if not run_args.get('details') and args.details:
1524+
run_args['details'] = args.details
1525+
14751526
if args.command in ["cp", "mv"]:
14761527
run_args['target'] = args.target
14771528
if hasattr(args, 'details') and args.details:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "mlcflow"
7-
version = "0.1.25"
7+
version = "0.1.26"
88
description = "An automation interface for ML applications"
99
authors = [
1010
{ name = "MLCommons", email = "systems@mlcommons.org" }

0 commit comments

Comments
 (0)