Skip to content

Commit 3dce64a

Browse files
committed
Move most logic into separate scripts / workflows
1 parent 2b2a2e5 commit 3dce64a

10 files changed

Lines changed: 318 additions & 191 deletions

File tree

.github/workflows/bench.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"CARGO_TERM_COLOR": "always"
99
},
1010
"jobs": {
11-
"build": {
11+
"bench": {
1212
"runs-on": "ubuntu-latest",
1313
"steps": [
1414
{
@@ -24,7 +24,11 @@
2424
},
2525
{
2626
"name": "Bench",
27-
"run": "cargo bench -p serde_arrow_bench\npython scripts/analyze-benchmark.py --criterion-root target/criterion --readme Readme.md --plot-output timings.png >> $GITHUB_STEP_SUMMARY"
27+
"run": "cargo bench -p serde_arrow_bench"
28+
},
29+
{
30+
"name": "Summarize",
31+
"run": "python scripts/analyze-benchmark.py --criterion-root target/criterion --update-github-summary"
2832
}
2933
]
3034
}

.github/workflows/local.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
{
6767
"name": "Check Cargo.toml",
68-
"run": "uv run python scripts/check-cargo-toml.py --arrow-features arrow-59 arrow-58 arrow-57 arrow-56 arrow-55 arrow-54 arrow-53"
68+
"run": "uv run python scripts/check-cargo-toml.py"
6969
},
7070
{
7171
"name": "Check workspace",

.github/workflows/test.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
{
7676
"name": "Check Cargo.toml",
77-
"run": "uv run python scripts/check-cargo-toml.py --arrow-features arrow-59 arrow-58 arrow-57 arrow-56 arrow-55 arrow-54 arrow-53"
77+
"run": "uv run python scripts/check-cargo-toml.py"
7878
},
7979
{
8080
"name": "Check",
@@ -144,10 +144,30 @@
144144
"name": "Check support packages",
145145
"run": "cargo check --all-features --package serde_arrow_bench --package serde_arrow_example --package serde_arrow_integration --package marrow_integration"
146146
},
147+
{
148+
"name": "Clippy serde_arrow",
149+
"run": "cargo clippy --all-targets --package serde_arrow --features arrow-59"
150+
},
151+
{
152+
"name": "Clippy marrow",
153+
"run": "cargo clippy --all-targets --package marrow --features serde,arrow-59"
154+
},
155+
{
156+
"name": "Clippy support packages",
157+
"run": "cargo clippy --all-targets --all-features --package serde_arrow_bench --package serde_arrow_example --package serde_arrow_integration --package marrow_integration"
158+
},
159+
{
160+
"name": "Check Python format",
161+
"run": "uv run ruff format --check x.py"
162+
},
147163
{
148164
"name": "Check format",
149165
"run": "cargo fmt --check"
150166
},
167+
{
168+
"name": "Check generated Rust format",
169+
"run": "rustfmt --check marrow/src/impl_arrow/impl_api_53.rs marrow/src/impl_arrow/impl_api_base.rs marrow_integration/src/tests/arrays.rs marrow_integration/src/tests/data_types.rs marrow_integration/src/tests/fixed_size_binary_arrays.rs marrow_integration/src/tests/intervals.rs marrow_integration/src/tests/struct_arrays.rs marrow_integration/src/tests/union_arrays.rs marrow_integration/src/tests/utils.rs marrow_integration/src/tests/views.rs"
170+
},
151171
{
152172
"name": "Build",
153173
"run": "cargo build --package serde_arrow --package marrow --features serde_arrow/arrow-59,marrow/serde,marrow/arrow-59"
@@ -159,6 +179,14 @@
159179
{
160180
"name": "Integration test",
161181
"run": "cargo test -p serde_arrow_integration"
182+
},
183+
{
184+
"name": "Run example",
185+
"run": "cargo run -p serde_arrow_example"
186+
},
187+
{
188+
"name": "Read example output",
189+
"run": "uv run python -c 'import polars as pl; print(pl.read_ipc(\"serde_arrow_example.ipc\"))'"
162190
}
163191
]
164192
}

arrow-versions.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
arrow-features = [
2+
# arrow-version:insert: "arrow-{version}",
3+
"arrow-59",
4+
"arrow-58",
5+
"arrow-57",
6+
"arrow-56",
7+
"arrow-55",
8+
"arrow-54",
9+
"arrow-53",
10+
]

scripts/add-arrow-version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def add_arrow_version(version):
3535
def arrow_version_paths():
3636
return [
3737
SELF_PATH / "x.py",
38+
*SELF_PATH.glob("*.toml"),
3839
*SELF_PATH.glob("*/**/*.rs"),
3940
*SELF_PATH.glob("*/**/*.toml"),
4041
]

scripts/analyze-benchmark.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import json
3+
import os
34
import pathlib
45
import statistics
56

@@ -19,32 +20,39 @@
1920
def main():
2021
parser = argparse.ArgumentParser()
2122
parser.add_argument("--criterion-root", type=pathlib.Path, required=True)
22-
parser.add_argument("--plot-output", type=pathlib.Path, required=True)
23-
parser.add_argument("--readme", type=pathlib.Path, required=True)
24-
parser.add_argument("--update", action="store_true", default=False)
23+
parser.add_argument(
24+
"--plot-output", type=pathlib.Path, default=pathlib.Path("timings.png")
25+
)
26+
parser.add_argument("--update", type=pathlib.Path)
27+
parser.add_argument("--update-github-summary", action="store_true", default=False)
2528
analyze_benchmark(parser.parse_args())
2629

2730

2831
def analyze_benchmark(args):
2932
root = resolve_path(args.criterion_root)
30-
readme = resolve_path(args.readme)
33+
update = resolve_path(args.update) if args.update else None
3134
plot_output = resolve_path(args.plot_output)
3235

3336
mean_times = load_times(root)
34-
print(format_benchmark(mean_times, ignore_groups=README_BENCHMARK_IGNORE_GROUPS))
37+
benchmark = format_benchmark(
38+
mean_times,
39+
ignore_groups=README_BENCHMARK_IGNORE_GROUPS,
40+
)
3541

36-
if args.update:
37-
update_readme(
38-
readme,
39-
mean_times,
40-
ignore_groups=README_BENCHMARK_IGNORE_GROUPS,
41-
)
42-
plot_times(
43-
mean_times,
44-
benchmark_baseline=BENCHMARK_BASELINE,
45-
ignore_groups=README_BENCHMARK_IGNORE_GROUPS,
46-
output=plot_output,
47-
)
42+
print(benchmark)
43+
44+
if update is not None:
45+
update_marked_output(update, benchmark)
46+
47+
if args.update_github_summary:
48+
update_github_summary(benchmark)
49+
50+
plot_times(
51+
mean_times,
52+
benchmark_baseline=BENCHMARK_BASELINE,
53+
ignore_groups=README_BENCHMARK_IGNORE_GROUPS,
54+
output=plot_output,
55+
)
4856

4957

5058
def resolve_path(path):
@@ -131,21 +139,35 @@ def _parts():
131139
return "\n".join(_parts())
132140

133141

134-
def update_readme(readme, mean_times, ignore_groups=()):
135-
print("Update readme")
136-
with open(readme, "rt", encoding="utf8") as fobj:
142+
def update_marked_output(output, content):
143+
print(f"Update markers in {output}")
144+
with open(output, "rt", encoding="utf8") as fobj:
137145
lines = [line.rstrip() for line in fobj]
138146

139-
with open(readme, "wt", encoding="utf8", newline="\n") as fobj:
147+
with open(output, "wt", encoding="utf8", newline="\n") as fobj:
140148
for line in replace_marked_section(
141149
lines,
142150
start_marker="<!-- start:benchmarks -->",
143151
end_marker="<!-- end:benchmarks -->",
144-
content=format_benchmark(mean_times, ignore_groups=ignore_groups),
152+
content=content,
145153
):
146154
print(line, file=fobj)
147155

148156

157+
def update_github_summary(content):
158+
path = os.environ.get("GITHUB_STEP_SUMMARY")
159+
if path is None:
160+
return
161+
162+
append_output(pathlib.Path(path), content)
163+
164+
165+
def append_output(path, content):
166+
print(f"Append summary to {path}")
167+
with open(path, "at", encoding="utf8", newline="\n") as fobj:
168+
print(content, file=fobj)
169+
170+
149171
def replace_marked_section(lines, *, start_marker, end_marker, content):
150172
start = None
151173
end = None

scripts/check-cargo-toml.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import argparse
21
import pathlib
32
import tomllib
43

@@ -9,12 +8,10 @@
98

109

1110
def main():
12-
parser = argparse.ArgumentParser()
13-
parser.add_argument("--arrow-features", required=True, nargs="+")
14-
check_cargo_toml(parser.parse_args())
11+
check_cargo_toml(load_script_config()["arrow-features"])
1512

1613

17-
def check_cargo_toml(args):
14+
def check_cargo_toml(arrow_features):
1815
print(":: check Cargo.toml")
1916
serde_arrow_config = load_config("serde_arrow")
2017
marrow_config = load_config("marrow")
@@ -36,16 +33,16 @@ def check_cargo_toml(args):
3633
"serde_arrow",
3734
"docs.rs configuration",
3835
serde_arrow_config["package"]["metadata"]["docs"]["rs"]["features"],
39-
(args.arrow_features[0],),
36+
(arrow_features[0],),
4037
)
4138
check_feature_list(
4239
"marrow",
4340
"docs.rs configuration",
4441
marrow_config["package"]["metadata"]["docs"]["rs"]["features"],
45-
("serde", args.arrow_features[0]),
42+
("serde", arrow_features[0]),
4643
)
4744

48-
for feature in args.arrow_features:
45+
for feature in arrow_features:
4946
check_arrow_feature(
5047
"serde_arrow",
5148
serde_arrow_config,
@@ -88,6 +85,11 @@ def load_config(crate):
8885
return tomllib.load(fobj)
8986

9087

88+
def load_script_config():
89+
with open(SELF_PATH / "arrow-versions.toml", "rb") as fobj:
90+
return tomllib.load(fobj)
91+
92+
9193
def check_feature_list(crate, label, actual, expected):
9294
actual_features = sorted(actual)
9395
expected_features = sorted(expected)

scripts/doc.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import argparse
2+
import pathlib
3+
import subprocess
4+
import tomllib
5+
6+
7+
SELF_PATH = pathlib.Path(__file__).parents[1].resolve()
8+
9+
10+
def main():
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument("--private", action="store_true", default=False)
13+
parser.add_argument("--open", action="store_true", default=False)
14+
doc(parser.parse_args())
15+
16+
17+
def doc(args):
18+
extra_args = (("--document-private-items",) if args.private else ()) + (
19+
("--open",) if args.open else ()
20+
)
21+
subprocess.run(
22+
split_command(
23+
cargo(
24+
"doc",
25+
*extra_args,
26+
packages=("serde_arrow", "marrow"),
27+
features=(
28+
f"serde_arrow/{arrow_features()[0]}",
29+
"marrow/serde",
30+
f"marrow/{arrow_features()[0]}",
31+
),
32+
)
33+
),
34+
check=True,
35+
cwd=SELF_PATH,
36+
)
37+
38+
39+
def arrow_features():
40+
return load_script_config()["arrow-features"]
41+
42+
43+
def load_script_config():
44+
with open(SELF_PATH / "arrow-versions.toml", "rb") as fobj:
45+
return tomllib.load(fobj)
46+
47+
48+
def cargo(command, *extra_args, packages=(), features=()):
49+
return " ".join(
50+
part
51+
for part in [
52+
"cargo",
53+
command,
54+
*(f"--package {package}" for package in packages),
55+
"--features" if features else "",
56+
",".join(features) if features else "",
57+
*extra_args,
58+
]
59+
if part
60+
)
61+
62+
63+
def split_command(command):
64+
import shlex
65+
66+
args = shlex.split(command.replace("\n", " "))
67+
print("::", *args)
68+
return args
69+
70+
71+
if __name__ == "__main__":
72+
main()

0 commit comments

Comments
 (0)