Skip to content

Commit 91e49e1

Browse files
committed
less invasive strategy
1 parent 423e715 commit 91e49e1

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/virtualenv/create/pyenv_cfg.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4+
import os
45
from collections import OrderedDict
56

67

@@ -32,7 +33,8 @@ def write(self):
3233
logging.debug("write %s", self.path)
3334
text = ""
3435
for key, value in self.content.items():
35-
line = f"{key} = {value}"
36+
normalized_value = os.path.realpath(value) if value and os.path.exists(value) else value
37+
line = f"{key} = {normalized_value}"
3638
logging.debug("\t%s", line)
3739
text += line
3840
text += "\n"

src/virtualenv/discovery/py_info.py

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

3434
def __init__(self) -> None: # noqa: PLR0915
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)
35+
def abs_path(v):
36+
return None if v is None else os.path.abspath(v) # unroll relative elements from path (e.g. ..)
3837

3938
# qualifies the python
4039
self.platform = sys.platform
@@ -54,16 +53,16 @@ def real_path(v):
5453
self.os = os.name
5554

5655
# information about the prefix - determines python home
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
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
6059

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

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
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
6766
self.system_executable = self._fast_get_system_executable() # the executable we are based of (if available)
6867

6968
try:

0 commit comments

Comments
 (0)