Skip to content

Commit

Permalink
Add a collapsible group for installation preliminaries tox-dev#67
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jul 21, 2023
1 parent f869574 commit 0fc0a8c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/tox_gh/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pathlib
import shutil
import sys
from typing import TYPE_CHECKING, Dict
from typing import TYPE_CHECKING, Any, Dict

from tox.config.loader.memory import MemoryLoader
from tox.config.loader.section import Section
Expand Down Expand Up @@ -80,14 +80,37 @@ def tox_add_core_config(core_conf: ConfigSet, state: State) -> None:
state.conf.core.loaders.insert(0, MemoryLoader(env_list=env_list))


installing = False


@impl
def tox_on_install(tox_env: ToxEnv, arguments: Any, section: str, of_type: str) -> None: # noqa: ANN401, ARG001
"""
Run before installing to prepare an environment.
:param tox_env: the tox environment
:param arguments: installation arguments
:param section: section of the installation
:param of_type: type of the installation
"""
global installing # noqa: PLW0603
if tox_env.core["is_on_gh_action"] and not installing:
installing = True
print("::group::tox:install") # noqa: T201


@impl
def tox_before_run_commands(tox_env: ToxEnv) -> None:
def tox_before_run_commands(tox_env: ToxEnv) -> None: # noqa: ARG001
"""
Run logic before tox run commands.
:param tox_env: the tox environment
"""
global installing # noqa: PLW0603
if tox_env.core["is_on_gh_action"]:
assert installing # noqa: S101
installing = False
print("::endgroup::") # noqa: T201
print(f"::group::tox:{tox_env.name}") # noqa: T201


Expand Down
8 changes: 8 additions & 0 deletions tests/test_tox_gh.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ def test_gh_ok(monkeypatch: MonkeyPatch, tox_project: ToxProjectCreator, tmp_pat
assert result.out.splitlines() == [
"ROOT: running tox-gh",
"ROOT: tox-gh set a, b",
"::group::tox:install",
"a: freeze> python -m pip freeze --all",
ANY, # freeze list
"::endgroup::",
"::group::tox:a",
"::endgroup::",
ANY, # a finished
"::group::tox:install",
"b: freeze> python -m pip freeze --all",
ANY, # freeze list
"::endgroup::",
"::group::tox:b",
"::endgroup::",
ANY, # a status
Expand Down Expand Up @@ -101,15 +105,19 @@ def test_gh_fail(monkeypatch: MonkeyPatch, tox_project: ToxProjectCreator, tmp_p
assert result.out.splitlines() == [
"ROOT: running tox-gh",
"ROOT: tox-gh set a, b",
"::group::tox:install",
"a: freeze> python -m pip freeze --all",
ANY, # freeze list
"::endgroup::",
"::group::tox:a",
ANY, # "a: commands[0]> python -c 'exit(1)'", but without the quotes on Windows.
ANY, # process details
"::endgroup::",
ANY, # a finished
"::group::tox:install",
"b: freeze> python -m pip freeze --all",
ANY, # freeze list
"::endgroup::",
"::group::tox:b",
ANY, # "b: commands[0]> python -c 'exit(1)'", but without the quotes on Windows.
ANY, # b process details
Expand Down

0 comments on commit 0fc0a8c

Please sign in to comment.