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

Make verify-all respect disabled and overriden commands #22

Merged
merged 3 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "MIT License"
Expand Down
12 changes: 11 additions & 1 deletion src/delfino/click_utils/command.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
26 changes: 22 additions & 4 deletions src/delfino/commands/verify_all.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion src/delfino/models/pyproject_toml.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand Down