Skip to content

Commit b47c144

Browse files
committed
Provide an alternative to os.path.samefile
For windows under python2
1 parent 57ea6dd commit b47c144

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pip/compat/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
__all__ = [
2727
"logging_dictConfig", "ipaddress", "uses_pycache", "console_to_str",
28-
"native_str", "get_path_uid", "stdlib_pkgs", "WINDOWS",
28+
"native_str", "get_path_uid", "stdlib_pkgs", "WINDOWS", "samefile"
2929
]
3030

3131

@@ -126,3 +126,13 @@ def expanduser(path):
126126
# windows detection, covers cpython and ironpython
127127
WINDOWS = (sys.platform.startswith("win") or
128128
(sys.platform == 'cli' and os.name == 'nt'))
129+
130+
131+
def samefile(file1, file2):
132+
"""Provide an alternative for os.path.samefile on Windows/Python2"""
133+
if hasattr(os.path, 'samefile'):
134+
return os.path.samefile(file1, file2)
135+
else:
136+
path1 = os.path.normcase(os.path.abspath(file1))
137+
path2 = os.path.normcase(os.path.abspath(file2))
138+
return path1 == path2

pip/vcs/git.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import tempfile
55
import os.path
66

7+
from pip.compat import samefile
78
from pip.exceptions import BadCommand
89
from pip._vendor.six.moves.urllib import parse as urllib_parse
910
from pip._vendor.six.moves.urllib import request as urllib_request
@@ -211,7 +212,7 @@ def _get_subdirectory(self, location):
211212
)
212213
return None
213214
# relative path of setup.py to repo root
214-
if os.path.samefile(root_dir, location):
215+
if samefile(root_dir, location):
215216
return None
216217
return os.path.relpath(location, root_dir)
217218

0 commit comments

Comments
 (0)