mirror of
https://github.com/astral-sh/ruff.git
synced 2025-12-15 22:14:44 +00:00
Remove remaining ruff_shrinking references (#11272)
## Summary This caused `rooster release` to fail. Initially removed in https://github.com/astral-sh/ruff/pull/11242.
This commit is contained in:
parent
8dd38110d9
commit
d0f51c6434
4 changed files with 0 additions and 92 deletions
1
.github/workflows/ci.yaml
vendored
1
.github/workflows/ci.yaml
vendored
|
|
@ -59,7 +59,6 @@ jobs:
|
|||
- "!crates/ruff_python_formatter/**"
|
||||
- "!crates/ruff_formatter/**"
|
||||
- "!crates/ruff_dev/**"
|
||||
- "!crates/ruff_shrinking/**"
|
||||
- scripts/*
|
||||
- python/**
|
||||
- .github/workflows/ci.yaml
|
||||
|
|
|
|||
|
|
@ -133,21 +133,6 @@ python scripts/check_ecosystem.py --checkouts target/checkouts --projects github
|
|||
cargo run --bin ruff_dev -- format-dev --stability-check --error-file target/formatter-ecosystem-errors.txt --multi-project target/checkouts
|
||||
```
|
||||
|
||||
**Shrinking** To shrink a formatter error from an entire file to a minimal reproducible example,
|
||||
you can use `ruff_shrinking`:
|
||||
|
||||
```shell
|
||||
cargo run --bin ruff_shrinking -- <your_file> target/shrinking.py "Unstable formatting" "target/debug/ruff_dev format-dev --stability-check target/shrinking.py"
|
||||
```
|
||||
|
||||
The first argument is the input file, the second is the output file where the candidates
|
||||
and the eventual minimized version will be written to. The third argument is a regex matching the
|
||||
error message, e.g. "Unstable formatting" or "Formatter error". The last argument is the command
|
||||
with the error, e.g. running the stability check on the candidate file. The script will try various
|
||||
strategies to remove parts of the code. If the output of the command still matches, it will use that
|
||||
slightly smaller code as starting point for the next iteration, otherwise it will revert and try
|
||||
a different strategy until all strategies are exhausted.
|
||||
|
||||
## Helper structs
|
||||
|
||||
To abstract formatting something into a helper, create a new struct with the data you want to
|
||||
|
|
|
|||
|
|
@ -1,75 +0,0 @@
|
|||
"""Take `format-dev --stability-check` output and shrink all stability errors into a
|
||||
single Python file. Used to update https://github.com/astral-sh/ruff/issues/5828 ."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from pathlib import Path
|
||||
from subprocess import check_output
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from tqdm import tqdm
|
||||
|
||||
root = Path(
|
||||
check_output(["git", "rev-parse", "--show-toplevel"], text=True).strip(),
|
||||
)
|
||||
target = root.joinpath("target")
|
||||
|
||||
error_report = target.joinpath("formatter-ecosystem-errors.txt")
|
||||
error_lines_prefix = "Unstable formatting "
|
||||
|
||||
|
||||
def get_filenames() -> list[str]:
|
||||
files = []
|
||||
for line in error_report.read_text().splitlines():
|
||||
if not line.startswith(error_lines_prefix):
|
||||
continue
|
||||
files.append(line.removeprefix(error_lines_prefix))
|
||||
return files
|
||||
|
||||
|
||||
def shrink_file(file: str) -> tuple[str, str]:
|
||||
"""Returns filename and minimization"""
|
||||
with NamedTemporaryFile(suffix=".py") as temp_file:
|
||||
print(f"Starting {file}")
|
||||
ruff_dev = target.joinpath("release").joinpath("ruff_dev")
|
||||
check_output(
|
||||
[
|
||||
target.joinpath("release").joinpath("ruff_shrinking"),
|
||||
file,
|
||||
temp_file.name,
|
||||
"Unstable formatting",
|
||||
f"{ruff_dev} format-dev --stability-check {temp_file.name}",
|
||||
],
|
||||
)
|
||||
print(f"Finished {file}")
|
||||
return file, Path(temp_file.name).read_text()
|
||||
|
||||
|
||||
def main():
|
||||
storage = target.joinpath("minimizations.json")
|
||||
output_file = target.joinpath("minimizations.py")
|
||||
if storage.is_file():
|
||||
outputs = json.loads(storage.read_text())
|
||||
else:
|
||||
outputs = {}
|
||||
files = sorted(set(get_filenames()) - set(outputs))
|
||||
# Each process will saturate one core
|
||||
with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
|
||||
tasks = [executor.submit(shrink_file, file) for file in files]
|
||||
for future in tqdm(as_completed(tasks), total=len(files)):
|
||||
file, output = future.result()
|
||||
outputs[file] = output
|
||||
storage.write_text(json.dumps(outputs, indent=4))
|
||||
|
||||
# Write to one shareable python file
|
||||
with output_file.open("w") as formatted:
|
||||
for file, code in sorted(json.loads(storage.read_text()).items()):
|
||||
file = file.split("/target/checkouts/")[1]
|
||||
formatted.write(f"# {file}\n{code}\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
@ -106,6 +106,5 @@ version_files = [
|
|||
"docs/integrations.md",
|
||||
"crates/ruff/Cargo.toml",
|
||||
"crates/ruff_linter/Cargo.toml",
|
||||
"crates/ruff_shrinking/Cargo.toml",
|
||||
"scripts/benchmarks/pyproject.toml",
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue