Skip to content

Commit e2ce869

Browse files
committed
Fix using platform with install_command
Fixes tox-dev#1464
1 parent 7c103c8 commit e2ce869

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

docs/changelog/1464.bugfix.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix ``platform`` support for ``install_command``. - by :user:`jayvdb`

src/tox/config/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,13 @@ def getargv(self, name, default="", replace=True):
16841684

16851685
def getargv_install_command(self, name, default="", replace=True):
16861686
s = self.getstring(name, default, replace=False)
1687+
if not s:
1688+
# This occurs when factors are used, and a testenv doesnt have
1689+
# a factorised value for install_command, most commonly occurring
1690+
# if setting platform is also used.
1691+
# An empty value causes error install_command must contain '{packages}'.
1692+
s = default
1693+
16871694
if "{packages}" in s:
16881695
s = s.replace("{packages}", r"\{packages\}")
16891696
if "{opts}" in s:

tests/unit/config/test_config.py

+91
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,97 @@ def test_config_parse_platform_with_factors(self, newconfig, plat):
248248
expected = {"win": "win32", "lin": "linux2", "osx": ""}.get(plat)
249249
assert platform == expected
250250

251+
def test_platform_install_command(self, newconfig, mocksession, monkeypatch):
252+
# Expanded from docs/example/platform.html
253+
config = newconfig(
254+
[],
255+
"""
256+
[tox]
257+
envlist = py{27,36}-{mylinux,mymacos,mywindows}
258+
259+
[testenv]
260+
platform =
261+
mylinux: linux
262+
mymacos: darwin
263+
mywindows: win32
264+
265+
deps =
266+
mylinux,mymacos: py==1.4.32
267+
mywindows: py==1.4.30
268+
269+
install_command =
270+
mylinux: python -m pip install {packages} distro
271+
mywindows: python -m pip install {packages} pywin32
272+
273+
commands=
274+
mylinux: echo Linus
275+
mymacos: echo Steve
276+
mywindows: echo Bill
277+
""",
278+
)
279+
mocksession.config = config
280+
assert len(config.envconfigs) == 6
281+
282+
monkeypatch.setattr(sys, "platform", "linux")
283+
284+
venv = mocksession.getvenv("py27-mylinux")
285+
assert venv.envconfig._reader.factors == {"py27", "mylinux"}
286+
assert venv.matching_platform()
287+
assert str(venv.envconfig.deps[0]) == "py==1.4.32"
288+
assert venv.envconfig.install_command == [
289+
"python",
290+
"-m",
291+
"pip",
292+
"install",
293+
"{packages}",
294+
"distro",
295+
]
296+
assert venv.envconfig.commands[0] == ["echo", "Linus"]
297+
298+
venv = mocksession.getvenv("py27-mymacos")
299+
assert venv.envconfig._reader.factors == {"py27", "mymacos"}
300+
assert not venv.matching_platform()
301+
assert str(venv.envconfig.deps[0]) == "py==1.4.32"
302+
assert venv.envconfig.install_command == [
303+
"python",
304+
"-m",
305+
"pip",
306+
"install",
307+
"{opts}",
308+
"{packages}",
309+
]
310+
assert venv.envconfig.commands[0] == ["echo", "Steve"]
311+
312+
venv = mocksession.getvenv("py27-mywindows")
313+
assert venv.envconfig._reader.factors == {"py27", "mywindows"}
314+
assert not venv.matching_platform()
315+
assert str(venv.envconfig.deps[0]) == "py==1.4.30"
316+
assert venv.envconfig.install_command == [
317+
"python",
318+
"-m",
319+
"pip",
320+
"install",
321+
"{packages}",
322+
"pywin32",
323+
]
324+
assert venv.envconfig.commands[0] == ["echo", "Bill"]
325+
326+
monkeypatch.undo()
327+
328+
monkeypatch.setattr(sys, "platform", "darwin")
329+
330+
venv = mocksession.getvenv("py27-mymacos")
331+
assert venv.envconfig.install_command == [
332+
"python",
333+
"-m",
334+
"pip",
335+
"install",
336+
"{opts}",
337+
"{packages}",
338+
]
339+
340+
monkeypatch.undo()
341+
251342

252343
class TestConfigPackage:
253344
def test_defaults(self, tmpdir, newconfig):

0 commit comments

Comments
 (0)