Skip to content

Commit 1cf476e

Browse files
authored
Handle rm repo in external paths (mlcommons#206)
* Handle rm repo in external paths
1 parent 85f150f commit 1cf476e

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

.github/workflows/test-mlc-core-actions.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,14 @@ jobs:
151151
mlc add repo my-new-repo
152152
mlc add repo https://github.com/mlcommons/inference
153153
mlc add repo https://mygit.com/myrepo
154-
154+
155+
' Disabled now as MLCFlow automatically deletes corrupted entries
155156
- name: Test 13 - rm repo where we have a corrupt entry
156157
run: |
157158
rm -r $HOME/MLC/repos/mlcommons@mlperf-automations
158159
mlc rm repo mlcommons@mlperf-automations
159160
mlc pull repo mlcommons@mlperf-automations --branch=dev
160-
161+
'
161162
- name: Test 14 - add script - Add a new MLC script
162163
run: |
163164
mlc add script my-script-1 --tags=my,new-tags-1

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.13
1+
1.1.14

mlc/action.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def is_curdir_inside_path(base_path):
106106
# Iterate through the list of repository paths
107107
for repo_path in repo_paths:
108108
if not os.path.exists(repo_path):
109-
logger.warning(f"""Warning: {repo_path} not found. Considering it as a corrupt entry and deleting automatically...""")
110-
logger.warning(f"Deleting the {meta_yaml_path} entry from repos.json")
109+
logger.warning(f"""Warning: {repo_path} not found. Considering it as a corrupt entry and deleting from repos.json...""")
111110
from .repo_action import rm_repo
112111
res = rm_repo(repo_path, os.path.join(self.repos_path, 'repos.json'), True)
113112

mlc/repo_action.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ def find(self, run_args):
212212
repo_name = result["value"]
213213
else:
214214
return result
215+
else:
216+
repo_name = repo
215217

216218
# Check if repo_name exists in repos.json
217219
matched_repo_path = None
@@ -220,22 +222,29 @@ def find(self, run_args):
220222
matched_repo_path = repo_obj
221223
break
222224

225+
223226
# Search through self.repos for matching repos
224227
lst = []
225228
for i in self.repos:
226229
if repo_uid and i.meta['uid'] == repo_uid:
227230
lst.append(i)
228231
elif repo_name == i.meta['alias']:
229232
lst.append(i)
230-
elif utils.is_uid(repo) and not any(i.meta['uid'] == repo_uid for i in self.repos):
233+
234+
235+
# After loop, check if any match was found
236+
if not lst and not matched_repo_path:
237+
# Determine error message based on input
238+
if utils.is_uid(repo):
231239
return {"return": 1, "error": f"No repository with UID: '{repo_uid}' was found"}
232-
elif "," in repo and not matched_repo_path and not any(i.meta['uid'] == repo_uid for i in self.repos) and not any(i.meta['alias'] == repo_name for i in self.repos):
240+
elif "," in repo and not matched_repo_path:
233241
return {"return": 1, "error": f"No repository with alias: '{repo_name}' and UID: '{repo_uid}' was found"}
234-
elif not matched_repo_path and not any(i.meta['alias'] == repo_name for i in self.repos) and not any(i.meta['uid'] == repo_uid for i in self.repos ):
242+
else:
235243
return {"return": 1, "error": f"No repository with alias: '{repo_name}' was found"}
244+
236245

237246
# Append the matched repo path
238-
if(len(lst)==0):
247+
if(len(lst)==0 and matched_repo_path):
239248
lst.append(matched_repo_path)
240249

241250
return {'return': 0, 'list': lst}
@@ -518,8 +527,27 @@ def rm(self, run_args):
518527
logger.error("The repository to be removed is not specified")
519528
return {"return": 1, "error": "The repository to be removed is not specified"}
520529

521-
repo_folder_name = run_args['repo']
522-
repo_path = os.path.join(self.repos_path, repo_folder_name)
530+
r = self.find(run_args)
531+
532+
533+
if r['return'] == 0:
534+
535+
list_repos = r['list']
536+
if len(list_repos) > 1:
537+
return {"return": 1, "error": "Please select a unique repo by repo alias or repo UID to remove"}
538+
539+
repo = list_repos[0]
540+
repo_path = repo.path
541+
542+
else:
543+
repo = run_args['repo']
544+
if os.path.exists(repo):
545+
repo_path = repo
546+
elif os.path.isdir(os.path.join(self.repos_path, repo)):
547+
repo_path = os.path.join(self.repos_path, repo)
548+
else:
549+
return r
550+
523551
repos_file_path = os.path.join(self.repos_path, 'repos.json')
524552

525553
force_remove = True if run_args.get('f') else False
@@ -530,7 +558,10 @@ def rm_repo(repo_path, repos_file_path, force_remove):
530558
logger.info("rm command has been called for repo. This would delete the repo folder and unregister the repo from repos.json")
531559

532560
repo_name = os.path.basename(repo_path)
533-
if os.path.exists(repo_path):
561+
mlc_repos_path = os.path.abspath(os.path.dirname(repos_file_path))
562+
repo_parent_path = os.path.abspath(os.path.dirname(repo_path))
563+
564+
if os.path.isdir(repo_path) and os.path.samefile(mlc_repos_path, repo_parent_path):
534565
# Check for local changes
535566
status_command = ['git', '-C', repo_path, 'status', '--porcelain', '--untracked-files=no']
536567
local_changes = subprocess.run(status_command, capture_output=True, text=True)
@@ -554,7 +585,7 @@ def rm_repo(repo_path, repos_file_path, force_remove):
554585

555586

556587
else:
557-
logger.warning(f"Repo {repo_name} was not found in the repo folder. repos.json will be checked for any corrupted entry. If any, that will be removed.")
588+
logger.warning(f"Repo {repo_name} was not found in the repo folder. repos.json will be checked for external paths. If any, that will be removed.")
558589
unregister_repo(repo_path, repos_file_path)
559590

560591
return {"return": 0}

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 = "1.1.13"
7+
version = "1.1.14"
88

99
description = "An automation interface tailored for CPU/GPU benchmarking"
1010
authors = [

0 commit comments

Comments
 (0)