Skip to content

Commit

Permalink
Use {env}/bin instead of {env}/Scripts when Python is from MSYS2 …
Browse files Browse the repository at this point in the history
…on Windows.

MSYS2 prefers a Linux filesystem layout, but is otherwise a native
Windows interpreter.

Fixes tox-dev#1982
  • Loading branch information
jschwartzentruber committed Apr 1, 2021
1 parent 1c8fa48 commit bfce0b5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Expand Up @@ -48,6 +48,7 @@ Ionel Maries Cristian
Itxaka Serrano
Jake Windle
Jannis Leidel
Jesse Schwartzentruber
Joachim Brandon LeBlanc
Johannes Christ
John Mark Vandenberg
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog/1982.bugfix.rst
@@ -0,0 +1,3 @@
Distinguish between normal Windows Python and MSYS2 Python when looking for
virtualenv executable path. Adds os.sep to :class:`InterpreterInfo`
- by :user:`jschwartzentruber`
5 changes: 5 additions & 0 deletions src/tox/config/__init__.py
Expand Up @@ -1053,6 +1053,11 @@ def get_envbindir(self):
isinstance(self.python_info, NoInterpreterInfo)
or tox.INFO.IS_WIN is False
or self.python_info.implementation == "Jython"
or (
# this combination is MSYS2
tox.INFO.IS_WIN
and self.python_info.os_sep == "/"
)
or (
tox.INFO.IS_WIN
and self.python_info.implementation == "PyPy"
Expand Down
2 changes: 2 additions & 0 deletions src/tox/helper/get_version.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals

import json
import os
import platform
import sys

Expand All @@ -11,6 +12,7 @@
"version": sys.version,
"is_64": sys.maxsize > 2 ** 32,
"sysplatform": sys.platform,
"os_sep": os.sep,
"extra_version_info": getattr(sys, "pypy_version_info", None),
}
info_as_dump = json.dumps(info)
Expand Down
2 changes: 2 additions & 0 deletions src/tox/interpreters/__init__.py
Expand Up @@ -103,6 +103,7 @@ def __init__(
version_info,
sysplatform,
is_64,
os_sep,
extra_version_info,
):
self.implementation = implementation
Expand All @@ -111,6 +112,7 @@ def __init__(
self.version_info = version_info
self.sysplatform = sysplatform
self.is_64 = is_64
self.os_sep = os_sep
self.extra_version_info = extra_version_info

def __str__(self):
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/config/test_config.py
Expand Up @@ -1469,6 +1469,22 @@ def test_envbindir_jython(self, newconfig, bp):
if bp == "jython":
assert envconfig.envpython == envconfig.envbindir.join(bp)

@pytest.mark.parametrize("sep, bindir", [("\\", "Scripts"), ("/", "bin")])
def test_envbindir_win(self, newconfig, monkeypatch, sep, bindir):
monkeypatch.setattr(tox.INFO, "IS_WIN", True)
config = newconfig(
"""
[testenv]
basepython=python
""",
)
assert len(config.envconfigs) == 1
envconfig = config.envconfigs["python"]
envconfig.python_info.os_sep = sep # force os.sep result
# on win32 with msys2, virtualenv uses "bin" for python
assert envconfig.envbindir.basename == bindir
assert envconfig.envpython == envconfig.envbindir.join("python")

@pytest.mark.parametrize("plat", ["win32", "linux2"])
def test_passenv_as_multiline_list(self, newconfig, monkeypatch, plat):
monkeypatch.setattr(tox.INFO, "IS_WIN", plat == "win32")
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/interpreters/test_interpreters.py
Expand Up @@ -192,7 +192,9 @@ def info(
version_info="my-version-info",
sysplatform="my-sys-platform",
):
return InterpreterInfo(implementation, executable, version_info, sysplatform, True, None)
return InterpreterInfo(
implementation, executable, version_info, sysplatform, True, "/", None
)

def test_data(self):
x = self.info("larry", "moe", "shemp", "curly")
Expand Down

0 comments on commit bfce0b5

Please sign in to comment.