Skip to content

Commit

Permalink
#1227 fix crash when proposed base python has no version data
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat committed Mar 29, 2019
1 parent 14c0bee commit 407121b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions docs/changelog/1227.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
don't crash when version information is not available for a proposed base python - by :user:`gaborbernat`
30 changes: 16 additions & 14 deletions src/tox/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,21 +561,23 @@ def basepython_default(testenv_config, value):
proposed_python = (implied_python or sys.executable) if value is None else str(value)
if implied_python is not None and implied_python != proposed_python:
testenv_config.basepython = proposed_python
implied_version = tox.PYTHON.PY_FACTORS_RE.match(factor).group(2)
python_info_for_proposed = testenv_config.python_info
if not isinstance(python_info_for_proposed, NoInterpreterInfo):
proposed_version = "".join(
str(i) for i in python_info_for_proposed.version_info[0:2]
)
# '27'.startswith('2') or '27'.startswith('27')
if not proposed_version.startswith(implied_version):
# TODO(stephenfin): Raise an exception here in tox 4.0
warnings.warn(
"conflicting basepython version (set {}, should be {}) for env '{}';"
"resolve conflict or set ignore_basepython_conflict".format(
proposed_version, implied_version, testenv_config.envname
)
match = tox.PYTHON.PY_FACTORS_RE.match(factor)
implied_version = match.group(2) if match else None
if implied_version is not None:
python_info_for_proposed = testenv_config.python_info
if not isinstance(python_info_for_proposed, NoInterpreterInfo):
proposed_version = "".join(
str(i) for i in python_info_for_proposed.version_info[0:2]
)
# '27'.startswith('2') or '27'.startswith('27')
if not proposed_version.startswith(implied_version):
# TODO(stephenfin): Raise an exception here in tox 4.0
warnings.warn(
"conflicting basepython version (set {}, should be {}) for env '{}';"
"resolve conflict or set ignore_basepython_conflict".format(
proposed_version, implied_version, testenv_config.envname
)
)
return proposed_python

parser.add_testenv_attribute(
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3061,3 +3061,17 @@ def test_posargs_relative_changedir(newconfig, tmpdir):
dir1.strpath,
"dir3",
]


def test_config_no_version_data_in__name(newconfig, capsys):
newconfig(
"""
[tox]
envlist = py, pypy, jython
[testenv]
basepython = python
"""
)
out, err = capsys.readouterr()
assert not out
assert not err

0 comments on commit 407121b

Please sign in to comment.