diff options
Diffstat (limited to 'pip/util.py')
-rw-r--r-- | pip/util.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/pip/util.py b/pip/util.py index d2dae97a8..b9c32525b 100644 --- a/pip/util.py +++ b/pip/util.py @@ -7,7 +7,7 @@ import posixpath import pkg_resources import zipfile import tarfile -from pip.exceptions import InstallationError +from pip.exceptions import InstallationError, BadCommand from pip.backwardcompat import WindowsError, string_types, raw_input from pip.locations import site_packages, running_under_virtualenv from pip.log import logger @@ -71,12 +71,12 @@ def backup_dir(dir, ext='.bak'): def find_command(cmd, paths=None, pathext=None): """Searches the PATH for the given command and returns its path""" if paths is None: - paths = os.environ.get('PATH', []).split(os.pathsep) + paths = os.environ.get('PATH', '').split(os.pathsep) if isinstance(paths, string_types): paths = [paths] # check if there are funny path extensions for executables, e.g. Windows if pathext is None: - pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD') + pathext = get_pathext() pathext = [ext for ext in pathext.lower().split(os.pathsep)] # don't use extensions if the command ends with one of them if os.path.splitext(cmd)[1].lower() in pathext: @@ -92,9 +92,16 @@ def find_command(cmd, paths=None, pathext=None): return cmd_path_ext if os.path.isfile(cmd_path): return cmd_path - return None + raise BadCommand('Cannot find command %r' % cmd) +def get_pathext(default_pathext=None): + """Returns the path extensions from environment or a default""" + if default_pathext is None: + default_pathext = os.pathsep.join([ '.COM', '.EXE', '.BAT', '.CMD' ]) + pathext = os.environ.get('PATHEXT', default_pathext) + return pathext + def ask(message, options): """Ask the message interactively, with the given possible responses""" while 1: |