Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1227 fix crash when proposed base python has no version data #1229

Merged
merged 1 commit into from
Mar 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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