Skip to content

Commit 5425b74

Browse files
authored
Merge pull request #182 from mlcommons/dev
Merge dev
2 parents a96ceca + bc93c82 commit 5425b74

File tree

7 files changed

+186
-87
lines changed

7 files changed

+186
-87
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- main
1010
- dev
1111
permissions:
12-
contents: read
12+
contents: write
1313
jobs:
1414
publish:
1515
name: Publish the site

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

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ jobs:
206206
- name: Test 22 - Test recursive mlc pull repo
207207
run: |
208208
export MLC_REPOS=$HOME/test
209-
mlc pull repo https://github.com/GATEOverflow/GO-PDFs
209+
mlcp https://github.com/GATEOverflow/GO-PDFs
210210
mlcr detect,os -j
211211
212212
test_mlc_access_core_actions:
@@ -271,9 +271,6 @@ jobs:
271271
matrix:
272272
python-version: ["3.12", "3.8"]
273273
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
274-
exclude:
275-
- os: windows-latest
276-
- os: macos-latest
277274

278275
steps:
279276
- uses: actions/checkout@v4
@@ -294,38 +291,92 @@ jobs:
294291
python -m pip install .
295292
- name: MLC intro
296293
run: |
297-
mlc help
294+
mlc --help
295+
mlc -h
298296
- name: MLC scripts - full
299297
run: |
300-
mlc help script
298+
mlc script --help
299+
mlc script --h
301300
- name: MLC scripts - individual actions
302301
run: |
303-
mlc help add script
304-
mlc help docker script
305-
mlc help find script
306-
mlc help search script
307-
mlc help list script
308-
mlc help rm script
309-
mlc help run script
310-
mlc help show script
311-
mlc help test script
302+
mlc add script --help
303+
mlc docker script --help
304+
mlc find script --help
305+
mlc search script --help
306+
mlc list script --help
307+
mlc rm script --help
308+
mlc run script --help
309+
mlc show script --help
310+
mlc test script --help
311+
mlc add script -h
312+
mlc docker script -h
313+
mlc find script -h
314+
mlc search script -h
315+
mlc list script -h
316+
mlc rm script -h
317+
mlc run script -h
318+
mlc show script -h
319+
mlc test script -h
312320
- name: MLC repos - full
313321
run: |
314-
mlc help repo
322+
mlc repo --help
323+
mlc repo -h
315324
- name: MLC repos - individual actions
316325
run: |
317-
mlc help add repo
318-
mlc help find repo
319-
mlc help pull repo
320-
mlc help list repo
321-
mlc help rm repo
326+
mlc add repo --help
327+
mlc find repo --help
328+
mlc pull repo --help
329+
mlc list repo --help
330+
mlc rm repo --help
331+
mlc add repo -h
332+
mlc find repo -h
333+
mlc pull repo -h
334+
mlc list repo -h
335+
mlc rm repo -h
322336
- name: MLC cache - full
323337
run: |
324-
mlc help cache
338+
mlc cache --help
339+
mlc cache -h
325340
- name: MLC cache - individual actions
326341
run: |
327-
mlc help find cache
328-
mlc help list cache
329-
mlc help rm cache
330-
mlc help search cache
331-
mlc help show cache
342+
mlc find cache --help
343+
mlc list cache --help
344+
mlc rm cache --help
345+
mlc search cache --help
346+
mlc show cache --help
347+
mlc find cache -h
348+
mlc list cache -h
349+
mlc rm cache -h
350+
mlc search cache -h
351+
mlc show cache -h
352+
353+
test_mlc_script_actions:
354+
runs-on: ${{ matrix.os }}
355+
strategy:
356+
fail-fast: false
357+
matrix:
358+
python-version: ["3.13", "3.8"]
359+
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
360+
action: ["mlcr", "mlce", "mlct"]
361+
362+
steps:
363+
- uses: actions/checkout@v4
364+
- name: Set up Python ${{ matrix.python-version }}
365+
uses: actions/setup-python@v3
366+
with:
367+
python-version: ${{ matrix.python-version }}
368+
369+
- name: Configure git longpaths (Windows)
370+
if: matrix.os == 'windows-latest'
371+
run: |
372+
git config --system core.longpaths true
373+
374+
- name: Install mlcflow from the pull request's source repository and branch
375+
run: |
376+
python -m pip install --upgrade pip
377+
python -m pip install --ignore-installed --verbose pip setuptools
378+
python -m pip install .
379+
- name: MLC ${{matrix.action}} script
380+
run: |
381+
mlcp mlcommons@mlperf-automations
382+
${{matrix.action}} detect,cpu

.github/workflows/test-mlc-docker-core.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
5757
- name: Test --docker_cache
5858
run: |
59-
mlc docker run --tags=detect,os --docker_dt --docker_cache=no
59+
mlcd detect,os --docker_dt --docker_cache=no
6060
6161
- name: Test --docker_rebuild
6262
run: |

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.0
1+
1.2.0

mlc/cache_action.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,32 @@ def search(self, i):
4242
"""
4343
i['target_name'] = "cache"
4444
#logger.debug(f"Searching for cache with input: {i}")
45-
return self.parent.search(i)
45+
r = self.parent.search(i)
46+
if r['return'] > 0:
47+
return r
48+
cleaned_list = []
49+
50+
for item in r['list']:
51+
item_meta = item.meta
52+
'''#handled in script automation now
53+
dep = item_meta.get('dependent_cached_path')
54+
if dep and not os.path.exists(dep):
55+
continue # skip item
56+
57+
deps = item_meta.get('dependent_cached_paths', '').split(',')
58+
if any(d and not os.path.exists(d) for d in deps):
59+
continue # skip item
60+
'''
61+
62+
expiration_time = item_meta.get('expiration_time')
63+
if expiration_time is not None and expiration_time < time.time():
64+
continue # skip expired item
65+
66+
cleaned_list.append(item)
67+
68+
r['list'] = cleaned_list
69+
70+
return r
4671

4772
find = search
4873

@@ -98,6 +123,9 @@ def show(self, run_args):
98123
"""
99124
self.action_type = "cache"
100125
res = self.search(run_args)
126+
if res['return'] > 0:
127+
return res
128+
101129
logger.info(f"Showing cache with tags: {run_args.get('tags')}")
102130
cached_meta_keys_to_show = ["uid", "tags", "dependent_cached_path", "associated_script_item"]
103131
cached_state_keys_to_show = ["new_env", "new_state", "version"]

mlc/main.py

Lines changed: 71 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,26 @@ def search(self, i):
7575
#indices
7676

7777

78-
def mlcr():
79-
first_arg_value = "run"
80-
second_arg_value = "script"
78+
def mlc_expand_short(action, target = "script"):
8179

8280
# Insert the positional argument into sys.argv for the main function
83-
sys.argv.insert(1, first_arg_value)
84-
sys.argv.insert(2, second_arg_value)
81+
sys.argv.insert(1, action)
82+
sys.argv.insert(2, target)
8583

8684
# Call the main function
8785
main()
8886

87+
def mlcr():
88+
mlc_expand_short("run")
89+
def mlcd():
90+
mlc_expand_short("docker")
91+
def mlce():
92+
mlc_expand_short("experiment")
93+
def mlct():
94+
mlc_expand_short("test")
95+
96+
def mlcp():
97+
mlc_expand_short("pull", "repo")
8998

9099

