From dc47ce3ddf53c2b950f0a776ea6ebcc7355e3522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 13 Jan 2020 00:33:21 +0100 Subject: [PATCH] Remove duplicate code and only delete venv if needed There is no associated issue. I was juts reading the code and noticed those two related things. --- src/tox_current_env/hooks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index a44bc77..2dd90b9 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -132,13 +132,14 @@ def tox_testenv_create(venv, action): # Remove the rest of the virtualenv. link = venv.envconfig.get_envpython() target = sys.executable - shutil.rmtree(os.path.dirname(os.path.dirname(link)), ignore_errors=True) + rm_venv(venv) os.makedirs(os.path.dirname(link)) os.symlink(target, link) + # prevent tox from creating the venv return True - else: + if not is_proper_venv(venv): rm_venv(venv) - return None # let tox handle the rest + return None # let tox handle the rest @tox.hookimpl