Skip to content

Commit 16724bb

Browse files
authored
Merge branch 'main' into minor-changes
2 parents e99f63e + c4a77ec commit 16724bb

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

bench_runner/git.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,9 @@ def get_log(
3030
if extra is None:
3131
extra = []
3232

33-
if ref is None:
34-
ref_args = []
35-
else:
36-
ref_args = [ref]
37-
if n < 1:
38-
n_args = []
39-
else:
40-
n_args = ["-n", str(n)]
33+
ref_args = [] if ref is None else [ref]
34+
n_args = [] if n < 1 else ["-n", str(n)]
35+
4136
return subprocess.check_output(
4237
["git", "log", f"--pretty=format:{format}", *n_args, *ref_args, *extra],
4338
encoding="utf-8",
@@ -64,7 +59,9 @@ def get_git_merge_base(dirname: PathLike) -> str | None:
6459
# We need to make sure we have commits from main that are old enough to be
6560
# the base of this branch, but not so old that we waste a ton of bandwidth
6661
commit_date = datetime.datetime.fromisoformat(get_git_commit_date(dirname))
67-
commit_date = commit_date - datetime.timedelta(365 * 2)
62+
commit_date = commit_date - datetime.timedelta(days=365 * 2)
63+
64+
# Get current commit hash
6865
commit_hash = get_log("%H", dirname)
6966

7067
try:
@@ -79,10 +76,7 @@ def get_git_merge_base(dirname: PathLike) -> str | None:
7976
cwd=dirname,
8077
)
8178
except subprocess.CalledProcessError as e:
82-
if e.returncode in (3, 128):
83-
# Remote may already exist, that's ok
84-
pass
85-
else:
79+
if e.returncode not in (3, 128):
8680
raise
8781

8882
subprocess.check_call(
@@ -96,6 +90,7 @@ def get_git_merge_base(dirname: PathLike) -> str | None:
9690
],
9791
cwd=dirname,
9892
)
93+
9994
try:
10095
merge_base = subprocess.check_output(
10196
["git", "merge-base", "upstream/main", "HEAD"],
@@ -107,9 +102,10 @@ def get_git_merge_base(dirname: PathLike) -> str | None:
107102
return None
108103

109104
if merge_base == commit_hash:
105+
# Get the parent commit if the merge base is the same as the current commit
110106
return get_log("%H", dirname, "HEAD^")
111-
else:
112-
return merge_base
107+
108+
return merge_base
113109

114110

115111
def get_tags(dirname: PathLike) -> list[str]:

bench_runner/scripts/install.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ def flag_env():
9999

100100

101101
def add_flag_env(jobs: dict[str, Any]):
102+
flag_value = flag_env() # Compute flag_env once and reuse the result
102103
for job in jobs.values():
103104
if "steps" in job:
104105
job.setdefault("env", {})
105-
job["env"]["flags"] = flag_env()
106+
job["env"]["flags"] = flag_value
106107
for step in job["steps"]:
107108
if "run" in step:
108-
step["run"] = step["run"].replace("${{ env.flags }}", flag_env())
109+
step["run"] = step["run"].replace("${{ env.flags }}", flag_value)
109110

110111

111112
def generate__benchmark(src: Any) -> Any:

0 commit comments

Comments
 (0)