Skip to content

Commit f570794

Browse files
stephenfingaborbernat
authored andcommitted
Support multiple versions of pypy (#19) (#843)
As with cpython, we can now support pypy2, pypy27 etc. Closes: #19
1 parent 48caca2 commit f570794

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

changelog/19.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Add support for multiple PyPy versions using default factors. This allows you
2+
to use, for example, ``pypy27`` knowing that the correct intepreter will be
3+
used by default - by @stephenfin

tests/test_config.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,12 +1817,16 @@ def test_correct_basepython_chosen_from_default_factors(self, newconfig):
18171817
basepython = config.envconfigs[name].basepython
18181818
if name == "jython":
18191819
assert basepython == "jython"
1820-
elif name.startswith("pypy"):
1821-
assert basepython == name
1820+
elif name in ("pypy2", "pypy3"):
1821+
assert basepython == "pypy" + name[-1]
18221822
elif name in ("py2", "py3"):
18231823
assert basepython == "python" + name[-1]
1824+
elif name == "pypy":
1825+
assert basepython == name
18241826
elif name == "py":
18251827
assert "python" in basepython or "pypy" in basepython
1828+
elif "pypy" in name:
1829+
assert basepython == "pypy{}.{}".format(name[-2], name[-1])
18261830
else:
18271831
assert name.startswith("py")
18281832
assert basepython == "python{}.{}".format(name[2], name[3])
@@ -2341,10 +2345,10 @@ def test_listenvs(self, cmd, initproj):
23412345
filedefs={
23422346
"tox.ini": """
23432347
[tox]
2344-
envlist=py36,py27,py34,pypy,docs
2348+
envlist=py36,py27,py34,pypi,docs
23452349
description= py27: run pytest on Python 2.7
23462350
py34: run pytest on Python 3.6
2347-
pypy: publish to pypy
2351+
pypi: publish to PyPI
23482352
docs: document stuff
23492353
notincluded: random extra
23502354
@@ -2357,20 +2361,20 @@ def test_listenvs(self, cmd, initproj):
23572361
},
23582362
)
23592363
result = cmd("-l")
2360-
assert result.outlines == ["py36", "py27", "py34", "pypy", "docs"]
2364+
assert result.outlines == ["py36", "py27", "py34", "pypi", "docs"]
23612365

23622366
def test_listenvs_verbose_description(self, cmd, initproj):
23632367
initproj(
23642368
"listenvs_verbose_description",
23652369
filedefs={
23662370
"tox.ini": """
23672371
[tox]
2368-
envlist=py36,py27,py34,pypy,docs
2372+
envlist=py36,py27,py34,pypi,docs
23692373
[testenv]
23702374
description= py36: run pytest on Python 3.6
23712375
py27: run pytest on Python 2.7
23722376
py34: run pytest on Python 3.4
2373-
pypy: publish to pypy
2377+
pypi: publish to PyPI
23742378
docs: document stuff
23752379
notincluded: random extra
23762380
@@ -2389,7 +2393,7 @@ def test_listenvs_verbose_description(self, cmd, initproj):
23892393
"py36 -> run pytest on Python 3.6",
23902394
"py27 -> run pytest on Python 2.7",
23912395
"py34 -> run pytest on Python 3.4",
2392-
"pypy -> publish to pypy",
2396+
"pypi -> publish to PyPI",
23932397
"docs -> let me overwrite that",
23942398
]
23952399
assert result.outlines[2:] == expected
@@ -2400,7 +2404,7 @@ def test_listenvs_all(self, cmd, initproj):
24002404
filedefs={
24012405
"tox.ini": """
24022406
[tox]
2403-
envlist=py36,py27,py34,pypy,docs
2407+
envlist=py36,py27,py34,pypi,docs
24042408
24052409
[testenv:notincluded]
24062410
changedir = whatever
@@ -2411,7 +2415,7 @@ def test_listenvs_all(self, cmd, initproj):
24112415
},
24122416
)
24132417
result = cmd("-a")
2414-
expected = ["py36", "py27", "py34", "pypy", "docs", "notincluded"]
2418+
expected = ["py36", "py27", "py34", "pypi", "docs", "notincluded"]
24152419
assert result.outlines == expected
24162420

24172421
def test_listenvs_all_verbose_description(self, cmd, initproj):

tox/constants.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
import sys as _sys
66

77

8-
def _construct_default_factors(version_tuples, other_interpreters):
8+
def _construct_default_factors(cpython_versions, pypy_versions, other_interpreters):
99
default_factors = {"py": _sys.executable, "py2": "python2", "py3": "python3"}
1010
default_factors.update(
1111
{
1212
"py{}{}".format(major, minor): "python{}.{}".format(major, minor)
13-
for major, minor in version_tuples
13+
for major, minor in cpython_versions
14+
}
15+
)
16+
default_factors.update({exc: exc for exc in ["pypy", "pypy2", "pypy3"]})
17+
default_factors.update(
18+
{
19+
"pypy{}{}".format(major, minor): "pypy{}.{}".format(major, minor)
20+
for major, minor in pypy_versions
1421
}
1522
)
1623
default_factors.update({interpreter: interpreter for interpreter in other_interpreters})
@@ -19,8 +26,11 @@ def _construct_default_factors(version_tuples, other_interpreters):
1926

2027
class PYTHON:
2128
CPYTHON_VERSION_TUPLES = [(2, 7), (3, 4), (3, 5), (3, 6), (3, 7)]
22-
OTHER_PYTHON_INTERPRETERS = ["jython", "pypy", "pypy3"]
23-
DEFAULT_FACTORS = _construct_default_factors(CPYTHON_VERSION_TUPLES, OTHER_PYTHON_INTERPRETERS)
29+
PYPY_VERSION_TUPLES = [(2, 7), (3, 5)]
30+
OTHER_PYTHON_INTERPRETERS = ["jython"]
31+
DEFAULT_FACTORS = _construct_default_factors(
32+
CPYTHON_VERSION_TUPLES, PYPY_VERSION_TUPLES, OTHER_PYTHON_INTERPRETERS
33+
)
2434
CURRENT_RELEASE_ENV = "py36"
2535
"""Should hold currently released py -> for easy updating"""
2636
QUICKSTART_PY_ENVS = ["py27", "py34", "py35", CURRENT_RELEASE_ENV, "pypy", "jython"]

0 commit comments

Comments
 (0)