Skip to content

Commit 47476e1

Browse files
authored
#1227 fix crash when proposed base python has no version data (#1229)
1 parent 14c0bee commit 47476e1

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

docs/changelog/1227.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
don't crash when version information is not available for a proposed base python - by :user:`gaborbernat`

src/tox/config/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -561,21 +561,23 @@ def basepython_default(testenv_config, value):
561561
proposed_python = (implied_python or sys.executable) if value is None else str(value)
562562
if implied_python is not None and implied_python != proposed_python:
563563
testenv_config.basepython = proposed_python
564-
implied_version = tox.PYTHON.PY_FACTORS_RE.match(factor).group(2)
565-
python_info_for_proposed = testenv_config.python_info
566-
if not isinstance(python_info_for_proposed, NoInterpreterInfo):
567-
proposed_version = "".join(
568-
str(i) for i in python_info_for_proposed.version_info[0:2]
569-
)
570-
# '27'.startswith('2') or '27'.startswith('27')
571-
if not proposed_version.startswith(implied_version):
572-
# TODO(stephenfin): Raise an exception here in tox 4.0
573-
warnings.warn(
574-
"conflicting basepython version (set {}, should be {}) for env '{}';"
575-
"resolve conflict or set ignore_basepython_conflict".format(
576-
proposed_version, implied_version, testenv_config.envname
577-
)
564+
match = tox.PYTHON.PY_FACTORS_RE.match(factor)
565+
implied_version = match.group(2) if match else None
566+
if implied_version is not None:
567+
python_info_for_proposed = testenv_config.python_info
568+
if not isinstance(python_info_for_proposed, NoInterpreterInfo):
569+
proposed_version = "".join(
570+
str(i) for i in python_info_for_proposed.version_info[0:2]
578571
)
572+
# '27'.startswith('2') or '27'.startswith('27')
573+
if not proposed_version.startswith(implied_version):
574+
# TODO(stephenfin): Raise an exception here in tox 4.0
575+
warnings.warn(
576+
"conflicting basepython version (set {}, should be {}) for env '{}';"
577+
"resolve conflict or set ignore_basepython_conflict".format(
578+
proposed_version, implied_version, testenv_config.envname
579+
)
580+
)
579581
return proposed_python
580582

581583
parser.add_testenv_attribute(

tests/unit/config/test_config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3061,3 +3061,17 @@ def test_posargs_relative_changedir(newconfig, tmpdir):
30613061
dir1.strpath,
30623062
"dir3",
30633063
]
3064+
3065+
3066+
def test_config_no_version_data_in__name(newconfig, capsys):
3067+
newconfig(
3068+
"""
3069+
[tox]
3070+
envlist = py, pypy, jython
3071+
[testenv]
3072+
basepython = python
3073+
"""
3074+
)
3075+
out, err = capsys.readouterr()
3076+
assert not out
3077+
assert not err

0 commit comments

Comments
 (0)