Skip to content

Commit 9591fc2

Browse files
authored
Add --list-dependencies options (#3024)
1 parent 7165642 commit 9591fc2

File tree

6 files changed

+41
-5
lines changed

6 files changed

+41
-5
lines changed

docs/changelog/3024.feature.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Addded ``--list-dependencies`` and ``--no-list-dependencies`` CLI parameters.
2+
If unspecified, defaults to listing when in CI, but not otherwise.

src/tox/session/cmd/run/common.py

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from tox.session.state import State
2323
from tox.tox_env.api import ToxEnv
2424
from tox.tox_env.runner import RunToxEnv
25+
from tox.util.ci import is_ci
2526
from tox.util.graph import stable_topological_sort
2627
from tox.util.spinner import MISS_DURATION, Spinner
2728

@@ -156,6 +157,19 @@ def __call__(
156157
help="if recreate is set do not recreate packaging tox environment(s)",
157158
action="store_true",
158159
)
160+
list_deps = parser.add_mutually_exclusive_group()
161+
list_deps.add_argument(
162+
"--list-dependencies",
163+
action="store_true",
164+
default=is_ci(),
165+
help="list the dependencies installed during environment setup",
166+
)
167+
list_deps.add_argument(
168+
"--no-list-dependencies",
169+
action="store_false",
170+
dest="list_dependencies",
171+
help="never list the dependencies installed during environment setup",
172+
)
159173
if mode not in ("devenv", "config", "depends"):
160174
parser.add_argument(
161175
"--skip-pkg-install",

src/tox/tox_env/python/api.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from tox.config.main import Config
1616
from tox.tox_env.api import ToxEnv, ToxEnvCreateArgs
1717
from tox.tox_env.errors import Fail, Recreate, Skip
18-
from tox.util.ci import is_ci
1918

2019

2120
class VersionInfo(NamedTuple):
@@ -227,12 +226,11 @@ def prepend_env_var_path(self) -> list[Path]:
227226
def _done_with_setup(self) -> None:
228227
"""called when setup is done"""
229228
super()._done_with_setup()
230-
running_in_ci = is_ci()
231-
if self.journal or running_in_ci:
229+
if self.journal or self.options.list_dependencies:
232230
outcome = self.installer.installed()
233231
if self.journal:
234232
self.journal["installed_packages"] = outcome
235-
if running_in_ci:
233+
if self.options.list_dependencies:
236234
logging.warning(",".join(outcome))
237235

238236
def python_cache(self) -> dict[str, Any]:

tests/config/cli/test_cli_env_var.py

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from tox.pytest import CaptureFixture, LogCaptureFixture, MonkeyPatch
1111
from tox.session.env_select import CliEnv
1212
from tox.session.state import State
13+
from tox.util.ci import is_ci
1314

1415

1516
def test_verbose() -> None:
@@ -63,6 +64,7 @@ def test_verbose_no_test() -> None:
6364
"factors": [],
6465
"labels": [],
6566
"skip_env": "",
67+
"list_dependencies": is_ci(),
6668
}
6769

6870

@@ -121,6 +123,7 @@ def test_env_var_exhaustive_parallel_values(
121123
"labels": [],
122124
"exit_and_dump_after": 0,
123125
"skip_env": "",
126+
"list_dependencies": is_ci(),
124127
}
125128
assert options.parsed.verbosity == 4
126129
assert options.cmd_handlers == core_handlers

tests/config/cli/test_cli_ini.py

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from tox.pytest import CaptureFixture, LogCaptureFixture, MonkeyPatch
2020
from tox.session.env_select import CliEnv
2121
from tox.session.state import State
22+
from tox.util.ci import is_ci
2223

2324

2425
@pytest.fixture()
@@ -102,6 +103,7 @@ def default_options() -> dict[str, Any]:
102103
"labels": [],
103104
"exit_and_dump_after": 0,
104105
"skip_env": "",
106+
"list_dependencies": is_ci(),
105107
}
106108

107109

@@ -139,6 +141,7 @@ def test_ini_exhaustive_parallel_values(core_handlers: dict[str, Callable[[State
139141
"labels": [],
140142
"exit_and_dump_after": 0,
141143
"skip_env": "",
144+
"list_dependencies": is_ci(),
142145
}
143146
assert options.parsed.verbosity == 4
144147
assert options.cmd_handlers == core_handlers

tests/tox_env/python/test_python_api.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,25 @@ def test_python_set_hash_seed_incorrect(tox_project: ToxProjectCreator) -> None:
218218

219219
@pytest.mark.parametrize("in_ci", [True, False])
220220
def test_list_installed_deps(in_ci: bool, tox_project: ToxProjectCreator, mocker: MockerFixture) -> None:
221-
mocker.patch("tox.tox_env.python.api.is_ci", return_value=in_ci)
221+
mocker.patch("tox.session.cmd.run.common.is_ci", return_value=in_ci)
222222
result = tox_project({"tox.ini": "[testenv]\nskip_install = true"}).run("r", "-e", "py")
223223
if in_ci:
224224
assert "pip==" in result.out
225225
else:
226226
assert "pip==" not in result.out
227+
228+
229+
@pytest.mark.parametrize("list_deps", ["--list-dependencies", "--no-list-dependencies"])
230+
@pytest.mark.parametrize("in_ci", [True, False])
231+
def test_list_installed_deps_explicit_cli(
232+
list_deps: str,
233+
in_ci: bool,
234+
tox_project: ToxProjectCreator,
235+
mocker: MockerFixture,
236+
) -> None:
237+
mocker.patch("tox.session.cmd.run.common.is_ci", return_value=in_ci)
238+
result = tox_project({"tox.ini": "[testenv]\nskip_install = true"}).run(list_deps, "r", "-e", "py")
239+
if list_deps == "--list-dependencies":
240+
assert "pip==" in result.out
241+
else:
242+
assert "pip==" not in result.out

0 commit comments

Comments
 (0)