Skip to content

Commit

Permalink
fix python discovery with non resolved prefix paths (#1590)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat authored Feb 12, 2020
1 parent 33dc914 commit 80fe52f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
2 changes: 2 additions & 0 deletions docs/changelog/1583.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix system python discovery mechanism when prefixes contain relative parts (e.g. ``..``) by resolving paths within the
python information query - by :user:`gaborbernat`.
12 changes: 9 additions & 3 deletions src/virtualenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
from datetime import datetime

import six


def run(args=None, options=None):
start = datetime.now()
Expand All @@ -14,14 +16,18 @@ def run(args=None, options=None):
if args is None:
args = sys.argv[1:]
try:
run_via_cli(args, options)
session = run_via_cli(args, options)
logging.warning(
"created virtual environment in %.0fms %s with seeder %s",
(datetime.now() - start).total_seconds() * 1000,
six.ensure_text(str(session.creator)),
six.ensure_text(str(session.seeder)),
)
except ProcessCallFailed as exception:
print("subprocess call failed for {}".format(exception.cmd))
print(exception.out, file=sys.stdout, end="")
print(exception.err, file=sys.stderr, end="")
raise SystemExit(exception.code)
finally:
logging.info("done in %.0fms", (datetime.now() - start).total_seconds() * 1000)


def run_with_catch(args=None):
Expand Down
21 changes: 10 additions & 11 deletions src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def __init__(self):
def u(v):
return v.decode("utf-8") if isinstance(v, bytes) else 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 = u(sys.platform)
self.implementation = u(platform.python_implementation())
Expand All @@ -49,16 +52,16 @@ def u(v):
self.os = u(os.name)

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

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

self.executable = u(sys.executable) # the executable we were invoked via
self.original_executable = u(self.executable) # the executable as known by the interpreter
self.executable = u(abs_path(sys.executable)) # the executable we were invoked via
self.original_executable = u(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 Expand Up @@ -413,10 +416,6 @@ def _find_possible_folders(self, inside_folder):

# or at root level
candidate_folder[inside_folder] = None
if self.executable.startswith(self.prefix):
binary_within = os.path.relpath(os.path.dirname(self.executable), self.prefix)
candidate_folder[os.path.join(inside_folder, binary_within)] = None

return list(candidate_folder.keys())

def _find_possible_exe_names(self):
Expand Down
8 changes: 0 additions & 8 deletions src/virtualenv/run/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import logging

import six

from ..config.cli.parser import VirtualEnvConfigParser
from ..report import LEVELS, setup_report
from ..session import Session
Expand All @@ -22,12 +20,6 @@ def run_via_cli(args, options=None):
"""
session = session_via_cli(args, options)
session.run()

logging.warning(
"created virtual environment %s with seeder %s",
six.ensure_text(str(session.creator)),
six.ensure_text(str(session.seeder)),
)
return session


Expand Down

0 comments on commit 80fe52f

Please sign in to comment.