From 4eaf4325452dce8d9997391934bfcbc57d8a473f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Wed, 17 Jul 2019 15:42:23 +0200 Subject: [PATCH] Very rough implementation --- src/tox_current_env/hooks.py | 62 +++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index 3d625ce..42dd14a 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -1,6 +1,66 @@ +import os +import shutil +import sys import tox +@tox.hookimpl +def tox_addoption(parser): + parser.add_argument( + "--current-env", + action="store_true", + dest="current_env", + default=False, + help="Run tests in current environment, not creating any virtual environment", + ) + parser.add_argument( + "--print-deps-only", + action="store_true", + dest="print_deps_only", + default=False, + help="Don't run tests, only print the dependencies", + ) + + +@tox.hookimpl +def tox_configure(config): + """Stores a global varibale with current_env option. + Makes all commands external""" + if config.option.print_deps_only: + config.skipsdist = True + elif config.option.current_env: + config.option.recreate = True + config.skipsdist = True + for testenv in config.envconfigs: + config.envconfigs[testenv].whitelist_externals = "*" + + return config + + @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: + link = venv.envconfig.get_envpython() + target = sys.executable + shutil.rmtree(os.path.dirname(link), ignore_errors=True) + os.makedirs(os.path.dirname(link)) + os.symlink(target, link) + return True + + +@tox.hookimpl +def tox_testenv_install_deps(venv, action): + """We don't install anything""" + config = venv.envconfig.config + if config.option.current_env or config.option.print_deps_only: + return True + + +@tox.hookimpl +def tox_runtest(venv, redirect): + if venv.envconfig.config.option.print_deps_only: + for depndency in venv.get_resolved_dependencies(): + print(depndency) + return True