[Fix] Fix the path separator problem of run command on Windows (#177)

This commit is contained in:
Range King 2022-12-20 10:46:30 +08:00 committed by GitHub
parent 6d947416dd
commit fae573e4ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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]