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

fix: fix default console output not printing file path #126

Merged
merged 2 commits into from
Oct 29, 2024
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
21 changes: 19 additions & 2 deletions src/erc7730/common/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ def add(self, output: Output) -> None:
assert_never(output.level)

log = f"[{style}]{prefix}"
context = []
if output.file is not None:
context.append(f"{output.file}")
if output.line is not None:
log += f"line {output.line}: "
context.append(f"line {output.line}")
log += ", ".join(context)
if output.title is not None:
log += f"{output.title}: "
log += f"[/{style}]{output.message}"
Expand Down Expand Up @@ -176,7 +180,7 @@ def add(self, output: Output) -> None:
builtin_print(log)


class FileOutputAdder(OutputAdder):
class AddFileOutputAdder(OutputAdder):
"""An output adder wrapper that adds a specific file to all outputs."""

def __init__(self, delegate: OutputAdder, file: FilePath) -> None:
Expand All @@ -190,6 +194,19 @@ def add(self, output: Output) -> None:
self.delegate.add(output.model_copy(update={"file": self.file}))


class DropFileOutputAdder(OutputAdder):
"""An output adder wrapper that drops file information from all outputs."""

def __init__(self, delegate: OutputAdder) -> None:
super().__init__()
self.delegate: OutputAdder = delegate

@override
def add(self, output: Output) -> None:
super().add(output)
self.delegate.add(output.model_copy(update={"file": None}))


@final
class BufferAdder(AbstractContextManager[OutputAdder]):
"""A context manager that buffers outputs and outputs them all at once."""
Expand Down
13 changes: 10 additions & 3 deletions src/erc7730/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
from rich import print

from erc7730 import ERC_7730_REGISTRY_CALLDATA_PREFIX, ERC_7730_REGISTRY_EIP712_PREFIX
from erc7730.common.output import BufferAdder, ConsoleOutputAdder, FileOutputAdder, GithubAnnotationsAdder, OutputAdder
from erc7730.common.output import (
AddFileOutputAdder,
BufferAdder,
ConsoleOutputAdder,
DropFileOutputAdder,
GithubAnnotationsAdder,
OutputAdder,
)
from erc7730.convert.resolved.convert_erc7730_input_to_resolved import ERC7730InputToResolved
from erc7730.lint import ERC7730Linter
from erc7730.lint.lint_base import MultiLinter
Expand All @@ -18,7 +25,7 @@


def lint_all_and_print_errors(paths: list[Path], gha: bool = False) -> bool:
out = GithubAnnotationsAdder() if gha else ConsoleOutputAdder()
out = GithubAnnotationsAdder() if gha else DropFileOutputAdder(delegate=ConsoleOutputAdder())

count = lint_all(paths, out)

Expand Down Expand Up @@ -91,7 +98,7 @@ def lint_file(path: Path, linter: ERC7730Linter, out: OutputAdder, show_as: Path
"""

label = path if show_as is None else show_as
file_out = FileOutputAdder(delegate=out, file=path)
file_out = AddFileOutputAdder(delegate=out, file=path)

with BufferAdder(file_out, prolog=f"➡️ checking [bold]{label}[/bold]…", epilog="") as out:
try:
Expand Down
Loading