Skip to content

Commit be51733

Browse files
committed
squash-me, remove dead code, add generated file header
1 parent 449c371 commit be51733

File tree

3 files changed

+8
-112
lines changed

3 files changed

+8
-112
lines changed

.github/workflows/build-notebooks.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This file is autogenerated by /home/jdanek/repos/notebooks/gen_gha_matrix_jobs.py DO NOT EDIT BY HAND
12
{
23
"name": "Build Notebooks",
34
"permissions": {

gen_gha_matrix_jobs.py

+7-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
2-
import math
3-
import os
2+
import pathlib
43
import re
54
import string
65
from typing import Iterable, cast
@@ -60,31 +59,6 @@ def extract_target_dependencies(lines: Iterable[str]) -> dict[str, list[str]]:
6059
return tree
6160

6261

63-
def compute_target_distances_from_root(tree: dict[str, list[str]]) -> dict[str, int]:
64-
levels = {key: math.inf for key in tree}
65-
66-
# roots have distance of 0
67-
roots = [key for key, value in tree.items() if not value]
68-
for root in roots:
69-
levels[root] = 0
70-
71-
# iterate through undetermined targets and try to compute their distance
72-
# this is an inefficient quadratic loop, but it does not matter here
73-
while math.inf in levels.values():
74-
changed = False
75-
for key, value in levels.items():
76-
if value == math.inf:
77-
dist = max(levels[dep] for dep in tree[key])
78-
if dist < math.inf:
79-
levels[key] = dist + 1
80-
changed = True
81-
if not changed:
82-
raise Exception("Iteration did not make any progress")
83-
84-
# math.inf is a float; at this point we know all inf values were replaced by integral distances
85-
return cast(dict[str, int], levels)
86-
87-
8862
def print_github_actions_matrix(levels: dict[str, int]) -> list[str]:
8963
"""Outputs GitHub matrix definition Json as per
9064
"""
@@ -103,7 +77,7 @@ def print_github_actions_matrix(levels: dict[str, int]) -> list[str]:
10377
lines.append(f"level{level}={json.dumps(matrix, separators=(",", ":"))}")
10478
return lines
10579

106-
def write_github_workflow_file(tree: dict[str, list[str]]) -> None:
80+
def write_github_workflow_file(tree: dict[str, list[str]], path: pathlib.Path) -> None:
10781
jobs = {}
10882

10983
# IDs may only contain alphanumeric characters, '_', and '-'. IDs must start with a letter or '_' and must be less than 100 characters.
@@ -143,26 +117,21 @@ def write_github_workflow_file(tree: dict[str, list[str]]) -> None:
143117
"jobs": jobs,
144118
}
145119

146-
with open(".github/workflows/build-notebooks.yaml", "wt") as f:
120+
with open(path, "wt") as f:
121+
print("# This file is autogenerated by", __file__, "DO NOT EDIT BY HAND", file=f)
147122
# every json file is a valid yaml file
148123
json.dump(workflow, f, sort_keys=False, indent=4)
149124

150125

151126
def main() -> None:
127+
cwd = pathlib.Path(__file__).parent.absolute()
128+
152129
# https://www.gnu.org/software/make/manual/make.html#Reading-Makefiles
153130
with open("Makefile", "rt") as makefile:
154131
lines = read_makefile_lines(makefile)
155132
tree = extract_target_dependencies(lines)
156133

157-
levels = compute_target_distances_from_root(tree)
158-
output = print_github_actions_matrix(levels)
159-
160-
write_github_workflow_file(tree)
161-
162-
print(*output, sep="\n")
163-
with open(os.environ["GITHUB_OUTPUT"], "at") as f:
164-
for line in output:
165-
print(line, file=f)
134+
write_github_workflow_file(tree, cwd / ".github" / "workflows" / "build-notebooks.yaml")
166135

167136

168137
if __name__ == '__main__':

gha_lvm_overlay.bash

-74
This file was deleted.

0 commit comments

Comments
 (0)