Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use samefile from stdlib, supported on Windows since Python 3.2. #3137

Merged
merged 1 commit into from Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3137.change.rst
@@ -0,0 +1 @@
Use samefile from stdlib, supported on Windows since Python 3.2.
20 changes: 2 additions & 18 deletions setuptools/command/easy_install.py
Expand Up @@ -70,7 +70,7 @@
warnings.filterwarnings("default", category=pkg_resources.PEP440Warning)

__all__ = [
'samefile', 'easy_install', 'PthDistributions', 'extract_wininst_cfg',
'easy_install', 'PthDistributions', 'extract_wininst_cfg',
'get_exe_prefixes',
]

Expand All @@ -79,22 +79,6 @@ def is_64bit():
return struct.calcsize("P") == 8


def samefile(p1, p2):
"""
Determine if two paths reference the same file.

Augments os.path.samefile to work on Windows and
suppresses errors if the path doesn't exist.
"""
both_exist = os.path.exists(p1) and os.path.exists(p2)
use_samefile = hasattr(os.path, 'samefile') and both_exist
if use_samefile:
return os.path.samefile(p1, p2)
norm_p1 = os.path.normpath(os.path.normcase(p1))
norm_p2 = os.path.normpath(os.path.normcase(p2))
return norm_p1 == norm_p2


def _to_bytes(s):
return s.encode('utf8')

Expand Down Expand Up @@ -928,7 +912,7 @@ def install_egg(self, egg_path, tmpdir): # noqa: C901
ensure_directory(destination)

dist = self.egg_distribution(egg_path)
if not samefile(egg_path, destination):
if not os.path.samefile(egg_path, destination):
if os.path.isdir(destination) and not os.path.islink(destination):
dir_util.remove_tree(destination, dry_run=self.dry_run)
elif os.path.exists(destination):
Expand Down
3 changes: 1 addition & 2 deletions setuptools/package_index.py
Expand Up @@ -680,8 +680,7 @@ def gen_setup(self, filename, fragment, tmpdir):
# Make sure the file has been downloaded to the temp dir.
if os.path.dirname(filename) != tmpdir:
dst = os.path.join(tmpdir, basename)
from setuptools.command.easy_install import samefile
if not samefile(filename, dst):
if not os.path.samefile(filename, dst):
shutil.copy2(filename, dst)
filename = dst

Expand Down