From 0236a47f0a35e76dafe30e4725dff4ae23fce9a1 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Mon, 14 Mar 2011 18:07:12 -0400 Subject: [PATCH] make sure paths found by find_command are files --- pip/util.py | 4 ++-- tests/test_basic.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pip/util.py b/pip/util.py index 1eab34c0634..1c8f58b0db1 100644 --- a/pip/util.py +++ b/pip/util.py @@ -86,9 +86,9 @@ def find_command(cmd, paths=None, pathext=None): for ext in pathext: # then including the extension cmd_path_ext = cmd_path + ext - if os.path.exists(cmd_path_ext): + if os.path.isfile(cmd_path_ext): return cmd_path_ext - if os.path.exists(cmd_path): + if os.path.isfile(cmd_path): return cmd_path return None diff --git a/tests/test_basic.py b/tests/test_basic.py index 7944f327ae8..c150e02267a 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -483,3 +483,18 @@ def test_install_package_which_contains_dev_in_name(): egg_info_folder = env.site_packages/'django_devserver-0.0.4-py%s.egg-info' % pyversion assert devserver_folder in result.files_created, str(result.stdout) assert egg_info_folder in result.files_created, str(result) + +def test_find_command_folder_in_path(): + """ + If a folder named e.g. 'git' is in PATH, and find_command is looking for + the 'git' executable, it should not match the folder, but rather keep + looking. + """ + env = reset_env() + mkdir('path_one'); path_one = env.scratch_path/'path_one' + mkdir(path_one/'foo') + mkdir('path_two'); path_two = env.scratch_path/'path_two' + write_file(path_two/'foo', '# nothing') + from pip.util import find_command + found_path = find_command('foo', map(str, [path_one, path_two])) + assert found_path == path_two/'foo'