Skip to content

Commit f43b31a

Browse files
committed
support relative path in docker run
1 parent 3b93437 commit f43b31a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

automation/script/docker_utils.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import os
22
from mlc import utils
33
from utils import *
4-
from pathlib import PureWindowsPath, PurePosixPath
4+
from pathlib import PureWindowsPath, PurePosixPath, Path
55
from script.docker_utils import *
66
import copy
77

8+
def convert_to_abs_path(path):
9+
if not os.path.isabs(path):
10+
path = os.path.abspath(path)
11+
return path
812

913
def process_mounts(mounts, env, docker_settings, f_run_cmd):
1014
"""
@@ -63,7 +67,6 @@ def process_mounts(mounts, env, docker_settings, f_run_cmd):
6367
else: # Skip mount if variable is missing
6468
mounts[index] = None
6569
break
66-
6770
# Skip further processing if the mount was invalid
6871
if mounts[index] is None:
6972
continue
@@ -241,7 +244,6 @@ def update_container_paths(path, mounts=None, force_target_path=''):
241244
if mounts is not None:
242245
if all(mount.lower() != mount_entry.lower() for mount in mounts):
243246
mounts.append(mount_entry)
244-
245247
return host_path, container_path
246248

247249

@@ -387,6 +389,9 @@ def get_docker_default(key):
387389

388390

389391
def get_host_path(value):
392+
# convert relative path to absolute path
393+
value = convert_to_abs_path(value)
394+
390395
path_split = value.split(os.sep)
391396
if len(path_split) == 1:
392397
return value
@@ -413,6 +418,9 @@ def get_container_path_script(i):
413418

414419

415420
def get_container_path(value, username="mlcuser"):
421+
# convert relative path to absolute path
422+
value = convert_to_abs_path(value)
423+
416424
path_split = value.split(os.sep)
417425
if len(path_split) == 1:
418426
return value, value

0 commit comments

Comments
 (0)