Fix error handling with fallback in which implementation

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2018-10-26 19:10:08 -04:00
parent 2803538701
commit b8db36ebdf
+23 -15
View File
@@ -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")