From fae573e4aba32a96b95f94ee36561843e7a2314d Mon Sep 17 00:00:00 2001 From: Range King Date: Tue, 20 Dec 2022 10:46:30 +0800 Subject: [PATCH] [Fix] Fix the path separator problem of run command on Windows (#177) --- mim/commands/run.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mim/commands/run.py b/mim/commands/run.py index 96cfaff..aaa55f6 100644 --- a/mim/commands/run.py +++ b/mim/commands/run.py @@ -110,8 +110,8 @@ def run( pkg_root = get_installed_path(package) possible_prefixes = [ - osp.join(pkg_root, '.mim', 'tools/'), - osp.join(pkg_root, 'tools/') + osp.join(pkg_root, '.mim', f'tools{os.sep}'), + osp.join(pkg_root, f'tools{os.sep}') ] for possible_prefix in possible_prefixes: if osp.exists(possible_prefix): @@ -121,15 +121,15 @@ def run( command_domain = '' if ':' in command: split_command = command.split(':') - command_domain = '/'.join(split_command[:-1]) + command_domain = os.sep.join(split_command[:-1]) command = split_command[-1] files = recursively_find(prefix, command + '.py') if command_domain == '': - suffix = f'/{command}.py' + suffix = f'{os.sep}{command}.py' else: - suffix = f'/{command_domain}/{command}.py' + suffix = f'{os.sep}{command_domain}{os.sep}{command}.py' files = [f for f in files if f.endswith(suffix)] if len(files) == 0: @@ -142,11 +142,11 @@ def run( echo_warning(f) # Use the shortest path - files.sort(key=lambda x: len(x.split('/'))) + files.sort(key=lambda x: len(x.split(os.sep))) echo_warning(f'We are using the script {files[0]}. ') echo_warning('To use other scripts, you need to use these commands: ') for f in files[1:]: - cmd = f.split(prefix)[1].split('.')[0].replace('/', ':') + cmd = f.split(prefix)[1].split('.')[0].replace(os.sep, ':') echo_warning(f'Command for {f}: {cmd}') script = files[0]