Skip to content

Commit fa83956

Browse files
authored
[Misc] Refactor: Improve argument handling for conda command (#20481)
Signed-off-by: reidliu41 <reid201711@gmail.com>
1 parent 75a99b9 commit fa83956

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

vllm/collect_env.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,30 @@
9696
def run(command):
9797
"""Return (return-code, stdout, stderr)."""
9898
shell = True if type(command) is str else False
99-
p = subprocess.Popen(command,
100-
stdout=subprocess.PIPE,
101-
stderr=subprocess.PIPE,
102-
shell=shell)
103-
raw_output, raw_err = p.communicate()
104-
rc = p.returncode
105-
if get_platform() == 'win32':
106-
enc = 'oem'
107-
else:
108-
enc = locale.getpreferredencoding()
109-
output = raw_output.decode(enc)
110-
if command == 'nvidia-smi topo -m':
111-
# don't remove the leading whitespace of `nvidia-smi topo -m`
112-
# because they are meaningful
113-
output = output.rstrip()
114-
else:
115-
output = output.strip()
116-
err = raw_err.decode(enc)
117-
return rc, output, err.strip()
99+
try:
100+
p = subprocess.Popen(command,
101+
stdout=subprocess.PIPE,
102+
stderr=subprocess.PIPE,
103+
shell=shell)
104+
raw_output, raw_err = p.communicate()
105+
rc = p.returncode
106+
if get_platform() == 'win32':
107+
enc = 'oem'
108+
else:
109+
enc = locale.getpreferredencoding()
110+
output = raw_output.decode(enc)
111+
if command == 'nvidia-smi topo -m':
112+
# don't remove the leading whitespace of `nvidia-smi topo -m`
113+
# because they are meaningful
114+
output = output.rstrip()
115+
else:
116+
output = output.strip()
117+
err = raw_err.decode(enc)
118+
return rc, output, err.strip()
119+
120+
except FileNotFoundError:
121+
cmd_str = command if isinstance(command, str) else command[0]
122+
return 127, '', f"Command not found: {cmd_str}"
118123

119124

120125
def run_and_read_all(run_lambda, command):
@@ -148,7 +153,7 @@ def get_conda_packages(run_lambda, patterns=None):
148153
if patterns is None:
149154
patterns = DEFAULT_CONDA_PATTERNS
150155
conda = os.environ.get('CONDA_EXE', 'conda')
151-
out = run_and_read_all(run_lambda, "{} list".format(conda))
156+
out = run_and_read_all(run_lambda, [conda, 'list'])
152157
if out is None:
153158
return out
154159

0 commit comments

Comments
 (0)