Skip to content

Commit bc249da

Browse files
committed
Improve the performance of the formatter instability checks
1 parent 42c35b6 commit bc249da

File tree

2 files changed

+74
-45
lines changed

2 files changed

+74
-45
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,12 @@ jobs:
563563
run: rustup show
564564
- name: "Cache rust"
565565
uses: Swatinem/rust-cache@v2
566-
- name: "Formatter progress"
566+
- name: "Run checks"
567567
run: scripts/formatter_ecosystem_checks.sh
568568
- name: "Github step summary"
569-
run: cat target/progress_projects_stats.txt > $GITHUB_STEP_SUMMARY
569+
run: cat target/formatter-ecosystem/stats.txt > $GITHUB_STEP_SUMMARY
570570
- name: "Remove checkouts from cache"
571-
run: rm -r target/progress_projects
571+
run: rm -r target/formatter-ecosystem
572572

573573
check-ruff-lsp:
574574
name: "test ruff-lsp"

scripts/formatter_ecosystem_checks.sh

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# errors.
99
#
1010
# This script will first clone a diverse set of (mostly) black formatted
11-
# repositories with fixed revisions to target/progress_projects. Each project
11+
# repositories with fixed revisions to target/formatter-ecosystem. Each project
1212
# gets formatted (without modifying the files on disk) to check how
1313
# similar our style is to black. It also catches common issues such as
1414
# unstable formatting, internal formatter errors and printing invalid syntax.
@@ -18,72 +18,101 @@
1818
set -e
1919

2020
target=$(git rev-parse --show-toplevel)/target
21-
dir="$target/progress_projects"
21+
dir="$target/formatter-ecosystem"
2222
mkdir -p "$dir"
2323

24+
# Perfom an idempotent clone and checkout of a commit
25+
clone_commit() {
26+
local repo="$1"
27+
local target="$2"
28+
local ref="$3"
29+
30+
if [ -z "$repo" ] || [ -z "$target" ] || [ -z "$ref" ]; then
31+
echo "Usage: clone_commit <repo> <dir> <ref>"
32+
return 1
33+
fi
34+
35+
if [ ! -d "$target/.git" ]; then
36+
echo "Cloning $repo to $target"
37+
# Perform a minimal clone, we only need a single commit
38+
git clone --filter=blob:none --depth=1 --no-tags --no-checkout --single-branch "$repo" "$target"
39+
fi
40+
41+
echo "Using $repo at $ref"
42+
git -C "$target" fetch --filter=blob:none --depth=1 --no-tags origin "$ref"
43+
git -C "$target" checkout -q "$ref"
44+
}
45+
2446
# small util library
25-
if [ ! -d "$dir/twine/.git" ]; then
26-
git clone --filter=tree:0 https://github.com/pypa/twine "$dir/twine"
27-
fi
28-
git -C "$dir/twine" checkout -q ae71822a3cb0478d0f6a0cccb65d6f8e6275ece5
47+
clone_commit \
48+
"https://github.com/pypa/twine" \
49+
"$dir/twine" \
50+
"ae71822a3cb0478d0f6a0cccb65d6f8e6275ece5" &
2951

3052
# web framework that implements a lot of magic
31-
if [ ! -d "$dir/django/.git" ]; then
32-
git clone --filter=tree:0 https://github.com/django/django "$dir/django"
33-
fi
34-
git -C "$dir/django" checkout -q ee5147cfd7de2add74a285537a8968ec074e70cd
53+
clone_commit \
54+
"https://github.com/django/django" \
55+
"$dir/django" \
56+
"ee5147cfd7de2add74a285537a8968ec074e70cd" &
3557

3658
# an ML project
37-
if [ ! -d "$dir/transformers/.git" ]; then
38-
git clone --filter=tree:0 https://github.com/huggingface/transformers "$dir/transformers"
39-
fi
40-
git -C "$dir/transformers" checkout -q ac5a0556f14dec503b064d5802da1092e0b558ea
59+
clone_commit \
60+
"https://github.com/huggingface/transformers" \
61+
"$dir/transformers" \
62+
"ac5a0556f14dec503b064d5802da1092e0b558ea" &
4163

