SPB Git

Repository Public License

make-badges.py 2.6 KB 58 lines python

1#!/usr/bin/env python32# ORIX Audio3# File: Scripts/make-badges.py4# Description: Generates the README's local SVG badges (flat "for-the-badge" style) into docs/assets/badges/.5#6# Author: Simon-Pierre Boucher7# Contact: contact@spboucher.ai8#9# Every badge states something true about the repository at the time of writing. There is no CI, so there is no10# "passing" badge and no coverage badge. Update the Tests and TestFlight entries by hand when they change.11import pathlib12from xml.sax.saxutils import escape1314OUT = pathlib.Path(__file__).resolve().parent.parent / "docs/assets/badges"15APPLE, SWIFT, DSP, VIZ, PRIVACY, AI, DEV = "#007AFF", "#FA7343", "#8B5CF6", "#06B6D4", "#22C55E", "#6366F1", "#F59E0B"16BADGES = [17    ("ios", "iOS", "26+", APPLE),18    ("ipados", "iPadOS", "Adaptive", APPLE),19    ("swift", "Swift", "6", SWIFT),20    ("swiftui", "UI", "SwiftUI", AI),21    ("dsp", "DSP", "Accelerate · vDSP", DSP),22    ("visualization", "Visualization", "Canvas · Core Graphics", VIZ),23    ("speech", "Speech", "On-device", AI),24    ("foundation-models", "Foundation Models", "Where supported", AI),25    ("privacy", "Privacy", "First", PRIVACY),26    ("offline", "Core", "Offline", PRIVACY),27    ("account", "Account", "Not required", PRIVACY),28    ("localized", "Localized", "EN · FR-CA", APPLE),29    ("tests", "Tests", "83 core · 21 app · 9 UI", DEV),30    ("testflight", "TestFlight", "1.0.0 (1) internal", DEV),31]3233def width(text: str) -> int:34    # Approximate advance of 11 px bold uppercase Verdana-like text with 1.1 px tracking.35    return int(sum(5.2 if c in " ·" else 8.4 if c in "MW" else 7.6 for c in text.upper()) + 24)3637def badge(label: str, value: str, color: str) -> str:38    lw, vw = width(label), width(value)39    w = lw + vw40    l, v = escape(label.upper()), escape(value.upper())41    return f'''<svg xmlns="http://www.w3.org/2000/svg" width="{w}" height="28" role="img" aria-label="{escape(label)}: {escape(value)}">42  <title>{escape(label)}: {escape(value)}</title>43  <g shape-rendering="crispEdges">44    <rect width="{lw}" height="28" fill="#1D2236"/>45    <rect x="{lw}" width="{vw}" height="28" fill="{color}"/>46  </g>47  <g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="10.5" font-weight="bold" letter-spacing="1.1">48    <text x="{lw / 2}" y="18" fill="#F2F4FB">{l}</text>49    <text x="{lw + vw / 2}" y="18">{v}</text>50  </g>51</svg>52'''5354OUT.mkdir(parents=True, exist_ok=True)55for name, label, value, color in BADGES:56    (OUT / f"{name}.svg").write_text(badge(label, value, color))57print(f"{len(BADGES)} badges written to {OUT}")58
Files main
Menu

Theme