summaryrefslogtreecommitdiffstats
path: root/Lib/venv
diff options
context:
space:
mode:
authorSteve Dower <steve.dower@python.org>2024-04-15 14:36:06 (GMT)
committerGitHub <noreply@github.com>2024-04-15 14:36:06 (GMT)
commit185999bb3ad3f1484da8fa4b84813980b976dc3c (patch)
treed288110bc9bac2e1459443a9a9d34ce12ac663b8 /Lib/venv
parent64cd6fc9a6a3c3c19091a1c81cbbe8994583017d (diff)
downloadcpython-185999bb3ad3f1484da8fa4b84813980b976dc3c.zip
cpython-185999bb3ad3f1484da8fa4b84813980b976dc3c.tar.gz
cpython-185999bb3ad3f1484da8fa4b84813980b976dc3c.tar.bz2
gh-90329: Add _winapi.GetLongPathName and GetShortPathName and use in venv to reduce warnings (GH-117817)
Diffstat (limited to 'Lib/venv')
-rw-r--r--Lib/venv/__init__.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index 4856594..fa69d58 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -107,6 +107,33 @@ class EnvBuilder:
}
return sysconfig.get_path(name, scheme='venv', vars=vars)
+ @classmethod
+ def _same_path(cls, path1, path2):
+ """Check whether two paths appear the same.
+
+ Whether they refer to the same file is irrelevant; we're testing for
+ whether a human reader would look at the path string and easily tell
+ that they're the same file.
+ """
+ if sys.platform == 'win32':
+ if os.path.normcase(path1) == os.path.normcase(path2):
+ return True
+ # gh-90329: Don't display a warning for short/long names
+ import _winapi
+ try:
+ path1 = _winapi.GetLongPathName(os.fsdecode(path1))
+ except OSError:
+ pass
+ try:
+ path2 = _winapi.GetLongPathName(os.fsdecode(path2))
+ except OSError:
+ pass
+ if os.path.normcase(path1) == os.path.normcase(path2):
+ return True
+ return False
+ else:
+ return path1 == path2
+
def ensure_directories(self, env_dir):
"""
Create the directories for the environment.
@@ -171,7 +198,7 @@ class EnvBuilder:
# bpo-45337: Fix up env_exec_cmd to account for file system redirections.
# Some redirects only apply to CreateFile and not CreateProcess
real_env_exe = os.path.realpath(context.env_exe)
- if os.path.normcase(real_env_exe) != os.path.normcase(context.env_exe):
+ if not self._same_path(real_env_exe, context.env_exe):
logger.warning('Actual environment location may have moved due to '
'redirects, links or junctions.\n'
' Requested location: "%s"\n'