"""Raises each slide's size level until less than TARGET px would be left, then keeps the last level that fits with at least TARGET px spare.""" import json, subprocess, sys, re root = sys.argv[1]; PY = sys.executable; TARGET = 50 ids = ["results", "method", "gains", "main", "backup", "tokenizer", "tax", "copying", "depth", "switch"] def spare(levels): json.dump(levels, open(f"{root}/build/levels.json", "w")) subprocess.run([PY, f"{root}/build/sparse.py", root], check=True, capture_output=True) out = {} for i in ids: r = subprocess.run([PY, "-I", f"{root}/check/layout_check.py", root, i, "2"], capture_output=True, text=True).stdout assert "PROBLEM" not in r, (i, [l for l in r.splitlines() if "PROBLEM" in l]) out[i] = 1080 - int(float(re.search(r"content height (\d+(?:\.\d+)?) of", r).group(1))) return out levels = {i: 0 for i in ids} best = spare(levels) for i in ids: while levels[i] < 14: levels[i] += 1 try: s = spare(levels) except AssertionError: levels[i] -= 1; break if s[i] < TARGET: levels[i] -= 1; break final = spare(levels) print({i: (levels[i], final[i]) for i in ids})