Skip to content

Commit 75a085b

Browse files
committed
Refactor so as much work as possible is done in Python
1 parent 0dee4d0 commit 75a085b

15 files changed

+700
-416
lines changed

Diff for: bench_runner/__main__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
"Get the merge base of the selected commit, and determine if it should run"
1515
),
1616
"install": "Install the workflow files into a results repository",
17+
"notify": "Send a notification about the completion of the workflow",
1718
"profiling_plot": "Generate the profiling plots from raw data",
1819
"purge": "Purge old results from a results repository",
1920
"remove_benchmark": "Remove specific benchmarks from the data set",
2021
"run_benchmarks": "Run benchmarks (in timing, pyperf or perf modes)",
21-
"should_run": "Determine whether we need to rerun results for the current commit",
22-
"notify": "Send a notification about the completion of the workflow",
22+
"workflow": "Run the full compile/benchmark workflow",
2323
}
2424

2525
if __name__ == "__main__":

Diff for: bench_runner/benchmark_definitions.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from __future__ import annotations
2+
3+
4+
import dataclasses
5+
import hashlib
6+
from pathlib import Path
7+
8+
9+
from . import git
10+
11+
12+
@dataclasses.dataclass
13+
class BenchmarkRepo:
14+
hash: str
15+
url: str
16+
dirname: str
17+
18+
19+
BENCHMARK_REPOS = [
20+
BenchmarkRepo(
21+
"56d12a8fd7cc1432835965d374929bfa7f6f7a07",
22+
"https://github.com/mdboom/pyperformance.git",
23+
"pyperformance",
24+
),
25+
BenchmarkRepo(
26+
"265655e7f03ace13ec1e00e1ba299179e69f8a00",
27+
"https://github.com/pyston/python-macrobenchmarks.git",
28+
"pyston-benchmarks",
29+
),
30+
]
31+
32+
33+
def get_benchmark_hash() -> str:
34+
hash = hashlib.sha256()
35+
for repo in BENCHMARK_REPOS:
36+
if Path(repo.dirname).is_dir():
37+
current_hash = git.get_git_hash(Path(repo.dirname))
38+
else:
39+
current_hash = repo.hash
40+
hash.update(current_hash.encode("ascii")[:7])
41+
return hash.hexdigest()[:6]

Diff for: bench_runner/git.py

+40
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
from __future__ import annotations
33

44

5+
import contextlib
56
import datetime
67
from pathlib import Path
8+
import shutil
79
import subprocess
10+
import re
811

912

1013
import rich
@@ -128,3 +131,40 @@ def get_commits_between(dirname: PathLike, ref1: str, ref2: str) -> list[str]:
128131
def bisect_commits(dirname: PathLike, ref1: str, ref2: str) -> str:
129132
commits = get_commits_between(dirname, ref1, ref2)
130133
return commits[len(commits) // 2]
134+
135+
136+
def clone(
137+
dirname: PathLike,
138+
url: str,
139+
*,
140+
branch: str | None = None,
141+
depth: int = 1,
142+
) -> None:
143+
is_hash = re.match(r"^[0-9a-f]{40}$", branch) if branch else False
144+
145+
dirname = Path(dirname)
146+
if dirname.is_dir():
147+
if is_hash and (dirname / ".git").is_dir() and get_git_hash(dirname) == branch:
148+
# This is a git repo, and the hash matches
149+
return
150+
shutil.rmtree(dirname)
151+
152+
# Fetching a hash and fetching a branch require different approaches
153+
154+
if is_hash:
155+
assert branch is not None
156+
dirname.mkdir()
157+
with contextlib.chdir(dirname):
158+
subprocess.check_call(["git", "init"])
159+
subprocess.check_call(["git", "remote", "add", "origin", url])
160+
subprocess.check_call(
161+
["git", "fetch", "--depth", str(depth), "origin", branch]
162+
)
163+
subprocess.check_call(["git", "checkout", branch])
164+
else:
165+
args = ["git", "clone", url, str(dirname)]
166+
if branch is not None:
167+
args += ["--branch", branch]
168+
if depth is not None:
169+
args += ["--depth", str(depth)]
170+
subprocess.check_call(args)

Diff for: bench_runner/scripts/get_merge_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import rich_argparse
77

88

9+
from bench_runner import benchmark_definitions
910
from bench_runner import flags as mflags
1011
from bench_runner import git
1112
from bench_runner.result import has_result
12-
from bench_runner import util
1313
from bench_runner.util import PathLike
1414

1515

@@ -55,7 +55,7 @@ def _main(
5555
machine,
5656
pystats,
5757
flags,
58-
util.get_benchmark_hash(),
58+
benchmark_definitions.get_benchmark_hash(),
5959
progress=False,
6060
)
6161
is None

Diff for: bench_runner/scripts/install.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,11 @@ def generate_generic(dst: Any) -> Any:
241241
def _main(check: bool) -> None:
242242
WORKFLOW_PATH.mkdir(parents=True, exist_ok=True)
243243

244-
env = load_yaml(TEMPLATE_PATH / "env.yml")
245-
246244
for path in TEMPLATE_PATH.glob("*"):
247245
if path.name.endswith(".src.yml") or path.name == "env.yml":
248246
continue
249247

250-
if not (ROOT_PATH / path.name).is_file():
248+
if not (ROOT_PATH / path.name).is_file() or path.suffix == ".py":
251249
if check:
252250
fail_check(ROOT_PATH / path.name)
253251
else:
@@ -258,7 +256,6 @@ def _main(check: bool) -> None:
258256
generator = GENERATORS.get(src_path.name, generate_generic)
259257
src = load_yaml(src_path)
260258
dst = generator(src)
261-
dst = {"env": env, **dst}
262259
write_yaml(dst_path, dst, check)
263260

264261

Diff for: bench_runner/scripts/run_benchmarks.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import rich_argparse
1919

2020

21+
from bench_runner import benchmark_definitions
2122
from bench_runner import flags
2223
from bench_runner import git
2324
from bench_runner.result import Result
@@ -265,7 +266,7 @@ def update_metadata(
265266
merge_base = git.get_git_merge_base(cpython)
266267
if merge_base is not None:
267268
metadata["commit_merge_base"] = merge_base
268-
metadata["benchmark_hash"] = util.get_benchmark_hash()
269+
metadata["benchmark_hash"] = benchmark_definitions.get_benchmark_hash()
269270
if run_id is not None:
270271
metadata["github_action_url"] = f"{GITHUB_URL}/actions/runs/{run_id}"
271272
actor = os.environ.get("GITHUB_ACTOR")

Diff for: bench_runner/scripts/should_run.py

-109
This file was deleted.

0 commit comments

Comments
 (0)