Skip to content

Commit b76157e

Browse files
ofekgaborbernat
authored andcommitted
Resolve symbolic links for environment metadata
1 parent cad5500 commit b76157e

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/virtualenv/discovery/py_info.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class PythonInfo: # noqa: PLR0904
3232
"""Contains information for a Python interpreter."""
3333

3434
def __init__(self) -> None: # noqa: PLR0915
35-
def abs_path(v):
36-
return None if v is None else os.path.abspath(v) # unroll relative elements from path (e.g. ..)
35+
def real_path(v):
36+
# unroll relative elements from path (e.g. ..) and ensure symbolic links are resolved
37+
return None if v is None else os.path.realpath(v)
3738

3839
# qualifies the python
3940
self.platform = sys.platform
@@ -53,16 +54,16 @@ def abs_path(v):
5354
self.os = os.name
5455

5556
# information about the prefix - determines python home
56-
self.prefix = abs_path(getattr(sys, "prefix", None)) # prefix we think
57-
self.base_prefix = abs_path(getattr(sys, "base_prefix", None)) # venv
58-
self.real_prefix = abs_path(getattr(sys, "real_prefix", None)) # old virtualenv
57+
self.prefix = real_path(getattr(sys, "prefix", None)) # prefix we think
58+
self.base_prefix = real_path(getattr(sys, "base_prefix", None)) # venv
59+
self.real_prefix = real_path(getattr(sys, "real_prefix", None)) # old virtualenv
5960

6061
# information about the exec prefix - dynamic stdlib modules
61-
self.base_exec_prefix = abs_path(getattr(sys, "base_exec_prefix", None))
62-
self.exec_prefix = abs_path(getattr(sys, "exec_prefix", None))
62+
self.base_exec_prefix = real_path(getattr(sys, "base_exec_prefix", None))
63+
self.exec_prefix = real_path(getattr(sys, "exec_prefix", None))
6364

64-
self.executable = abs_path(sys.executable) # the executable we were invoked via
65-
self.original_executable = abs_path(self.executable) # the executable as known by the interpreter
65+
self.executable = real_path(sys.executable) # the executable we were invoked via
66+
self.original_executable = real_path(self.executable) # the executable as known by the interpreter
6667
self.system_executable = self._fast_get_system_executable() # the executable we are based of (if available)
6768

6869
try:

0 commit comments

Comments
 (0)