mirror of
https://github.com/astral-sh/ruff.git
synced 2026-10-28 10:45:37 +08:00
## Summary Enable return type inference for all 24 standalone Python scripts checked by ty in CI, along with `py-fuzzer` and `ty_benchmark`.
111 lines
2.9 KiB
Python
111 lines
2.9 KiB
Python
# /// script
|
|
# requires-python = ">=3.12"
|
|
# dependencies = ["tqdm"]
|
|
#
|
|
# [tool.ty.analysis]
|
|
# return-type-inference = "always"
|
|
#
|
|
# [tool.ty.rules]
|
|
# truthiness-test-of-none-union = "warn"
|
|
# blanket-ignore-comment = "warn"
|
|
# missing-type-argument = "warn"
|
|
# possibly-unresolved-reference = "warn"
|
|
# unsound-return-statement = "warn"
|
|
# unsound-yield = "warn"
|
|
# unsupported-dynamic-base = "warn"
|
|
# division-by-zero = "warn"
|
|
# dynamic-function-decorator-return = "warn"
|
|
# unsound-assignment = "warn"
|
|
# redundant-condition-strict = "warn"
|
|
# disjoint-cast = "warn"
|
|
# missing-direct-dependency = "warn"
|
|
#
|
|
# [tool.uv]
|
|
# no-build = true
|
|
# exclude-newer = "P7D"
|
|
# require-build-hashes = true
|
|
# preview-features = ["build-dependency-hashes", "missing-exclude-newer-package-lock"]
|
|
# ///
|
|
|
|
"""This is @konstin's scripts for checking an entire checkout of ~2.1k packages for
|
|
panics, fix errors and similar problems.
|
|
|
|
It's a less elaborate, more hacky ecosystem checker.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
from subprocess import CalledProcessError
|
|
from typing import NamedTuple
|
|
|
|
from tqdm import tqdm
|
|
|
|
|
|
class Repository(NamedTuple):
|
|
"""A GitHub repository at a specific ref."""
|
|
|
|
org: str
|
|
repo: str
|
|
ref: str | None
|
|
|
|
|
|
def main() -> None:
|
|
ruff_args = sys.argv[1:]
|
|
checkouts = Path("checkouts")
|
|
out_dir = Path("ecosystem_all_results")
|
|
github_search_json = Path("github_search.jsonl")
|
|
# Somehow it doesn't like plain ruff
|
|
ruff = Path.cwd().joinpath("ruff")
|
|
|
|
out_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
repositories = []
|
|
for line in github_search_json.read_text().splitlines():
|
|
item = json.loads(line)
|
|
# Pick only the easier case for now.
|
|
if item["path"] != "pyproject.toml":
|
|
continue
|
|
repositories.append(
|
|
Repository(
|
|
item["owner"],
|
|
item["repo"],
|
|
item.get("ref"),
|
|
),
|
|
)
|
|
|
|
successes = 0
|
|
errors = 0
|
|
for repository in tqdm(repositories):
|
|
project_dir = checkouts.joinpath(f"{repository.org}:{repository.repo}")
|
|
if not project_dir.is_dir():
|
|
tqdm.write(f"Missing {project_dir}")
|
|
errors += 1
|
|
continue
|
|
|
|
try:
|
|
output = subprocess.run(
|
|
[ruff, *ruff_args, "."],
|
|
cwd=project_dir,
|
|
capture_output=True,
|
|
text=True,
|
|
check=False,
|
|
)
|
|
except CalledProcessError as e:
|
|
tqdm.write(f"Ruff failed on {project_dir}: {e}")
|
|
errors += 1
|
|
continue
|
|
|
|
org_repo = f"{repository.org}:{repository.repo}"
|
|
out_dir.joinpath(f"{org_repo}.stdout.txt").write_text(output.stdout)
|
|
out_dir.joinpath(f"{org_repo}.stderr.txt").write_text(output.stderr)
|
|
successes += 1
|
|
print(f"Success: {successes} Error {errors}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|