Skip to content

Commit a215ea6

Browse files
authored
Merge branch 'mlcommons:dev' into dev
2 parents 80e3d98 + 2c45516 commit a215ea6

File tree

28 files changed

+317
-195
lines changed

28 files changed

+317
-195
lines changed

automation/script/docker.py

+32-10
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def dockerfile(self_module, input_params):
2020
run_command_arc = prune_result['new_input']
2121
current_directory = os.getcwd()
2222
is_quiet_mode = input_params.get('quiet', False)
23-
verbose = input_params.get('v', False)
2423
is_console_output = input_params.get('out') == 'con'
2524

2625
# Step 2: Search for scripts
@@ -88,8 +87,7 @@ def dockerfile(self_module, input_params):
8887
new_state_keys_from_meta=[], # Add state keys from meta if needed
8988
add_deps_recursive=add_deps_recursive,
9089
run_state=run_state,
91-
recursion_spaces='',
92-
verbose=verbose # Set to True or False as needed
90+
recursion_spaces=''
9391
)
9492
if update_variations_result['return'] > 0:
9593
return update_variations_result
@@ -109,7 +107,7 @@ def dockerfile(self_module, input_params):
109107
deps = docker_settings.get('build_deps', [])
110108
if deps:
111109
r = self_module._run_deps(
112-
deps, [], env, {}, {}, {}, {}, '', [], '', False, '', verbose,
110+
deps, [], env, {}, {}, {}, {}, '', [], '', False, '',
113111
show_time, ' ', run_state)
114112
if r['return'] > 0:
115113
return r
@@ -180,8 +178,34 @@ def dockerfile(self_module, input_params):
180178
'comments': comments, 'run_cmd': f"{run_command_string} --quiet",
181179
'script_tags': input_params.get('tags'), 'env': env,
182180
'dockerfile_env': dockerfile_env,
183-
'quiet': True, 'v': input_params.get('v', False), 'real_run': True
181+
'quiet': True, 'real_run': True
184182
}
183+
184+
docker_v = False
185+
docker_s = False
186+
if is_true(input_params.get(
187+
'docker_v', input_params.get('docker_verbose', False))):
188+
docker_v = True
189+
if is_true(input_params.get(
190+
'docker_s', input_params.get('docker_silent', False))):
191+
docker_s = True
192+
193+
if docker_s and docker_v:
194+
logger.warning(
195+
"Both verbose and silent is set to True. Verbose will take precedence.")
196+
docker_s = False
197+
198+
if not docker_s and not docker_v:
199+
if logger.level == logging.DEBUG:
200+
docker_v = True
201+
elif logger.level == logging.WARNING:
202+
docker_s = True
203+
204+
if docker_s:
205+
mlc_docker_input['run_cmd'] += ' -s'
206+
elif docker_v:
207+
mlc_docker_input['run_cmd'] += ' -v'
208+
185209
mlc_docker_input.update(docker_inputs)
186210

187211
dockerfile_result = self_module.action_object.access(mlc_docker_input)
@@ -209,7 +233,6 @@ def docker_run(self_module, i):
209233

210234
# Extract and handle basic inputs
211235
quiet = i.get('quiet', False)
212-
verbose = i.get('v', False)
213236
show_time = i.get('show_time', False)
214237
logger = self_module.logger
215238
env = i.get('env', {})
@@ -296,8 +319,7 @@ def docker_run(self_module, i):
296319
posthook_deps=[],
297320
new_env_keys_from_meta=[],
298321
new_state_keys_from_meta=[],
299-
add_deps_recursive=add_deps_recursive, run_state=run_state, recursion_spaces='',
300-
verbose=False)
322+
add_deps_recursive=add_deps_recursive, run_state=run_state, recursion_spaces='')
301323
if r['return'] > 0:
302324
return r
303325

@@ -306,7 +328,7 @@ def docker_run(self_module, i):
306328
deps = docker_settings.get('deps', [])
307329
if deps:
308330
r = self_module._run_deps(
309-
deps, [], env, {}, {}, {}, {}, '', [], '', False, '', verbose,
331+
deps, [], env, {}, {}, {}, {}, '', [], '', False, '',
310332
show_time, ' ', run_state)
311333
if r['return'] > 0:
312334
return r
@@ -374,7 +396,7 @@ def docker_run(self_module, i):
374396
'action': 'run', 'target': 'script', 'tags': 'run,docker,container',
375397
'rebuild': rebuild_docker_image,
376398
'env': env, 'mounts': mounts,
377-
'script_tags': i.get('tags'), 'run_cmd': final_run_cmd, 'v': verbose,
399+
'script_tags': i.get('tags'), 'run_cmd': final_run_cmd,
378400
'quiet': True, 'real_run': True, 'add_deps_recursive': {'build-docker-image': {'dockerfile': dockerfile_path}},
379401
**docker_inputs
380402
}

automation/script/docker_utils.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
import copy
77

88

9+
def convert_to_abs_path(path):
10+
if not os.path.isabs(path):
11+
path = os.path.abspath(path)
12+
return path
13+
14+
915
def process_mounts(mounts, env, docker_settings, f_run_cmd):
1016
"""
1117
Processes and updates the Docker mounts based on the provided inputs and environment variables.
@@ -63,7 +69,6 @@ def process_mounts(mounts, env, docker_settings, f_run_cmd):
6369
else: # Skip mount if variable is missing
6470
mounts[index] = None
6571
break
66-
6772
# Skip further processing if the mount was invalid
6873
if mounts[index] is None:
6974
continue
@@ -241,7 +246,6 @@ def update_container_paths(path, mounts=None, force_target_path=''):
241246
if mounts is not None:
242247
if all(mount.lower() != mount_entry.lower() for mount in mounts):
243248
mounts.append(mount_entry)
244-
245249
return host_path, container_path
246250

247251

@@ -344,7 +348,10 @@ def rebuild_flags(
344348
command_line += f" --{full_key},={list_values}"
345349
# Process scalar values.
346350
else:
347-
command_line += f" --{full_key}={quote}{str(value)}{quote}"
351+
if full_key in ['s', 'v']:
352+
command_line += f" -{full_key}"
353+
else:
354+
command_line += f" --{full_key}={quote}{str(value)}{quote}"
348355

349356
return command_line
350357

@@ -384,9 +391,10 @@ def get_docker_default(key):
384391

385392

386393
def get_host_path(value):
394+
# convert relative path to absolute path
395+
value = convert_to_abs_path(value)
396+
387397
path_split = value.split(os.sep)
388-
if len(path_split) == 1:
389-
return value
390398

391399
new_value = ''
392400
if "cache" in path_split and "local":
@@ -410,9 +418,10 @@ def get_container_path_script(i):
410418

411419

412420
def get_container_path(value, username="mlcuser"):
421+
# convert relative path to absolute path
422+
value = convert_to_abs_path(value)
423+
413424
path_split = value.split(os.sep)
414-
if len(path_split) == 1:
415-
return value, value
416425

417426
new_value = ''
418427
if "cache" in path_split and "local" in path_split:

0 commit comments

Comments
 (0)