mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 21:34:57 +00:00
Allow config-file overrides in ecosystem checks (#9286)
Adds the ability to override `ruff.toml` or `pyproject.toml` settings per-project during ecosystem checks. Exploring this as a fix for the `setuptools` project error. Also useful for including Jupyter Notebooks in the ecosystem checks, see #9293 Note the remaining `sphinx` project error is resolved in #9294
This commit is contained in:
parent
f8fc309855
commit
57b6a8cedd
6 changed files with 210 additions and 60 deletions
|
@ -18,7 +18,7 @@ from ruff_ecosystem.markdown import markdown_project_section
|
|||
from ruff_ecosystem.types import Comparison, Diff, Result, ToolError
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ruff_ecosystem.projects import ClonedRepository, FormatOptions
|
||||
from ruff_ecosystem.projects import ClonedRepository, ConfigOverrides, FormatOptions
|
||||
|
||||
|
||||
def markdown_format_result(result: Result) -> str:
|
||||
|
@ -137,10 +137,17 @@ async def compare_format(
|
|||
ruff_baseline_executable: Path,
|
||||
ruff_comparison_executable: Path,
|
||||
options: FormatOptions,
|
||||
config_overrides: ConfigOverrides,
|
||||
cloned_repo: ClonedRepository,
|
||||
format_comparison: FormatComparison,
|
||||
):
|
||||
args = (ruff_baseline_executable, ruff_comparison_executable, options, cloned_repo)
|
||||
args = (
|
||||
ruff_baseline_executable,
|
||||
ruff_comparison_executable,
|
||||
options,
|
||||
config_overrides,
|
||||
cloned_repo,
|
||||
)
|
||||
match format_comparison:
|
||||
case FormatComparison.ruff_then_ruff:
|
||||
coro = format_then_format(Formatter.ruff, *args)
|
||||
|
@ -162,25 +169,27 @@ async def format_then_format(
|
|||
ruff_baseline_executable: Path,
|
||||
ruff_comparison_executable: Path,
|
||||
options: FormatOptions,
|
||||
config_overrides: ConfigOverrides,
|
||||
cloned_repo: ClonedRepository,
|
||||
) -> Sequence[str]:
|
||||
# Run format to get the baseline
|
||||
await format(
|
||||
formatter=baseline_formatter,
|
||||
executable=ruff_baseline_executable.resolve(),
|
||||
path=cloned_repo.path,
|
||||
name=cloned_repo.fullname,
|
||||
options=options,
|
||||
)
|
||||
# Then get the diff from stdout
|
||||
diff = await format(
|
||||
formatter=Formatter.ruff,
|
||||
executable=ruff_comparison_executable.resolve(),
|
||||
path=cloned_repo.path,
|
||||
name=cloned_repo.fullname,
|
||||
options=options,
|
||||
diff=True,
|
||||
)
|
||||
with config_overrides.patch_config(cloned_repo.path, options.preview):
|
||||
# Run format to get the baseline
|
||||
await format(
|
||||
formatter=baseline_formatter,
|
||||
executable=ruff_baseline_executable.resolve(),
|
||||
path=cloned_repo.path,
|
||||
name=cloned_repo.fullname,
|
||||
options=options,
|
||||
)
|
||||
# Then get the diff from stdout
|
||||
diff = await format(
|
||||
formatter=Formatter.ruff,
|
||||
executable=ruff_comparison_executable.resolve(),
|
||||
path=cloned_repo.path,
|
||||
name=cloned_repo.fullname,
|
||||
options=options,
|
||||
diff=True,
|
||||
)
|
||||
return diff
|
||||
|
||||
|
||||
|
@ -189,32 +198,39 @@ async def format_and_format(
|
|||
ruff_baseline_executable: Path,
|
||||
ruff_comparison_executable: Path,
|
||||
options: FormatOptions,
|
||||
config_overrides: ConfigOverrides,
|
||||
cloned_repo: ClonedRepository,
|
||||
) -> Sequence[str]:
|
||||
# Run format without diff to get the baseline
|
||||
await format(
|
||||
formatter=baseline_formatter,
|
||||
executable=ruff_baseline_executable.resolve(),
|
||||
path=cloned_repo.path,
|
||||
name=cloned_repo.fullname,
|
||||
options=options,
|
||||
)
|
||||
with config_overrides.patch_config(cloned_repo.path, options.preview):
|
||||
# Run format without diff to get the baseline
|
||||
await format(
|
||||
formatter=baseline_formatter,
|
||||
executable=ruff_baseline_executable.resolve(),
|
||||
path=cloned_repo.path,
|
||||
name=cloned_repo.fullname,
|
||||
options=options,
|
||||
)
|
||||
|
||||
# Commit the changes
|
||||
commit = await cloned_repo.commit(
|
||||
message=f"Formatted with baseline {ruff_baseline_executable}"
|
||||
)
|
||||
# Then reset
|
||||
await cloned_repo.reset()
|
||||
# Then run format again
|
||||
await format(
|
||||
formatter=Formatter.ruff,
|
||||
executable=ruff_comparison_executable.resolve(),
|
||||
path=cloned_repo.path,
|
||||
name=cloned_repo.fullname,
|
||||
options=options,
|
||||
)
|
||||
|
||||
with config_overrides.patch_config(cloned_repo.path, options.preview):
|
||||
# Then run format again
|
||||
await format(
|
||||
formatter=Formatter.ruff,
|
||||
executable=ruff_comparison_executable.resolve(),
|
||||
path=cloned_repo.path,
|
||||
name=cloned_repo.fullname,
|
||||
options=options,
|
||||
)
|
||||
|
||||
# Then get the diff from the commit
|
||||
diff = await cloned_repo.diff(commit)
|
||||
|
||||
return diff
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue