Skip to content

Commit

Permalink
less invasive strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored and gaborbernat committed Feb 21, 2024
1 parent b76157e commit afd73d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/virtualenv/create/pyenv_cfg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import os
from collections import OrderedDict


Expand Down Expand Up @@ -32,7 +33,8 @@ def write(self):
logging.debug("write %s", self.path)
text = ""
for key, value in self.content.items():
line = f"{key} = {value}"
normalized_value = os.path.realpath(value) if value and os.path.exists(value) else value
line = f"{key} = {normalized_value}"
logging.debug("\t%s", line)
text += line
text += "\n"
Expand Down
19 changes: 9 additions & 10 deletions src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ class PythonInfo: # noqa: PLR0904
"""Contains information for a Python interpreter."""

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

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

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

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

self.executable = real_path(sys.executable) # the executable we were invoked via
self.original_executable = real_path(self.executable) # the executable as known by the interpreter
self.executable = abs_path(sys.executable) # the executable we were invoked via
self.original_executable = abs_path(self.executable) # the executable as known by the interpreter
self.system_executable = self._fast_get_system_executable() # the executable we are based of (if available)

try:
Expand Down

0 comments on commit afd73d2

Please sign in to comment.