From b8db36ebdf2733e13282f6b3d0eaa4b045a90258 Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Fri, 26 Oct 2018 19:10:08 -0400 Subject: [PATCH] Fix error handling with fallback in `which` implementation Signed-off-by: Dan Ryan --- pipenv/core.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/pipenv/core.py b/pipenv/core.py index b776f736..bb415317 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -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")