make sure paths found by find_command are files

This commit is contained in:
Alex Morega 2011-03-14 18:07:12 -04:00
parent b3423ade7d
commit 0236a47f0a
2 changed files with 17 additions and 2 deletions

View File

@ -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

View File

@ -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'