mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-90329: Add _winapi.GetLongPathName and GetShortPathName and use in venv to reduce warnings (GH-117817)
This commit is contained in:
parent
64cd6fc9a6
commit
185999bb3a
6 changed files with 328 additions and 3 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue