unsloth/scripts/make_dmg_background.py
Daniel Han 971eb36f48
Trim comments in tests, scripts, CI helpers and unsloth_cli (#10113)
* Trim comments in tests, scripts and CI helpers

Comment-only pass over 453 changed files under tests/ (excluding the
studiobench harness), scripts/ and .github/scripts/.

17,749 -> 10,635 comment lines (-40.1%)
1,183,079 -> 757,190 comment characters (-36.0%)

Distinctive-fact retention against the base commit: 93.2%. A sample of 100
restoration and deletion decisions was judged by hand: 98 correct.

No comment line exceeds 120 physical characters. Nothing outside comments
changes: no code, docstrings, string literals, licence headers or pragmas.
Verified with an AST code-only signature of every file against the base.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Put the moved comments back on the code they describe

The signal-handler rationale in launch.py had been reattached to the
handler registration loop, which has no try/finally, and its except-branch
note had been split into a fragment starting mid-sentence with the noqa
marker duplicated into the prose. The PORT_FILE launcher comments had been
reattached to the _studio_root_id caching test, which does not touch
PORT_FILE.

* Put the section banners back, and use plain dashes in comments

The trim removed the rule-line comments that index these files. Tests locate a
region by finding its banner and end it on the next one, so a missing banner is
a broken anchor rather than lost decoration. Each is restored above the code
line it preceded at 1d2679f; where that anchor is not unique the banner is left
out rather than guessed at.

Em and en dashes are rewritten as plain dashes inside comment tokens only.
String literals are code and are untouched, so the diff stays comment-only.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Put reattached comments back on the code they describe

The comment pass moved a number of explanatory comments off the code they
were written for and onto unrelated statements nearby, so they now read as
false or as truncated fragments. This restores each one at its correct site:

- lint_duplicate_definitions: the import-key rationale goes back on the
  emitted Finding key instead of being half-pasted onto `implicit =`.
- lockfile_supply_chain_audit: "Empty by default" belongs on the empty
  CARGO_IOC_STRINGS tuple, not on the non-empty source allowlist; the
  missing-lockfile and traceback notes go back on their own branches.
- scan_packages: "archives landed in dest" describes the successful pip
  download, not `if not downloaded:`; the backslash-continuation note goes
  back on the continuation check in _scan_line_end.
- interrupted_install_probe: the start_new_session/getpgid note belongs on
  the posix branch that calls getpgid, not on the win32 branch.
- virustotal_scan: the missing-secret rationale goes back on the skip path
  and the :⚠️: note back on the detection print.
- scan_npm_packages: the rmtree cleanup note goes back on the rmtree.
- check_frontend_dep_removal: one per-key rationale per key again, instead
  of five concatenated onto browserslist.
- profile_startup: failed-launch and nothing-measured notes swapped back.
- enforce_kwargs_spacing: fold-rejection reasons back on the guards that
  reject for them, and the f-string fold comment back in order.
- tests/conftest: the bitsandbytes broken-wheel note back on the
  bitsandbytes handler.

Comments only; no code, string literal, docstring or pragma changes.

* Repair the banner restore: drop duplicate headings, keep the blank line

The scripted restore re-added each section banner without removing the
de-bannered plain heading the trim had left behind, so a heading appeared
twice, once ruled and once bare. It also inserted the banner flush against the
next line of code where the base had a blank line after it, which turns a
section separator into a doc comment for whichever def follows.

Both are the same fault the trim itself was being screened for, introduced by
the remediation rather than by the trim.

* Reattach 12 review comments to the code they describe

Each of these was a rationale that ended up on a neighbouring test or
assertion, or a fragment cut mid-sentence, so it described something
other than the line under it.

- test_gguf_disk_preflight: the 3GB-embeddings arithmetic belongs to the
  untied case, not the tied one (2GB there).
- lockfile_supply_chain_audit: reassemble the workflow-command escaping
  rationale on the skip branch.
- studio_smoke/multi_turn_chat: restore the retry-policy explanation in
  main().
- test_virustotal_scan: restore the advisory-posture rationale on the
  scan step.
- test_amd_fastpath_probe: return each ROCm rationale to its parameter
  row.
- test_cuda_repair: the Blackwell span note goes back on the Blackwell
  test; complete the Kepler sentence.
- test_windows_rocm_bnb_version: realign the sitecustomize / opt-out
  rationales with their cases.
- test_dataset_num_proc: the Pool(1) note belongs to the low-memory auto
  path.
- test_install_whisper_prebuilt_logic: decoy-DLL, libomp, build-bump and
  same-ggml notes back on their own tests; the link copy fallback needs
  none.
- playwright_loaded_models_indicator: stale-eject notes back on their
  sections and the preference banner restored.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Restore the review comments that were cut mid-sentence or reattached to the wrong code

* Restore the comment tails the 120-column pass cut off

The trim enforced the column limit by chopping the physical line rather than
rewrapping it, so a block's last sentence stopped mid-thought and the clause
carrying the reason was gone:

    -# ...fails in a second rather than
    +# ...fails in a second rather than after the quantise and the multi-gigabyte save.

    -# fp8 / mxfp8 need bf16 weights, so skip non-bf16 Linears;
    +# fp8 / mxfp8 need bf16 weights, so skip non-bf16 Linears; nvfp4 handles fp32. Mirrors the runtime gate.

883 blocks across 266 files, restored from the merge base and rewrapped at word
boundaries within 120 columns. Blocks that end on proper punctuation followed by
a new sentence are left alone: those were shortened on purpose, and only a base
that continues the same sentence where the head stops counts as a cut. No word
is invented; every restored word comes from the base. Pragmas, shebangs, coding
lines, licence text and rule-line banners are skipped.

Dangling truncations drop from 336 to 77. Full suite is 65 failed / 18683
passed, matching main exactly, so no test changes behaviour.

* Restore comment tails cut inside a parenthetical or abbreviation

The first repair pass keyed on terminal punctuation, so a block cut after
"(e.g." or mid-code-span looked finished and was left alone. Balance the
brackets and backticks instead, and treat a trailing abbreviation as
mid-sentence:

    -# ...skip the whole module up front on runners without it (e.g.
    +# ...skip the whole module up front on runners without it (e.g. CPU-only) before importing unsloth, otherwise
    +# collection errors instead of producing a skip.

22 further blocks across 20 files. _ts_deps.py is fixed by hand: it had also
lost a sentence from the MIDDLE of the block, so it was not a prefix of the
base text and no prefix rule could reach it.

* Reassemble the review comments that were left scrambled or cut short

Restore the full rationale for the comments the trim pass left as reversed
or truncated fragments, and put the openenv, reasoning-effort and recovery
window notes back on the code they describe.

* Put the scrambled comment blocks back over the code they describe

* Put the inline labels back on the entries they label

* Restore an inline label lost in the merge

* Restore the facts the reworded comments dropped

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Move the displaced notes back onto the tests they describe

* Re-pair the fixture rationales with their fixtures

* Put the relocated notes back and finish the sentences the trim cut

* Restore the dropped facts and correct the ones that were never true

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Unfuse the merged notes and drop the reformatting the trim smuggled in

* Restore the clauses the trim cut off and unfuse the notes it merged

Thirty sites where a comment was shortened past the point it still said
anything. Most ended on a colon or a dangling word, so the reason the
branch exists was gone while the sentence introducing it stayed. The
rest had absorbed a neighbouring test's note, which left one row
documented as another row's behaviour.

Each restored clause was checked against the code under it rather than
copied back on trust. Three were not restored: a pointer to a
measurement that is not in the function it names, a claim that a missing
import fails as NameError when it fails at collection, and a redundant
restatement in the autoscroll check.

tests/kaggle/t4_smoke/training_evidence.py ends up identical to main,
which is the right outcome for a file whose only trimmed sentence was
load-bearing.

* Give back the halves of the comments the trim cut off

Two hundred and twenty comments across a hundred and twenty files had
been shortened to the sentence that introduces a fact and none of the
fact. A note ending on a colon or on "so" or "carried over" still reads
as a comment and still parses, which is why every structural check has
been passing over them: a truncated comment is a well-formed comment.

Most of these were only findable by asking what a block ENDS on rather
than what it starts with. The seven passes before this one all keyed on
the first line, so they were blind to the commonest damage in the whole
trim. The supply-chain audit had seven "Mini Shai-Hulud May-12 wave:"
headers with the package names deleted, which was the entire content of
each one.

A handful were worse than truncated. A "can't fit on one line, so leave
it" note had moved from the test asserting changed is False onto the one
asserting changed is True; the sm_61 and sm_70 rationales in the CUDA
repair tests were stacked on a test that exercises neither, leaving
their own tests bare; an unpinned-latest note sat on a test that stubs a
working install on disk.

Restored clauses were checked against the code under them, not copied
back on trust. Around a dozen were left out or rewritten because the
base was wrong about the code as it stands: a pip stub credited with an
append it does not do, five exports said to be filled by a loop that
fills one, a __dict__ rationale that argues for the opposite of what the
loop needs, and UI strings quoted as current that the sources no longer
use.

* Put the fused row notes back on the rows they are true of

Ten sites where a comment described a sibling. The torchao skew table
had three rows' notes concatenated onto the 0.18.0+cu130 row; the
revision-forwarding table had the adapter-tokenizer exception one row
below the only row it holds for; the vision LoRA pair had the tied and
untied cases on a single anchor.

Four of these were mine, not the trim's. The 120-column rewrap left an
orphaned continuation line sitting on a class, one repair copied an
untagged-build note onto a fixture that pins a URL and has no untagged
build in it, another duplicated a namespace-package note and pushed the
interrupted-install label onto the wrong row, and a fourth moved a
collision note onto a fixture with a single host, where it is false. A
pass that rewrites 220 comments will get some of them wrong, and these
are the ones it got wrong.

Two reported sites were left alone. The masking note in the VirusTotal
client already carries its full clause, reflowed; the IOC scan comment
reads complete, and its missing "4." went with the numbering on every
other step in that function.

* Move the row and branch notes back onto what they describe

Nineteen sites. The token-count parity table had every row comment one
param too low, so each seeded reasoning style was documented as the next
one; the font-scale contract had two rationales slid down a continue
each; the validator fixture banner for R-INST-001 sat under R-INST-005,
leaving three tests unlabelled and two double-labelled.

Three of these I caused. The parity table was misplaced by the previous
commit, which moved fused notes onto rows without checking the seeds
underneath them; a timing bound landed in a test that has no timing
assertion; a restore note was reinserted between the two commands it
claims to cover instead of above them.

The pacing benchmark had lost its measurement table entirely, including
the #7892 result that is the reason there are two budgets rather than
one headline number. Restored with the columns intact.

* Undo the damage the last four repair passes did

Twenty-five sites, and almost none of them were the trim's. Round nine
was called "move the row and branch notes back onto what they describe",
and it moved a good many onto things they do not describe: the xpu swap
tests had the pinned-mirror rationale on the test that asserts the index
is dropped, the cuda repair file had a whole run of rationales slid one
test upward, and several notes were duplicated onto a neighbour rather
than moved. Where a clause was already correct on its real anchor, the
copy is deleted rather than parked somewhere new.

Separately, this PR had been changing code, and the gate could not see
it. Five files: three where a repair split a tuple across lines to make
room for a restored trailing comment, two where the trim deleted a
trailing comment and then joined up the wrapping that existed only to
carry it. Parentheses and line breaks leave the parse tree untouched, so
an AST comparison calls all of it comments. Every one is back to base
byte for byte, with the comments that justified the wrapping restored.

scripts/code_reflow.py is the check for it: same tokens in a different
arrangement is a code change, whatever the AST says.

* Let ruff rejoin the two lines the shorter comments freed

Both were split only to make room for a trailing comment. Round ten cut
those comments back to what is true of the row, the expressions now fit,
and the formatter joins them. Running it is not optional: pre-commit.ci
was red on exactly these two.

* Delete the stray copies rather than move them again

Five sites. Three were duplicates: the correct sentence still sits on
the test it describes, and a repair pass left a second copy on a
neighbour. Moving those would have been the fourth round of shuffling
one clause between two tests, so the copies are simply gone.

The mislabelling was the point in each case. An empty handover tag and
an absent one are different precedence rules, and the PowerShell 7.5
parsing note had been copied from the empty-string test onto the one
whose variable is unset. A non-zero-exit rationale sat on a parser test
that asserts a successful exit.

The other two are the trim's own: "#5854)," with its subject cut away,
and a regex description that stopped before naming the self. prefix it
matches, which is what explains the narrower filter below it.

* Put the nine slid notes back on what they assert

Seven had moved one branch or one call down. The autocast one had landed
on the case that forces float32 and asserts dtype float16, directly
under a note saying there is no dtype at all; the JAX rationale sat on
the USE_FLAX env-var case, whose module map has no jax in it; the
kill-and-sentinel note sat on a test that only checks a GPU row regex.
Each is back on the assert it describes, with a tenth found in the same
file as the probe timeouts.

Two are the trim's own. A mid-block deletion in the settings-tabs driver
spliced two half sentences into "blocking a / error-handling regression
and was a stale constant"; the macOS slot table lost the only statement
of why macos-14 is absent from a set named for images GitHub still
schedules. The retirement dates are restored, verified against all three
workflows that carry them.

The settings-tabs note is shorter than base on purpose. It now says the
invariant, that blocking a panel must not collapse the dialog, and drops
the tab count, which nothing asserts.

* Move twelve more notes back onto the branch they are about

All twelve had slid onto an adjacent test or branch, and in each the
displaced note contradicted what it now sat on. The CPU-backend note
about a wheel being left alone had landed on the test asserting a repair
runs; the XPU one about a dispatched shard sat on the single-device
case; the redirect-body note sat in a test that never binds served; the
draft-state refusal sat on the test where the target is present and the
run returns 0.

One lost text on the way as well: the missing-target rationale had been
cut to its first two sentences, dropping the reason the draft and
prerelease refusal above it would otherwise degrade into no check.

Also a rewrap that duplicated its own tail instead of replacing it, so
the merge-budget note read "else a sharded own device, not GPU0, else a
sharded model OOMs".

* Return six notes to the test whose behaviour they describe

Eight reports, six defects: two pairs described the same misplacement
from either side.

One was worse than misplaced. "A comment naming a probe is not a probe"
had moved onto the metadata scan, whose predicate matches the raw line
with no comment handling at all, so it claimed an exemption that scan
does not implement. It belongs on the Test-Path scan, the only one that
splits on # before matching. Moved, not reworded.

The rest argued against the test they sat on. The lazy-trl note was on
a stub with no __getattr__ to raise; the bogus-variant note was above a
request sending a valid variant; the imported-TensorFlow note was on
the case that supplies no tensorflow and asserts the flag is cleared;
the 62-token rationale was on the test that asserts 12.

* Move ten more notes onto the statement they explain

Seven had slid off their anchor, and in most the stray was also cut
short, so the fix was to restore the whole sentence where it is true and
delete the fragment. The torchao dependency reason sat on a test about
re-verification rather than on the --no-deps assertion it justifies; the
bitsandbytes heading sat on a test that fetches quantizers_utils.py; the
no-selection latch note sat on the delete block, which asserts nothing
reaches the action.

Two are the trim's own truncations. The stand-aside rationale in the
shortcut driver stopped at a colon, losing why Enter on a focused Deny
button would otherwise be defaulted away into approve. The kwargs-union
case stopped at a semicolon, and the trim had eaten the leading ** from
**kwargs as well.

One was about the driver rather than a test: the JSON note sat beside
the final print, where it described the document, instead of on the
stderr redirection that is what actually keeps stdout clean.

* Restore what the reflow cut, including three markers it mangled

Nine sites. Most are the trim's own truncations: the dill fixture had
lost the property that makes lookup by reference fail, so an otherwise
unexplained __module__ = "builtins" sat there with no reason; the rope
drift test had two clauses spliced into "every buffer keeps scaling in a
buffer"; the playwright guard had lost the three command shapes it
matches and why the regex is not anchored on an engine list.

Three are a shape I had not seen. The reflow rewrote the `#:` variable
documentation markers in the fast-copy constructs to `# :`, and dropped
stray colons into the wrapped prose, leaving "text : node". Those
markers are syntax, not punctuation to be tidied.

One was misplacement rather than truncation. The dotted-import rationale
had moved onto the second copy of its case and lost its tail, leaving a
dangling "and" above a capitalised "Still caught" and the first row bare.
Restored where base has it, stray deleted.

lint_duplicate_definitions self-test still passes, 63 cases.

* Put five drifted comments back on the code they describe

The trim slid several notes onto neighbouring tests, where they describe
something they no longer sit on:

- test_qat.py: the TODO moved off _test_full_model_fake_quantize, whose
  leading underscore is what keeps pytest from collecting it, onto a test
  that is collected and was never disabled.
- playwright_chat_ime_i18n.py: 6f carried a stray copy of 6e's
  compositionstart note above an Enter KeyboardEvent, and had lost its own
  rationale for why Enter reports isComposing=false while composingRef is
  pinned.
- test_install_node_prebuilt_logic.py: the short-circuit note landed on the
  transient-download-failure test, leaving the SHA-enforcement test bare and
  dropping the carve-out that a different usable version is still kept for
  offline resilience.
- test_chat_autoload_failure_gate.py: the default/namespace note moved onto
  the named-import loop, and the mixed-form note explaining that regex's
  optional prefix was dropped.
- test_frontend_dep_removal.py: the unquoted CSS url() note moved onto the
  quoted fixture, and the HTML package-name-boundary note moved off the
  script-src case onto the link-href case.

Comments only; the gate reports code unchanged on all five files.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: danielhanchen <michaelhan2050@gmail.com>
2026-09-04 15:31:50 -07:00

198 lines
7 KiB
Python

#!/usr/bin/env python3
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
"""Render the macOS DMG install-window background.
Writes studio/src-tauri/dmg/background.tiff, the image Finder draws behind the
app icon and the Applications alias when the disk image opens.
The layout is tied to the Finder coordinates in studio/src-tauri/tauri.macos.conf.json.
Finder maps icon positions onto the background from the same origin, so the base
page has to match dmg.windowSize exactly or the artwork slides out from under the
icons. tests/studio/test_tauri_branding_contract.py holds that contract.
Output is a two-page TIFF: a base page at window size and a second page at twice
that, which is how Finder picks up a sharp image on a retina display.
"""
from __future__ import annotations
import subprocess
import tempfile
from pathlib import Path
import numpy as np
from PIL import Image, ImageDraw
REPO = Path(__file__).resolve().parents[1]
OUTPUT = REPO / "studio/src-tauri/dmg/background.tiff"
# window geometry in points, mirroring tauri.macos.conf.json
WIN_W, WIN_H = 660, 400
APP_X, APP_Y = 180, 170
APPS_X, APPS_Y = 480, 170
# the base page renders at 1pt per pixel, the hidpi page at SCALE
SCALE = 2
W, H = WIN_W * SCALE, WIN_H * SCALE
# Finder's title bar and bottom path bar eat the rest of the window, so only about this much of the image is ever on
# screen. measured, not derived.
VISIBLE_H = 340
TOP_COLOR = "#FFFFFF"
BOTTOM_COLOR = "#F5F8F7"
# One brand green fading to a lighter green further out.
GLOW_CORE = "#17B88B"
GLOW_EDGE = "#7BE8A6"
GLOW_EDGE_MIX = 0.45
GLOW_MIX_RADIUS = 110.0
# strength is the peak tint, sigma sets how far the halo reaches.
GLOW_STRENGTH = 1.48
GLOW_SIGMA = 50.0
# the icon label sits just below the icon, so the halo is eased off down there.
# the taper waits until START, which is inside the icon's own lower half, so the
# disc still reads round and the transition is hidden behind the artwork rather
# than eating the visible bottom edge. left, right and top keep the full falloff.
GLOW_BOTTOM_FLOOR = 0.25
GLOW_BOTTOM_START = 50.0
GLOW_BOTTOM_SPAN = 30.0
# chevron between the two icons, sized to match the macOS installers this mirrors:
# a light 16x27pt mark in neutral grey, not a heavy arrow.
CHEVRON_HALF_W, CHEVRON_HALF_H = 8.0, 13.5
CHEVRON_STROKE = 6.0
CHEVRON_COLOR = (87, 87, 87, 255)
# ImageDraw has no anti-aliasing, so the chevron is drawn oversized and scaled back down.
CHEVRON_SUPERSAMPLE = 4
def hex_rgb(value: str) -> np.ndarray:
value = value.lstrip("#")
return np.array([int(value[i : i + 2], 16) / 255.0 for i in (0, 2, 4)], dtype = np.float32)
def smoothstep(edge: np.ndarray) -> np.ndarray:
clamped = np.clip(edge, 0.0, 1.0)
return clamped * clamped * (3.0 - 2.0 * clamped)
def base_canvas() -> np.ndarray:
ramp = np.linspace(0.0, 1.0, H, dtype = np.float32)[:, None, None]
return hex_rgb(TOP_COLOR) * (1.0 - ramp) + hex_rgb(BOTTOM_COLOR) * ramp
def render_glow(canvas: np.ndarray) -> np.ndarray:
ys, xs = np.mgrid[0:H, 0:W].astype(np.float32)
cx, cy = APP_X * SCALE, APP_Y * SCALE
sigma = GLOW_SIGMA * SCALE
radius = np.sqrt((xs - cx) ** 2 + (ys - cy) ** 2)
weight = GLOW_STRENGTH * np.exp(-(radius**2) / (2.0 * sigma**2))
# smoothstep, so the taper eases in and out with no seam at either end
taper = smoothstep((ys - cy - GLOW_BOTTOM_START * SCALE) / (GLOW_BOTTOM_SPAN * SCALE))
weight = weight * (1.0 - (1.0 - GLOW_BOTTOM_FLOOR) * taper)
# a peak strength above 1 saturates the core rather than extrapolating past
# the glow colour. that core sits under the app icon either way.
weight = np.clip(weight, 0.0, 1.0)[..., None]
mix = (GLOW_EDGE_MIX * smoothstep(radius / (GLOW_MIX_RADIUS * SCALE)))[..., None]
color = hex_rgb(GLOW_CORE) * (1.0 - mix) + hex_rgb(GLOW_EDGE) * mix
return canvas * (1.0 - weight) + color * weight
def draw_chevron(image: Image.Image) -> None:
"""Rounded chevron pointing from the app icon toward Applications."""
ss = CHEVRON_SUPERSAMPLE
layer = Image.new("RGBA", (image.width * ss, image.height * ss), (0, 0, 0, 0))
draw = ImageDraw.Draw(layer)
cx = ((APP_X + APPS_X) / 2) * SCALE * ss
cy = APP_Y * SCALE * ss
half_w, half_h = CHEVRON_HALF_W * SCALE * ss, CHEVRON_HALF_H * SCALE * ss
stroke = CHEVRON_STROKE * SCALE * ss
points = [(cx - half_w, cy - half_h), (cx + half_w, cy), (cx - half_w, cy + half_h)]
draw.line(points, fill = CHEVRON_COLOR, width = int(stroke), joint = "curve")
for x, y in points:
draw.ellipse(
[x - stroke / 2, y - stroke / 2, x + stroke / 2, y + stroke / 2],
fill = CHEVRON_COLOR,
)
image.alpha_composite(layer.resize(image.size, Image.LANCZOS))
def build() -> Image.Image:
canvas = render_glow(base_canvas())
pixels = np.clip(canvas * 255.0 + 0.5, 0, 255).astype(np.uint8)
image = Image.fromarray(pixels).convert("RGBA")
draw_chevron(image)
return image
def report() -> None:
"""Print how the halo sits relative to the icon and its label."""
base = base_canvas()
# the halo on its own, with the base gradient taken back out so the vertical ramp does not read as part of it
halo = np.clip(base - render_glow(base), 0.0, None).max(axis = 2)
cx, cy = APP_X * SCALE, APP_Y * SCALE
# 60pt is the disc a viewer reads as round, 90pt is out in the label's row
for distance in (60, 90):
for name, sample in (
("left", halo[cy, cx - distance * SCALE]),
("right", halo[cy, cx + distance * SCALE]),
("up", halo[cy - distance * SCALE, cx]),
("down", halo[cy + distance * SCALE, cx]),
):
print(f" {name:<5} at {distance}pt {sample * 100:5.1f}%")
visible = np.nonzero(halo[cy, :cx] > 0.03)[0]
print(f" reach {(cx - visible.min()) / SCALE:5.0f}pt")
label = halo[238 * SCALE : 260 * SCALE, 140 * SCALE : 220 * SCALE]
print(f" icon label {label.mean() * 100:5.1f}% mean, {label.max() * 100:5.1f}% peak")
def write_tiff(image: Image.Image, destination: Path) -> None:
"""Combine a base and a hidpi page into the multi-page TIFF Finder expects."""
with tempfile.TemporaryDirectory() as workspace:
base_page = Path(workspace) / "base.png"
hidpi_page = Path(workspace) / "hidpi.png"
image.resize((WIN_W, WIN_H), Image.LANCZOS).convert("RGB").save(base_page)
image.convert("RGB").save(hidpi_page)
destination.parent.mkdir(parents = True, exist_ok = True)
subprocess.run(
[
"tiffutil",
"-cathidpicheck",
str(base_page),
str(hidpi_page),
"-out",
str(destination),
],
check = True,
stdout = subprocess.DEVNULL,
)
def main() -> None:
write_tiff(build(), OUTPUT)
report()
print(f"wrote {OUTPUT.relative_to(REPO)}")
if __name__ == "__main__":
main()