1
0
mirror of https://github.com/fedora-python/tox-current-env.git synced 2025-01-11 08:56:14 +01:00

Support report of installed packages in CI (#64)

* Support report of installed packages in CI

Fixes: https://github.com/fedora-python/tox-current-env/issues/63

Co-authored-by: Miro Hrončok <miro@hroncok.cz>
This commit is contained in:
Lumír 'Frenzy' Balhar 2023-01-07 11:40:07 +01:00 committed by GitHub
parent bf900a5c7c
commit daf3872164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View File

@ -15,6 +15,11 @@ from tox.plugin import impl
from tox.tox_env.python.api import PythonInfo
from tox.tox_env.python.runner import PythonRun
try:
import importlib.metadata as importlib_metadata
except ImportError:
import importlib_metadata
@impl
def tox_register_tox_env(register):
@ -106,6 +111,15 @@ class Installer:
def install(self, *args, **kwargs):
return None
def installed(self):
"""Return list of installed packages like `pip freeze`."""
return [
"{}=={}".format(d.metadata.get("name"), d.version)
for d in sorted(
importlib_metadata.distributions(), key=lambda d: d.metadata.get("name")
)
]
class CurrentEnvLocalSubProcessExecutor(Execute):
def build_instance(

View File

@ -421,3 +421,12 @@ def test_pass_env(projdir, pass_env):
assert result.returncode == 0
assert "\nassertme\n" in result.stdout
assert "\nNone\n" not in result.stdout
def test_report_installed(projdir):
# tox4 only reports installed when a CI is detected
env = {"CI": "true"}
result = tox("-e", NATIVE_TOXENV, "--current-env", env=env, quiet=False)
assert result.returncode == 0
assert "tox==" in result.stdout
assert "pytest==" in result.stdout