Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --list-dependencies options #3024

Merged
merged 7 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/tox/session/cmd/run/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ def __call__(
help="skip package installation for this run",
action="store_true",
)
list_deps = parser.add_mutually_exclusive_group()
lengau marked this conversation as resolved.
Show resolved Hide resolved
list_deps.add_argument(
"--list-dependencies",
action="store_true",
default="auto",
help="list the dependencies installed during environment setup",
)
list_deps.add_argument(
"--no-list-dependencies",
action="store_false",
dest="list_dependencies",
help="never list the dependencies installed during environment setup",
)


def report(start: float, runs: list[ToxEnvRunResult], is_colored: bool, verbosity: int) -> int:
Expand Down
8 changes: 5 additions & 3 deletions src/tox/tox_env/python/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,14 @@ def prepend_env_var_path(self) -> list[Path]:
def _done_with_setup(self) -> None:
"""called when setup is done"""
super()._done_with_setup()
running_in_ci = is_ci()
if self.journal or running_in_ci:
list_deps = self.options.list_dependencies
if list_deps == "auto":
list_deps = is_ci()
if self.journal or list_deps:
outcome = self.installer.installed()
if self.journal:
self.journal["installed_packages"] = outcome
if running_in_ci:
if list_deps:
logging.warning(",".join(outcome))

def python_cache(self) -> dict[str, Any]:
Expand Down
16 changes: 16 additions & 0 deletions tests/tox_env/python/test_python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,19 @@ def test_list_installed_deps(in_ci: bool, tox_project: ToxProjectCreator, mocker
assert "pip==" in result.out
else:
assert "pip==" not in result.out


@pytest.mark.parametrize("list_deps", ["--list-dependencies", "--no-list-dependencies"])
@pytest.mark.parametrize("in_ci", [True, False])
def test_cli_list_installed_deps(
list_deps: str,
in_ci: bool,
tox_project: ToxProjectCreator,
mocker: MockerFixture,
) -> None:
mocker.patch("tox.tox_env.python.api.is_ci", return_value=in_ci)
result = tox_project({"tox.ini": "[testenv]\nskip_install = true"}).run(list_deps, "r", "-e", "py")
if list_deps == "--list-dependencies":
assert "pip==" in result.out
else:
assert "pip==" not in result.out