From aca2fb563b363c0dbdaf7f0242f0d3745ec661ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Thu, 27 Aug 2020 16:35:19 +0100 Subject: [PATCH] hooks: implement custom tox_runenvreport without a pip dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gets rid of the pip dependency, undesirable in some cases. Signed-off-by: Filipe LaĆ­ns --- setup.py | 1 + src/tox_current_env/hooks.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/setup.py b/setup.py index 63ddc01..920f2ac 100644 --- a/setup.py +++ b/setup.py @@ -24,6 +24,7 @@ setup( # but the one downloaded from PyPI isn't and it doesn't work properly. "tox>=3.15; python_version >= '3.8'", "tox>=3.13; python_version < '3.8'", + "importlib_metadata; python_version < '3.8'" ], python_requires=">=3.6", classifiers=[ diff --git a/src/tox_current_env/hooks.py b/src/tox_current_env/hooks.py index f04ad67..695f320 100644 --- a/src/tox_current_env/hooks.py +++ b/src/tox_current_env/hooks.py @@ -4,6 +4,11 @@ import subprocess import sys import tox +try: + import importlib.metadata as importlib_metadata +except ImportError: + import importlib_metadata + @tox.hookimpl def tox_addoption(parser): @@ -185,3 +190,13 @@ def tox_cleanup(session): for venv in session.venv_dict.values(): if is_current_env_link(venv): rm_venv(venv) + + +@tox.hookimpl +def tox_runenvreport(venv, action): + if not venv.envconfig.config.option.current_env: + return None + return ( + "{}=={}".format(d.metadata.get("name"), d.version) + for d in importlib_metadata.distributions() + )