Add new ecosystem comparison modes for the formatter (#8416)

Previously, the ecosystem checks formatted with the baseline then
formatted again with `--diff` to get the changed files.

Now, the ecosystem checks support a new mode where we:
- Format with the baseline
- Commit the changes
- Reset to the target ref
- Format again
- Check the diff from the baseline commit

This effectively tests Ruff changes on unformatted code rather than
changes in previously formatted code (unless, of course, the project is
already using Ruff).

While this mode is the new default, I've retained the old one for local
checks. The mode can be toggled with `--format-comparison <type>`.

Includes some more aggressive resetting of the GitHub repositories when
cached.

Here, I've also stubbed comparison modes in which `black` is used as the
baseline. While these do nothing here, #8419 adds support.

I tested this with the commit from #8216 and ecosystem changes appear
https://gist.github.com/zanieb/a982ec8c392939043613267474471a6e
This commit is contained in:
Zanie Blue 2023-11-01 20:20:52 -05:00 committed by GitHub
parent 4d23c1fc83
commit 2f7e2a8de3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 201 additions and 13 deletions

View file

@ -7,7 +7,11 @@ from typing import Awaitable, TypeVar
from ruff_ecosystem import logger
from ruff_ecosystem.check import compare_check, markdown_check_result
from ruff_ecosystem.format import compare_format, markdown_format_result
from ruff_ecosystem.format import (
FormatComparison,
compare_format,
markdown_format_result,
)
from ruff_ecosystem.projects import (
Project,
RuffCommand,
@ -30,6 +34,7 @@ async def main(
targets: list[Project],
project_dir: Path,
format: OutputFormat,
format_comparison: FormatComparison | None,
max_parallelism: int = 50,
raise_on_failure: bool = False,
) -> None:
@ -55,6 +60,7 @@ async def main(
ruff_comparison_executable,
target,
project_dir,
format_comparison,
)
)
for target in targets
@ -96,6 +102,7 @@ async def clone_and_compare(
ruff_comparison_executable: Path,
target: Project,
project_dir: Path,
format_comparison: FormatComparison | None,
) -> Comparison:
"""Check a specific repository against two versions of ruff."""
assert ":" not in target.repo.owner
@ -103,14 +110,12 @@ async def clone_and_compare(
match command:
case RuffCommand.check:
compare, options = (
compare_check,
target.check_options,
)
compare, options, kwargs = (compare_check, target.check_options, {})
case RuffCommand.format:
compare, options = (
compare, options, kwargs = (
compare_format,
target.format_options,
{"format_comparison": format_comparison},
)
case _:
raise ValueError(f"Unknown target Ruff command {command}")
@ -124,6 +129,7 @@ async def clone_and_compare(
ruff_comparison_executable,
options,
cloned_repo,
**kwargs,
)
except ExceptionGroup as e:
raise e.exceptions[0] from e