91100
def process_console_output(res, target, action, run_args):
@@ -132,12 +141,63 @@ def main():
132141
133142
For help related to a particular target, run:
134143
135-
mlc help <target>
144+
mlc <target> --help/-h
145+
146+
Examples:
147+
mlc script --help
148+
mlc repo -h
136149
137150
For help related to a specific action for a target, run:
138151
139-
mlc help <action> <target>
152+
mlc <action> <target> --help/-h
153+
Examples:
154+
mlc run script --help
155+
mlc pull repo -h
140156
"""
157+
158+
# First level parser for showing help
159+
pre_parser = argparse.ArgumentParser(add_help=False)
160+
pre_parser.add_argument("action", nargs="?", help="Top-level action (run, build, help, etc.)")
161+
pre_parser.add_argument("target", choices=['run', 'script', 'cache', 'repo'], nargs="?", help="Potential target (repo, script, cache, ...)")
162+
pre_parser.add_argument("-h", "--help", action="store_true")
163+
pre_args, remaining_args = pre_parser.parse_known_args()
164+
165+
if pre_args.help and not any("--tags" in arg for arg in remaining_args):
166+
help_text = ""
167+
if pre_args.target == "run":
168+
if pre_args.action == "docker":
169+
pre_args.target = "script"
170+
else:
171+
logger.error(f"Invalid action-target {pre_args.action} - {pre_args.target} combination")
172+
raise Exception(f"Invalid action-target {pre_args.action} - {pre_args.target} combination")
173+
if not pre_args.action and not pre_args.target:
174+
help_text += main.__doc__
175+
elif pre_args.action and not pre_args.target:
176+
if pre_args.action not in ['script', 'cache', 'repo']:
177+
logger.error(f"Invalid target {pre_args.action}")
178+
raise Exception(f"""Invalid target {pre_args.action}""")
179+
else:
180+
pre_args.target, pre_args.action = pre_args.action, None
181+
actions = get_action(pre_args.target, default_parent)
182+
help_text += actions.__doc__
183+
# iterate through every method
184+
for method_name, method in inspect.getmembers(actions.__class__, inspect.isfunction):
185+
method = getattr(actions, method_name)
186+
if method.__doc__ and not method.__doc__.startswith("_"):
187+
help_text += method.__doc__
188+
elif pre_args.action and pre_args.target:
189+
actions = get_action(pre_args.target, default_parent)
190+
try:
191+
method = getattr(actions, pre_args.action)
192+
help_text += actions.__doc__
193+
help_text += method.__doc__
194+
except:
195+
logger.error(f"Error: '{pre_args.action}' is not supported for {pre_args.target}.")
196+
if help_text != "":
197+
print(help_text)
198+
sys.exit(0)
199+
200+
# parser for execution of the automation scripts
141201
parser = argparse.ArgumentParser(prog='mlc', description='A CLI tool for managing repos, scripts, and caches.', add_help=False)
142202

143203
# Subparsers are added to main parser, allowing for different commands (subcommands) to be defined.
@@ -146,30 +206,24 @@ def main():
146206

147207
# Script and Cache-specific subcommands
148208
for action in ['run', 'pull', 'test', 'add', 'show', 'list', 'find', 'search', 'rm', 'cp', 'mv']:
149-
action_parser = subparsers.add_parser(action, help=f'{action} a target.')
209+
action_parser = subparsers.add_parser(action, add_help=False)
150210
action_parser.add_argument('target', choices=['repo', 'script', 'cache'], help='Target type (repo, script, cache).')
151211
# the argument given after target and before any extra options like --tags will be stored in "details"
152212
action_parser.add_argument('details', nargs='?', help='Details or identifier (optional for list).')
153213
action_parser.add_argument('extra', nargs=argparse.REMAINDER, help='Extra options (e.g., -v)')
154214

155215
# Script specific subcommands
156216
for action in ['docker', 'experiment', 'doc', 'lint']:
157-
action_parser = subparsers.add_parser(action, help=f'{action.capitalize()} a target.')
217+
action_parser = subparsers.add_parser(action, add_help=False)
158218
action_parser.add_argument('target', choices=['script', 'run'], help='Target type (script).')
159219
# the argument given after target and before any extra options like --tags will be stored in "details"
160220
action_parser.add_argument('details', nargs='?', help='Details or identifier (optional for list).')
161221
action_parser.add_argument('extra', nargs=argparse.REMAINDER, help='Extra options (e.g., -v)')
162222

163223
for action in ['load']:
164-
load_parser = subparsers.add_parser(action, help=f'{action.capitalize()} a target.')
224+
load_parser = subparsers.add_parser(action, add_help=False)
165225
load_parser.add_argument('target', choices=['cfg'], help='Target type (cfg).')
166226

167-
for action in ['help']:
168-
action_parser = subparsers.add_parser(action, help=f'{action.capitalize()} a target.')
169-
action_parser.add_argument('action', help='action type (run).', nargs='?', default=None)
170-
action_parser.add_argument('target', choices=['script', 'cache', 'repo'], help='Target type (script).', nargs='?', default=None)
171-
action_parser.add_argument('extra', nargs=argparse.REMAINDER, help='Extra options (e.g., -v)')
172-
173227
# Parse arguments
174228
args = parser.parse_args()
175229

@@ -201,45 +255,7 @@ def main():
201255

202256
run_args = res['args_dict']
203257

204-
# handle help in mlcflow
205-
if args.command in ['help']:
206-
help_text = ""
207-
if not args.action and not args.target:
208-
help_text += main.__doc__
209-
elif args.action and not args.target:
210-
if args.action not in ['script', 'cache', 'repo']:
211-
logger.error(f"Invalid target {args.action}")
212-
raise Exception(f"""Invalid target {args.action}""")
213-
else:
214-
args.target, args.action = args.action, None
215-
actions = get_action(args.target, default_parent)
216-
help_text += actions.__doc__
217-
# iterate through every method
218-
for method_name, method in inspect.getmembers(actions.__class__, inspect.isfunction):
219-
method = getattr(actions, method_name)
220-
if method.__doc__ and not method.__doc__.startswith("_"):
221-
help_text += method.__doc__
222-
elif args.action and args.target and run_args.get('tags'):
223-
actions = get_action(args.target, default_parent)
224-
if actions and hasattr(actions, args.command):
225-
method = getattr(actions, args.command)
226-
res = method(run_args)
227-
if res['return'] > 0:
228-
logger.error(res.get('error', f"Error in {action}"))
229-
raise Exception(f"""An error occurred {res}""")
230-
else:
231-
logger.error(f"Error: '{args.command}' is not supported for {args.target}.")
232-
elif args.action and args.target:
233-
actions = get_action(args.target, default_parent)
234-
try:
235-
method = getattr(actions, args.action)
236-
help_text += actions.__doc__
237-
help_text += method.__doc__
238-
except:
239-
logger.error(f"Error: '{args.action}' is not supported for {args.target}.")
240-
if help_text != "":
241-
print(help_text)
242-
sys.exit(0)
258+
run_args['mlc_run_cmd'] = " ".join(sys.argv)
243259

244260
if hasattr(args, 'repo') and args.repo:
245261
run_args['repo'] = args.repo

pyproject.toml

Lines changed: 5 additions & 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.0.20"
7+
version = "1.0.23"
88

99

1010

@@ -47,3 +47,7 @@ py-modules = []
4747
[project.scripts]
4848
mlc = "mlc.main:main"
4949
mlcr = "mlc.main:mlcr"
50+
mlcd = "mlc.main:mlcd"
51+
mlce = "mlc.main:mlce"
52+
mlct = "mlc.main:mlct"
53+
mlcp = "mlc.main:mlcp"

0 commit comments

Comments
 (0)