Skip to content

Commit 8d6a324

Browse files
Use {env}/bin instead of {env}/Scripts when Python is from MSYS2 on Windows. (#1983)
1 parent bf9e060 commit 8d6a324

File tree

7 files changed

+33
-1
lines changed

7 files changed

+33
-1
lines changed

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Ionel Maries Cristian
4848
Itxaka Serrano
4949
Jake Windle
5050
Jannis Leidel
51+
Jesse Schwartzentruber
5152
Joachim Brandon LeBlanc
5253
Johannes Christ
5354
John Mark Vandenberg

docs/changelog/1982.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Distinguish between normal Windows Python and MSYS2 Python when looking for
2+
virtualenv executable path. Adds os.sep to :class:`InterpreterInfo`
3+
- by :user:`jschwartzentruber`

src/tox/config/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,11 @@ def get_envbindir(self):
10531053
isinstance(self.python_info, NoInterpreterInfo)
10541054
or tox.INFO.IS_WIN is False
10551055
or self.python_info.implementation == "Jython"
1056+
or (
1057+
# this combination is MSYS2
1058+
tox.INFO.IS_WIN
1059+
and self.python_info.os_sep == "/"
1060+
)
10561061
or (
10571062
tox.INFO.IS_WIN
10581063
and self.python_info.implementation == "PyPy"

src/tox/helper/get_version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import unicode_literals
22

33
import json
4+
import os
45
import platform
56
import sys
67

@@ -11,6 +12,7 @@
1112
"version": sys.version,
1213
"is_64": sys.maxsize > 2 ** 32,
1314
"sysplatform": sys.platform,
15+
"os_sep": os.sep,
1416
"extra_version_info": getattr(sys, "pypy_version_info", None),
1517
}
1618
info_as_dump = json.dumps(info)

src/tox/interpreters/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(
103103
version_info,
104104
sysplatform,
105105
is_64,
106+
os_sep,
106107
extra_version_info,
107108
):
108109
self.implementation = implementation
@@ -111,6 +112,7 @@ def __init__(
111112
self.version_info = version_info
112113
self.sysplatform = sysplatform
113114
self.is_64 = is_64
115+
self.os_sep = os_sep
114116
self.extra_version_info = extra_version_info
115117

116118
def __str__(self):

tests/unit/config/test_config.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,23 @@ def test_envbindir_jython(self, newconfig, bp):
14691469
if bp == "jython":
14701470
assert envconfig.envpython == envconfig.envbindir.join(bp)
14711471

1472+
@pytest.mark.skipif(tox.INFO.IS_PYPY, reason="only applies to CPython")
1473+
@pytest.mark.parametrize("sep, bindir", [("\\", "Scripts"), ("/", "bin")])
1474+
def test_envbindir_win(self, newconfig, monkeypatch, sep, bindir):
1475+
monkeypatch.setattr(tox.INFO, "IS_WIN", True)
1476+
config = newconfig(
1477+
"""
1478+
[testenv]
1479+
basepython=python
1480+
""",
1481+
)
1482+
assert len(config.envconfigs) == 1
1483+
envconfig = config.envconfigs["python"]
1484+
envconfig.python_info.os_sep = sep # force os.sep result
1485+
# on win32 with msys2, virtualenv uses "bin" for python
1486+
assert envconfig.envbindir.basename == bindir
1487+
assert envconfig.envpython == envconfig.envbindir.join("python")
1488+
14721489
@pytest.mark.parametrize("plat", ["win32", "linux2"])
14731490
def test_passenv_as_multiline_list(self, newconfig, monkeypatch, plat):
14741491
monkeypatch.setattr(tox.INFO, "IS_WIN", plat == "win32")

tests/unit/interpreters/test_interpreters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ def info(
192192
version_info="my-version-info",
193193
sysplatform="my-sys-platform",
194194
):
195-
return InterpreterInfo(implementation, executable, version_info, sysplatform, True, None)
195+
return InterpreterInfo(
196+
implementation, executable, version_info, sysplatform, True, "/", None
197+
)
196198

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

0 commit comments

Comments
 (0)