diff options
author | Bernát Gábor <bgabor8@bloomberg.net> | 2021-09-11 21:17:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-11 21:17:08 +0100 |
commit | 9d1a46a624862347959c22bab7e0c35dcf37187a (patch) | |
tree | 4e3773788aea04165b11664fcd73261ecf28c3d8 /src/tox/plugin | |
parent | 48da3664ecfee2173838f6604e73f48d579e56ce (diff) | |
download | tox-git-9d1a46a624862347959c22bab7e0c35dcf37187a.tar.gz |
Support for plugin before and after, fix ASCII report fails (#2214)
Diffstat (limited to 'src/tox/plugin')
-rw-r--r-- | src/tox/plugin/manager.py | 11 | ||||
-rw-r--r-- | src/tox/plugin/spec.py | 34 |
2 files changed, 39 insertions, 6 deletions
diff --git a/src/tox/plugin/manager.py b/src/tox/plugin/manager.py index 786d9819..f173743d 100644 --- a/src/tox/plugin/manager.py +++ b/src/tox/plugin/manager.py @@ -1,5 +1,6 @@ """Contains the plugin manager object""" from pathlib import Path +from typing import List import pluggy @@ -16,6 +17,8 @@ from tox.tox_env.python.virtual_env.package import api from tox.tox_env.register import REGISTER, ToxEnvRegister from ..config.main import Config +from ..execute import Outcome +from ..tox_env.api import ToxEnv from . import NAME, spec from .inline import load_inline @@ -58,9 +61,15 @@ class Plugin: def tox_configure(self, config: Config) -> None: self.manager.hook.tox_configure(config=config) - def tox_register_tox_env(self, register: "ToxEnvRegister") -> None: + def tox_register_tox_env(self, register: ToxEnvRegister) -> None: self.manager.hook.tox_register_tox_env(register=register) + def tox_before_run_commands(self, tox_env: ToxEnv) -> None: + self.manager.hook.tox_before_run_commands(tox_env=tox_env) + + def tox_after_run_commands(self, tox_env: ToxEnv, exit_code: int, outcomes: List[Outcome]) -> None: + self.manager.hook.tox_after_run_commands(tox_env=tox_env, exit_code=exit_code, outcomes=outcomes) + def load_inline_plugin(self, path: Path) -> None: result = load_inline(path) if result is not None: diff --git a/src/tox/plugin/spec.py b/src/tox/plugin/spec.py index 4ad80529..1e772f38 100644 --- a/src/tox/plugin/spec.py +++ b/src/tox/plugin/spec.py @@ -1,5 +1,4 @@ -from argparse import ArgumentParser -from typing import Any, Callable, TypeVar, cast +from typing import Any, Callable, List, TypeVar, cast import pluggy @@ -7,6 +6,9 @@ from tox.config.main import Config from tox.config.sets import ConfigSet from tox.tox_env.register import ToxEnvRegister +from ..config.cli.parser import ToxParser +from ..execute import Outcome +from ..tox_env.api import ToxEnv from . import NAME _F = TypeVar("_F", bound=Callable[..., Any]) @@ -30,7 +32,7 @@ def tox_register_tox_env(register: ToxEnvRegister) -> None: # noqa: U100 @_spec -def tox_add_option(parser: ArgumentParser) -> None: # noqa: U100 +def tox_add_option(parser: ToxParser) -> None: # noqa: U100 """ Add a command line argument. This is the first hook to be called, right after the logging setup and config source discovery. @@ -58,10 +60,32 @@ def tox_configure(config: Config) -> None: # noqa: U100 """ -__all__ = ( +@_spec +def tox_before_run_commands(tox_env: ToxEnv) -> None: # noqa: U100 + """ + Called before the commands set is executed. + + :param tox_env: the tox environment being executed + """ + + +@_spec +def tox_after_run_commands(tox_env: ToxEnv, exit_code: int, outcomes: List[Outcome]) -> None: # noqa: U100 + """ + Called after the commands set is executed. + + :param tox_env: the tox environment being executed + :param exit_code: exit code of the command + :param outcomes: outcome of each command execution + """ + + +__all__ = [ "NAME", "tox_register_tox_env", "tox_add_option", "tox_add_core_config", "tox_configure", -) + "tox_before_run_commands", + "tox_after_run_commands", +] |