diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de8dd5..4957715 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,16 @@ Types of changes are: ## [Unreleased] +## [0.15.0] - 2022-08-23 + +### Added + +- A new configuration field `verify_commands` can be configured to fine-tune which commands are run as part of `verify-all` + +### Changed + +- The `verify-all` command now respects overridden commands and disabled commands + ## [0.14.0] - 2022-07-08 ### Added diff --git a/pyproject.toml b/pyproject.toml index e651568..32af53c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "delfino" -version = "0.14.0" +version = "0.15.0" description = "A collection of command line helper scripts wrapping tools used during Python development." authors = ["Radek Lát "] license = "MIT License" diff --git a/src/delfino/click_utils/command.py b/src/delfino/click_utils/command.py index 3d18f27..8fb21bf 100644 --- a/src/delfino/click_utils/command.py +++ b/src/delfino/click_utils/command.py @@ -1,6 +1,6 @@ from importlib import import_module, resources from importlib.resources import Package -from typing import Dict, List +from typing import Dict, List, cast import click @@ -41,3 +41,13 @@ def find_commands(package: Package, *, required: bool, new_name: str = "") -> Di click.secho(f"⚠ Plugin module '{package}' is deprecated. Please use '{new_name}' instead.", fg="yellow") return commands + + +def get_root_command(click_context: click.Context) -> click.MultiCommand: + """Find the root command. + + In the context of `delfino`, this is generally the ``main.Commands`` instance. + """ + while click_context.parent: + click_context = click_context.parent + return cast(click.MultiCommand, click_context.command) diff --git a/src/delfino/commands/verify_all.py b/src/delfino/commands/verify_all.py index 1fa0593..cf47aab 100644 --- a/src/delfino/commands/verify_all.py +++ b/src/delfino/commands/verify_all.py @@ -1,16 +1,34 @@ +from typing import Dict, cast + import click -from delfino.click_utils.command import command_names +from delfino.click_utils.command import get_root_command from delfino.commands.format import run_format from delfino.commands.lint import lint from delfino.commands.test import test_all from delfino.commands.typecheck import typecheck +from delfino.contexts import AppContext, pass_app_context _COMMANDS = [run_format, lint, typecheck, test_all] -@click.command(help=f"Runs all checks.\n\nAlias for the {command_names(_COMMANDS)} commands.") +@click.command(help="Runs all verification commands. Configured by the ``verify_commands`` setting.") @click.pass_context -def verify_all(click_context: click.Context): - for command in _COMMANDS: +@pass_app_context +def verify_all(click_context: click.Context, app_context: AppContext): + delfino = app_context.pyproject_toml.tool.delfino + + root = get_root_command(click_context) + commands: Dict[str, click.Command] = { + command: cast(click.Command, root.get_command(click_context, command)) + for command in root.list_commands(click_context) + } + + target_commands = [ + commands[target_name] + for target_name in delfino.verify_commands + if target_name in commands and target_name not in delfino.disable_commands + ] + + for command in target_commands: click_context.forward(command) diff --git a/src/delfino/models/pyproject_toml.py b/src/delfino/models/pyproject_toml.py index 39fbece..c003fe2 100644 --- a/src/delfino/models/pyproject_toml.py +++ b/src/delfino/models/pyproject_toml.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import Any, Dict, List, Optional, Set +from typing import Any, Dict, List, Optional, Set, Tuple from pydantic import BaseModel, Extra, Field @@ -15,6 +15,7 @@ class Delfino(BaseModel): reports_directory: Path = Path("reports") test_types: List[str] = ["unit", "integration"] disable_commands: Set[str] = Field(default_factory=set) + verify_commands: Tuple[str, ...] = ("format", "lint", "typecheck", "test-all") dockerhub: Optional[Dockerhub] = None