From 84ed60250254b854dc05dca63a81a88159bb3dc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Fri, 26 Jul 2019 13:35:26 +0200 Subject: [PATCH] Move block of code a bit above (no chnages) --- src/tox_current_env/hooks.py | 62 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index 93f2792..e23040e 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -37,6 +37,37 @@ class InterpreterMismatch(tox.exception.InterpreterNotFound): """Interpreter version in current env does not match requested version""" +def _python_activate_exists(venv): + python = venv.envconfig.get_envpython() + bindir = os.path.dirname(python) + activate = os.path.join(bindir, "activate") + return os.path.exists(python), os.path.exists(activate) + + +def is_current_env_link(venv): + python, activate = _python_activate_exists(venv) + return python and not activate + + +def is_proper_venv(venv): + python, activate = _python_activate_exists(venv) + return python and activate + + +def unsupported_raise(config, venv): + if config.option.recreate: + return + regular = not (config.option.current_env or config.option.print_deps_only) + if regular and is_current_env_link(venv): + raise tox.exception.ConfigError( + "Regular tox run after --current-env or --print-deps-only tox run is not supported without --recreate (-r)." + ) + elif config.option.current_env and is_proper_venv(venv): + raise tox.exception.ConfigError( + "--current-env after regular tox run is not supported without --recreate (-r)." + ) + + @tox.hookimpl def tox_testenv_create(venv, action): """We create a fake virtualenv with just the symbolic link""" @@ -70,37 +101,6 @@ def tox_testenv_create(venv, action): return None # let tox handle the rest -def _python_activate_exists(venv): - python = venv.envconfig.get_envpython() - bindir = os.path.dirname(python) - activate = os.path.join(bindir, "activate") - return os.path.exists(python), os.path.exists(activate) - - -def is_current_env_link(venv): - python, activate = _python_activate_exists(venv) - return python and not activate - - -def is_proper_venv(venv): - python, activate = _python_activate_exists(venv) - return python and activate - - -def unsupported_raise(config, venv): - if config.option.recreate: - return - regular = not (config.option.current_env or config.option.print_deps_only) - if regular and is_current_env_link(venv): - raise tox.exception.ConfigError( - "Regular tox run after --current-env or --print-deps-only tox run is not supported without --recreate (-r)." - ) - elif config.option.current_env and is_proper_venv(venv): - raise tox.exception.ConfigError( - "--current-env after regular tox run is not supported without --recreate (-r)." - ) - - @tox.hookimpl def tox_testenv_install_deps(venv, action): """We don't install anything"""