mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
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:
parent
4d23c1fc83
commit
2f7e2a8de3
5 changed files with 201 additions and 13 deletions
|
@ -12,6 +12,7 @@ from signal import SIGINT, SIGTERM
|
|||
|
||||
from ruff_ecosystem import logger
|
||||
from ruff_ecosystem.defaults import DEFAULT_TARGETS
|
||||
from ruff_ecosystem.format import FormatComparison
|
||||
from ruff_ecosystem.main import OutputFormat, main
|
||||
from ruff_ecosystem.projects import RuffCommand
|
||||
|
||||
|
@ -77,6 +78,12 @@ def entrypoint():
|
|||
if args.force_preview:
|
||||
targets = [target.with_preview_enabled() for target in targets]
|
||||
|
||||
format_comparison = (
|
||||
FormatComparison(args.format_comparison)
|
||||
if args.ruff_command == RuffCommand.format.value
|
||||
else None
|
||||
)
|
||||
|
||||
with cache_context as cache:
|
||||
loop = asyncio.get_event_loop()
|
||||
main_task = asyncio.ensure_future(
|
||||
|
@ -88,6 +95,7 @@ def entrypoint():
|
|||
format=OutputFormat(args.output_format),
|
||||
project_dir=Path(cache),
|
||||
raise_on_failure=args.pdb,
|
||||
format_comparison=format_comparison,
|
||||
)
|
||||
)
|
||||
# https://stackoverflow.com/a/58840987/3549270
|
||||
|
@ -120,7 +128,7 @@ def parse_args() -> argparse.Namespace:
|
|||
)
|
||||
parser.add_argument(
|
||||
"--output-format",
|
||||
choices=[option.name for option in OutputFormat],
|
||||
choices=[option.value for option in OutputFormat],
|
||||
default="markdown",
|
||||
help="Location for caching cloned repositories",
|
||||
)
|
||||
|
@ -140,9 +148,15 @@ def parse_args() -> argparse.Namespace:
|
|||
action="store_true",
|
||||
help="Force preview mode to be enabled for all projects",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--format-comparison",
|
||||
choices=[option.value for option in FormatComparison],
|
||||
default=FormatComparison.ruff_and_ruff,
|
||||
help="Type of comparison to make when checking formatting.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"ruff_command",
|
||||
choices=[option.name for option in RuffCommand],
|
||||
choices=[option.value for option in RuffCommand],
|
||||
help="The Ruff command to test",
|
||||
)
|
||||
parser.add_argument(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue