mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Fix error handling with fallback in which implementation
Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
+23
-15
@@ -1524,22 +1524,30 @@ def system_which(command, mult=False):
|
||||
vistir.compat.fs_str(k): vistir.compat.fs_str(val)
|
||||
for k, val in os.environ.items()
|
||||
}
|
||||
c = delegator.run("{0} {1}".format(_which, command))
|
||||
try:
|
||||
# Which Not found…
|
||||
if c.return_code == 127:
|
||||
click.echo(
|
||||
"{}: the {} system utility is required for Pipenv to find Python installations properly."
|
||||
"\n Please install it.".format(
|
||||
crayons.red("Warning", bold=True), crayons.red(_which)
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
assert c.return_code == 0
|
||||
except AssertionError:
|
||||
return None if not mult else []
|
||||
|
||||
result = c.out.strip() or c.err.strip()
|
||||
c = delegator.run("{0} {1}".format(_which, command))
|
||||
try:
|
||||
# Which Not found…
|
||||
if c.return_code == 127:
|
||||
click.echo(
|
||||
"{}: the {} system utility is required for Pipenv to find Python installations properly."
|
||||
"\n Please install it.".format(
|
||||
crayons.red("Warning", bold=True), crayons.red(_which)
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
assert c.return_code == 0
|
||||
except AssertionError:
|
||||
return None if not mult else[]
|
||||
except TypeError:
|
||||
from .vendor.pythonfinder import Finder
|
||||
finder = Finder()
|
||||
result = finder.which(command)
|
||||
if result:
|
||||
return result.path.as_posix()
|
||||
return
|
||||
else:
|
||||
result = c.out.strip() or c.err.strip()
|
||||
if mult:
|
||||
return result.split("\n")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user