diff --git a/python/ruff-ecosystem/ruff_ecosystem/check.py b/python/ruff-ecosystem/ruff_ecosystem/check.py index 6e998e938c..617514d1a0 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/check.py +++ b/python/ruff-ecosystem/ruff_ecosystem/check.py @@ -112,7 +112,7 @@ def summarize_check_result(result: Result) -> str: markdown_project_section( title=f"+{diff.lines_added}, -{diff.lines_removed}", content=diff_lines, - options=project.check_options.markdown(), + options=project.check_options, project=project, ) ) @@ -122,7 +122,7 @@ def summarize_check_result(result: Result) -> str: markdown_project_section( title="error", content=str(error), - options="", + options=project.check_options, project=project, ) ) @@ -146,7 +146,7 @@ def summarize_check_result(result: Result) -> str: lines.extend( markdown_details( summary="Rule change summary", - preface="f"{len(all_rule_changes.rule_codes())} rules changed"", + preface=f"{len(all_rule_changes.rule_codes())} rules changed", content=table_lines, ) ) @@ -166,18 +166,10 @@ def add_permalink_to_diagnostic_line(repo: ClonedRepository, line: str) -> str: async def ruff_check( *, executable: Path, path: Path, name: str, options: CheckOptions -) -> Sequence[str]: +) -> tuple[str, Sequence[str]]: """Run the given ruff binary against the specified path.""" logger.debug(f"Checking {name} with {executable}") - ruff_args = ["check", "--no-cache", "--exit-zero"] - if options.select: - ruff_args.extend(["--select", options.select]) - if options.ignore: - ruff_args.extend(["--ignore", options.ignore]) - if options.exclude: - ruff_args.extend(["--exclude", options.exclude]) - if options.show_fixes: - ruff_args.extend(["--show-fixes", "--ecosystem-ci"]) + ruff_args = options.to_cli_args() start = time.time() proc = await create_subprocess_exec( @@ -225,6 +217,18 @@ class CheckOptions(Serializable): def markdown(self) -> str: return f"select {self.select} ignore {self.ignore} exclude {self.exclude}" + def to_cli_args(self) -> list[str]: + args = ["check", "--no-cache", "--exit-zero"] + if self.select: + args.extend(["--select", self.select]) + if self.ignore: + args.extend(["--ignore", self.ignore]) + if self.exclude: + args.extend(["--exclude", self.exclude]) + if self.show_fixes: + args.extend(["--show-fixes", "--ecosystem-ci"]) + return args + @dataclass(frozen=True) class RuleChanges: diff --git a/python/ruff-ecosystem/ruff_ecosystem/format.py b/python/ruff-ecosystem/ruff_ecosystem/format.py index 8f7a04507e..07f67134f4 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/format.py +++ b/python/ruff-ecosystem/ruff_ecosystem/format.py @@ -59,7 +59,7 @@ def summarize_format_result(result: Result) -> str: markdown_project_section( title=title, content=patch_set_with_permalinks(patch_set, comparison.repo), - options=project.format_options.markdown(), + options=project.format_options, project=project, ) ) @@ -69,7 +69,7 @@ def summarize_format_result(result: Result) -> str: markdown_project_section( title="error", content=str(error), - options="", + options=project.format_options, project=project, ) ) @@ -176,13 +176,12 @@ def create_format_comparison(repo: ClonedRepository, diff: str) -> FormatCompari @dataclass(frozen=True) class FormatOptions: """ - Ruff format options + Ruff format options. """ - pass - - def markdown(self: Self) -> str: - return "" + def to_cli_args(self) -> list[str]: + args = ["format", "--diff"] + return args @dataclass(frozen=True) diff --git a/python/ruff-ecosystem/ruff_ecosystem/markdown.py b/python/ruff-ecosystem/ruff_ecosystem/markdown.py index 74bea83540..e1094c8595 100644 --- a/python/ruff-ecosystem/ruff_ecosystem/markdown.py +++ b/python/ruff-ecosystem/ruff_ecosystem/markdown.py @@ -11,7 +11,7 @@ def markdown_project_section( ) -> list[str]: return markdown_details( summary=f'{project.repo.fullname} ({title})', - preface=options, + preface="`ruff " + " ".join(options.to_cli_args()) + "`", content=content, )