From 2857e80ea0dc7bed17fbf9c4847d3210524e9533 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 17 Jul 2019 16:48:12 +0200 Subject: [PATCH] Raise if requested interpreter doesn't match the current one --- src/tox_current_env/hooks.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index d14f90c..c9854b7 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -35,12 +35,22 @@ def tox_configure(config): return config +class InterpreterMismatch(tox.exception.InterpreterNotFound): + """Interpreter version in current env does not match requested version""" @tox.hookimpl def tox_testenv_create(venv, action): """We don't create anything""" config = venv.envconfig.config if config.option.current_env or config.option.print_deps_only: + version_info = venv.envconfig.python_info.version_info + if version_info[:2] != sys.version_info[:2]: + raise InterpreterMismatch( + f'tox_current_env: interpreter versions do not match:\n' + + f' in current env: {tuple(sys.version_info)}\n' + + f' requested: {version_info}', + ) + # Make sure the `python` command on path is sys.executable. # (We might have e.g. /usr/bin/python3, not `python`.) # Remove the rest of the virtualenv.