4264
# type annotations
43-
if [ ! -d "$dir/typeshed/.git" ]; then
44-
git clone --filter=tree:0 https://github.com/python/typeshed "$dir/typeshed"
45-
fi
46-
git -C "$dir/typeshed" checkout -q d34ef50754de993d01630883dbcd1d27ba507143
65+
clone_commit \
66+
"https://github.com/python/typeshed" \
67+
"$dir/typeshed" \
68+
"d34ef50754de993d01630883dbcd1d27ba507143" &
4769

4870
# python 3.11, typing and 100% test coverage
49-
if [ ! -d "$dir/warehouse/.git" ]; then
50-
git clone --filter=tree:0 https://github.com/pypi/warehouse "$dir/warehouse"
51-
fi
52-
git -C "$dir/warehouse" checkout -q 5a4d2cadec641b5d6a6847d0127940e0f532f184
71+
clone_commit \
72+
"https://github.com/pypi/warehouse" \
73+
"$dir/warehouse" \
74+
"5a4d2cadec641b5d6a6847d0127940e0f532f184" &
5375

5476
# zulip, a django user
55-
if [ ! -d "$dir/zulip/.git" ]; then
56-
git clone --filter=tree:0 https://github.com/zulip/zulip "$dir/zulip"
57-
fi
58-
git -C "$dir/zulip" checkout -q ccddbba7a3074283ccaac3bde35fd32b19faf042
77+
clone_commit \
78+
"https://github.com/zulip/zulip" \
79+
"$dir/zulip" \
80+
"ccddbba7a3074283ccaac3bde35fd32b19faf042" &
5981

6082
# home-assistant, home automation with 1ok files
61-
if [ ! -d "$dir/home-assistant/.git" ]; then
62-
git clone --filter=tree:0 https://github.com/home-assistant/core "$dir/home-assistant"
63-
fi
64-
git -C "$dir/home-assistant" checkout -q 3601c531f400255d10b82529549e564fbe483a54
83+
clone_commit \
84+
"https://github.com/home-assistant/core" \
85+
"$dir/home-assistant" \
86+
"3601c531f400255d10b82529549e564fbe483a54" &
6587

6688
# poetry, a package manager that uses black preview style
67-
if [ ! -d "$dir/poetry/.git" ]; then
68-
git clone --filter=tree:0 https://github.com/python-poetry/poetry "$dir/poetry"
69-
fi
70-
git -C "$dir/poetry" checkout -q 36fedb59b8e655252168055b536ead591068e1e4
89+
clone_commit \
90+
"https://github.com/python-poetry/poetry" \
91+
"$dir/poetry" \
92+
"36fedb59b8e655252168055b536ead591068e1e4" &
7193

7294
# cpython itself
73-
if [ ! -d "$dir/cpython/.git" ]; then
74-
git clone --filter=tree:0 https://github.com/python/cpython "$dir/cpython"
75-
fi
76-
git -C "$dir/cpython" checkout -q 28aea5d07d163105b42acd81c1651397ef95ea57
95+
clone_commit \
96+
"https://github.com/python/cpython" \
97+
"$dir/cpython" \
98+
"28aea5d07d163105b42acd81c1651397ef95ea57" &
99+
100+
# wait for the concurrent clones to complete
101+
wait
77102

78103
# Uncomment if you want to update the hashes
79104
#for i in "$dir"/*/; do git -C "$i" switch main && git -C "$i" pull; done
80105
#for i in "$dir"/*/; do echo "# $(basename "$i") $(git -C "$i" rev-parse HEAD)"; done
81106

82107
time cargo run --bin ruff_dev -- format-dev --stability-check \
83-
--error-file "$target/progress_projects_errors.txt" --log-file "$target/progress_projects_log.txt" --stats-file "$target/progress_projects_stats.txt" \
84-
--files-with-errors 3 --multi-project "$dir" || (
108+
--error-file "$target/formatter-ecosystem/errors.txt" \
109+
--log-file "$target/formatter-ecosystem/log.txt" \
110+
--stats-file "$target/formatter-ecosystem/stats.txt" \
111+
--files-with-errors 3 --multi-project "$dir" \
112+
|| (
85113
echo "Ecosystem check failed"
86-
cat "$target/progress_projects_log.txt"
114+
cat "$target/formatter-ecosystem/log.txt"
87115
exit 1
88116
)
89-
cat "$target/progress_projects_stats.txt"
117+
118+
cat "$target/formatter-ecosystem/stats.txt"

0 commit comments

Comments
 (0)