Skip to content

Commit daf3872

Browse files
Support report of installed packages in CI (#64)
* Support report of installed packages in CI Fixes: #63 Co-authored-by: Miro Hrončok <[email protected]>
1 parent bf900a5 commit daf3872

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/tox_current_env/hooks4.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
from tox.tox_env.python.api import PythonInfo
1616
from tox.tox_env.python.runner import PythonRun
1717

18+
try:
19+
import importlib.metadata as importlib_metadata
20+
except ImportError:
21+
import importlib_metadata
22+
1823

1924
@impl
2025
def tox_register_tox_env(register):
@@ -106,6 +111,15 @@ class Installer:
106111
def install(self, *args, **kwargs):
107112
return None
108113

114+
def installed(self):
115+
"""Return list of installed packages like `pip freeze`."""
116+
return [
117+
"{}=={}".format(d.metadata.get("name"), d.version)
118+
for d in sorted(
119+
importlib_metadata.distributions(), key=lambda d: d.metadata.get("name")
120+
)
121+
]
122+
109123

110124
class CurrentEnvLocalSubProcessExecutor(Execute):
111125
def build_instance(

tests/test_integration_tox4.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,12 @@ def test_pass_env(projdir, pass_env):
421421
assert result.returncode == 0
422422
assert "\nassertme\n" in result.stdout
423423
assert "\nNone\n" not in result.stdout
424+
425+
426+
def test_report_installed(projdir):
427+
# tox4 only reports installed when a CI is detected
428+
env = {"CI": "true"}
429+
result = tox("-e", NATIVE_TOXENV, "--current-env", env=env, quiet=False)
430+
assert result.returncode == 0
431+
assert "tox==" in result.stdout
432+
assert "pytest==" in result.stdout

0 commit comments

Comments
 (0)