Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix system executable discovery #1550

Merged
merged 3 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/1552.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Virtual environments created via relative path on Windows creates bad console executables - by :user:`gaborbernat`.
2 changes: 2 additions & 0 deletions docs/changelog/1553.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Seems sometimes venvs created set their base executable to themselves; we accept these without question, so we handle
virtual environments as system pythons causing issues - by :user:`gaborbernat`.
2 changes: 1 addition & 1 deletion src/virtualenv/create/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def non_write_able(dest, value):
# pre 3.6 resolve is always strict, aka must exists, sidestep by using os.path operation
dest = Path(os.path.realpath(raw_value))
else:
dest = value.resolve()
dest = value.resolve().absolute() # on Windows absolute does not imply resolve so use both
value = dest
while dest:
if dest.exists():
Expand Down
3 changes: 2 additions & 1 deletion src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def _fast_get_system_executable(self):
if self.real_prefix is None:
base_executable = getattr(sys, "_base_executable", None) # some platforms may set this to help us
if base_executable is not None: # use the saved system executable if present
return base_executable
if sys.executable != base_executable: # we know we're in a virtual environment, cannot be us
return base_executable
return None # in this case we just can't tell easily without poking around FS and calling them, bail
# if we're not in a virtual environment, this is already a system python, so return the original executable
# note we must choose the original and not the pure executable as shim scripts might throw us off
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/create/test_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import six

from virtualenv.__main__ import run
from virtualenv.create.creator import DEBUG_SCRIPT, get_env_debug_info
from virtualenv.create.creator import DEBUG_SCRIPT, Creator, get_env_debug_info
from virtualenv.discovery.builtin import get_interpreter
from virtualenv.discovery.py_info import PythonInfo
from virtualenv.info import IS_PYPY, fs_supports_symlink
Expand Down Expand Up @@ -291,3 +291,9 @@ def create(count):
thread.start()
for thread in threads:
thread.join()


def test_creator_input_passed_is_abs(tmp_path, monkeypatch):
monkeypatch.chdir(tmp_path)
result = Creator.validate_dest("venv")
assert str(result) == str(tmp_path / "venv")