From 4f7b4c62025cc3a54ad7310f68a96e28f7caadc2 Mon Sep 17 00:00:00 2001 From: Patrick Ballard Date: Fri, 4 Dec 2026 21:01:36 +0000 Subject: [PATCH 1/3] Add the "Failed building wheel?" hub page /tracker/failed-building-wheel/ lists, per platform, the top packages pip builds from source on a regular Python (newest Python first, then those that only build on an older one), and those with no wheel and no sdist, by download rank, each linking its package page with the way-out hint the page shows. Built from the committed coverage.json at publish time, right after the package pages, and added to the sitemap. Every package page with a "Why the install fails" section now links its platforms' lists on the hub; the home page's More line and the Install-time builds page link the hub too. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/scan.yml | 5 + README.md | 1 + scripts/build_failed_building_wheel.py | 332 +++++++++++++++++++++++ scripts/build_install_builds.py | 17 +- scripts/build_pages.py | 27 +- site/index.html | 2 +- tests/test_failed_building_wheel_page.py | 217 +++++++++++++++ 7 files changed, 593 insertions(+), 8 deletions(-) create mode 100644 scripts/build_failed_building_wheel.py create mode 100644 tests/test_failed_building_wheel_page.py diff --git a/.github/workflows/scan.yml b/.github/workflows/scan.yml index 82b61a0..3b36f4e 100644 --- a/.github/workflows/scan.yml +++ b/.github/workflows/scan.yml @@ -379,6 +379,11 @@ jobs: if ! python3 scripts/build_api.py _site; then echo "::warning::couldn't build the Data API page" fi + # The "Failed building wheel?" hub, from this scan's data/coverage.json (no network). Unguarded, like the + # campaign pages: every package page with a "Why the install fails" section links back to it, so if it + # can't be built the deploy stops rather than publish those links dead. Before the Install-time builds page, + # which links it only if it was built. + python3 scripts/build_failed_building_wheel.py data/coverage.json _site python3 scripts/build_campaigns.py data/coverage.json data/history.json data/changes.json campaigns.toml _site # Extra home-page card and platform-page section: if it fails, the card says the list isn't available and # the platform pages leave the section out (they warn about the missing file) rather than stopping the deploy. diff --git a/README.md b/README.md index 26f32c4..13d870f 100644 --- a/README.md +++ b/README.md @@ -187,6 +187,7 @@ curl -sfL --max-time 60 -o _site/data/gap-wheels.json https://wheelgap.github.io curl -sfL --max-time 60 -o _site/data/status.json https://wheelgap.github.io/wheels/data/status.json \ || echo "::warning::couldn't download status.json from wheelgap.github.io/wheels" python3 scripts/build_pages.py data/coverage.json _site notes _site/data/gap-wheels.json _site/data/status.json +python3 scripts/build_failed_building_wheel.py data/coverage.json _site python3 scripts/build_campaigns.py data/coverage.json data/history.json data/changes.json campaigns.toml _site python3 scripts/build_blockers.py data/coverage.json _site/data/blockers.json python3 scripts/build_free_threaded.py data/upstream-fixes-freethreaded.json data/builds.json data/coverage.json _site --proofs data/upstream-proofs.json diff --git a/scripts/build_failed_building_wheel.py b/scripts/build_failed_building_wheel.py new file mode 100644 index 0000000..e1b7549 --- /dev/null +++ b/scripts/build_failed_building_wheel.py @@ -0,0 +1,332 @@ +"""Publish the "Failed building wheel?" hub from the nightly scan (data/coverage.json): for each platform, the top +packages pip builds from source there on a regular Python (the ones whose package page is titled "Failed building +wheel for NAME?"), and those with no wheel and no source (titled "No matching distribution found for NAME?"), each +linking its package page, with the release that has a wheel where the scan found one. + + python3 scripts/build_failed_building_wheel.py data/coverage.json _site + +Writes /failed-building-wheel/index.html and adds it to /sitemap.xml, so run it after build_pages.py, which +writes the sitemap and the package pages that link back here, and before build_install_builds.py, which links it once +it's built. Reads the committed coverage file only, never the network. Plain HTML, no JavaScript, under the site's usual +CSP; every value from the file is escaped. A file of another shape stops with an error. +""" + +from __future__ import annotations + +import html +import json +import sys +from pathlib import Path + +if __package__: # imported as scripts.build_failed_building_wheel (the tests) + from . import build_campaigns, build_pages +else: + import build_campaigns + import build_pages + +BASE = build_pages.BASE_URL +PATH = "failed-building-wheel/" +URL = f"{BASE}{PATH}" +ROOT = "../" +TITLE = "Failed building wheel? Which PyPI packages build from source on your platform" +# The native platforms, in the package pages' order. Pyodide is left out: nobody's pip builds there. +PLATFORM_NAMES = {k: v for k, v in build_pages.PLATFORM_NAMES.items() if k != "pyodide"} +COMMAND = "pip install -r requirements.txt 2>&1 | uvx wheelgap --from-log -" + + +def regular(target: dict) -> bool: + """A target the package pages' titles count: a native platform on a regular (not free-threaded) Python.""" + return target["platform"] in PLATFORM_NAMES and not target["python"].endswith("t") + + +def missing_id(platform: str) -> str: + """The anchor of a platform's "No matching distribution found" list (its "Failed building wheel" section's is + the platform itself).""" + return f"missing-{platform}" + + +def check(data: object) -> list[str]: + """What's wrong with a coverage file for this page, or [].""" + if not isinstance(data, dict): + return ["not a JSON object"] + problems = [] + if data.get("schema") != build_pages.SCAN_SCHEMA: + problems.append(f"schema {data.get('schema')!r}, expected {build_pages.SCAN_SCHEMA}") + targets = data.get("targets") + packages = data.get("packages") + if not isinstance(targets, list) or not all( + isinstance(t, dict) and all(isinstance(t.get(k), str) for k in ("label", "python", "platform")) for t in targets + ): + problems.append("targets isn't a list of targets with labels, Pythons and platforms") + targets = None + elif not any(regular(t) for t in targets): + problems.append("no regular Python on a native platform") + if not isinstance(packages, list): + problems.append("packages isn't a list") + elif targets is not None: + for p in packages: + if not isinstance(p, dict) or not isinstance(p.get("name"), str) or type(p.get("rank")) is not int: + problems.append("a package has no name or rank") + break + results = p.get("results") + if not isinstance(results, list) or len(results) != len(targets): + problems.append(f"{p['name']}: results don't match the targets") + break + return problems + + +def newest_python(targets: list[dict]) -> str: + return max({t["python"] for t in targets if regular(t)}, key=build_pages.python_key) + + +def _hint(package: dict, labels: dict[str, str], pythons: list[str], newest: str) -> str: + """The way out the package page's cell shows (scan_way_out.py's hint), for the newest of `pythons` that has one, + naming that Python when it isn't the newest in the scan.""" + way_out, _ = build_pages.clean_way_out(package.get("way_out", {})) + for py in sorted(pythons, key=build_pages.python_key, reverse=True): + if hint := way_out.get(labels[py]): + text = ( + f"{hint['release']} is the last release with a wheel here" + if hint["kind"] == "older" + else f"Upgrade to {hint['release']} for a wheel here" + ) + return text if py == newest else f"{text} (Python {py})" + return "" + + +def groups(data: dict) -> dict[str, dict[str, list[dict]]]: + """Per platform, the packages that build from source (`source`) and those with no wheel and no source + (`missing`) on a regular Python there, by rank. Each entry: the package, the regular Pythons with that status + there (oldest first), whether the newest regular Python in the scan is one of them, and the way-out hint.""" + targets = data["targets"] + newest = newest_python(targets) + platforms = [pl for pl in PLATFORM_NAMES if any(t["platform"] == pl and regular(t) for t in targets)] + out: dict[str, dict[str, list[dict]]] = {pl: {"source": [], "missing": []} for pl in platforms} + for p in sorted(data["packages"], key=lambda p: p["rank"]): + if p.get("error"): + continue # its page has no answer section either + for pl in platforms: + labels: dict[str, dict[str, str]] = {"source": {}, "missing": {}} + for t, status in zip(targets, p["results"]): + if t["platform"] == pl and regular(t) and status in labels: + labels[status][t["python"]] = t["label"] + for status, found in labels.items(): + if not found: + continue + pythons = sorted(found, key=build_pages.python_key) + out[pl][status].append({ + "package": p, + "pythons": pythons, + "newest": newest in found, + "hint": _hint(p, found, pythons, newest), + }) # fmt: skip + return out + + +def _entry(item: dict, page_names: set[str], newest: str) -> str: + """One package on one line: its name (linking its page when it has one), version, rank, the Pythons and the hint.""" + e = html.escape + p = item["package"] + slug = build_pages.canonical(p["name"]) + name = ( + f'{e(p["name"])}' + if slug in page_names and build_pages.SAFE_NAME.fullmatch(slug) + else e(p["name"]) + ) + version = f" {e(str(p['version']))}" if p.get("version") else "" + others = [py for py in item["pythons"] if py != newest] + if not item["newest"]: + pythons = f"Python {', '.join(others)} only" + elif others: + pythons = f"also Python {', '.join(others)}" + else: + pythons = f"Python {newest} only" + parts = [f"#{p['rank']:,}", e(pythons)] + ([e(item["hint"])] if item["hint"] else []) + return f"
  • {name}{version} · {' · '.join(parts)}
  • " + + +def _list(items: list[dict], page_names: set[str], newest: str) -> str: + return "
      " + "".join(_entry(item, page_names, newest) for item in items) + "
    " + + +def _fold(summary: str, items: list[dict], page_names: set[str], newest: str, fold_id: str = "") -> str: + attr = f' id="{html.escape(fold_id, quote=True)}"' if fold_id else "" + return ( + f'

    {html.escape(summary)}

    ' + + _list(items, page_names, newest) + + "
    " + ) + + +def _summary_table(grouped: dict, newest: str) -> str: + e = html.escape + rows = [] + for pl, g in grouped.items(): + on_newest = sum(item["newest"] for item in g["source"]) + missing = len(g["missing"]) + missing_cell = f'{missing:,}' if missing else "0" + rows.append( + f'{e(PLATFORM_NAMES[pl])}' + f"{on_newest:,}{len(g['source']):,}{missing_cell}" + ) + return ( + build_campaigns.table_open("Top packages that fail to install from a wheel, per platform", "caption-summary") + + 'Platform' + f'Build from source on Python {e(newest)}' + 'On any regular Python' + 'No matching distribution' + "" + "".join(rows) + "" + ) + + +def _platform_section(pl: str, items: list[dict], page_names: set[str], newest: str, pythons: list[str]) -> str: + e = html.escape + name = PLATFORM_NAMES[pl] + current = [item for item in items if item["newest"]] + older = [item for item in items if not item["newest"]] + everywhere = sum(len(item["pythons"]) == len(pythons) for item in current) + every = f"; {everywhere:,} of them on every regular Python the scan checks ({e(', '.join(pythons))})" + text = ( + f"

    {len(current):,} of the top packages have no wheel for Python {e(newest)} on {e(name)}, so pip builds " + f"them from source" + + (every if len(pythons) > 1 else "") + + "." + + (f" {len(older):,} more build from source here only on an older Python." if older else "") + + "

    " + ) + lists = "" + if current: + lists += _fold(f"The {len(current):,} on Python {newest}, most downloaded first", current, page_names, newest) + if older: + lists += _fold(f"The {len(older):,} only on an older Python", older, page_names, newest) + return f'

    {e(name)}

    {text}{lists}
    ' + + +def description(grouped: dict, total: int) -> str: + building = len({item["package"]["name"] for g in grouped.values() for item in g["source"]}) + return ( + f"pip's \"Failed building wheel\" means no wheel fits your platform and Python. The {building:,} of PyPI's top " + f"{total:,} packages that build from source, per platform, and the fix." + ) + + +def page(data: dict, page_names: set[str]) -> str: + """page_names: the canonical names that have a package page (build_pages.py writes one per safe, unique name).""" + e = html.escape + grouped = groups(data) + newest = newest_python(data["targets"]) + pythons = sorted({t["python"] for t in data["targets"] if regular(t)}, key=build_pages.python_key) + total = len(data["packages"]) + summary = description(grouped, total) + lede = ( + "pip and uv install a prebuilt wheel when one fits your platform and Python. When none does, they download " + "the package's source and build it on your machine, which needs a compiler and the libraries the package " + "links against; without them the install stops with "Failed building wheel for NAME". Where a " + "package has no wheel and no source either, pip stops with "No matching distribution found"." + ) + meta = ( + f'

    From the nightly scan of {e(str(data.get("generated", ""))[:10])} of PyPI\'s {total:,} most ' + f"downloaded packages, with wheelgap {e(str(data.get('wheelgap', '')))}.

    " + ) + ways = ( + '

    The ways out

    ' + "

    Easiest first:

      " + "
    • Use a Python and platform that has a wheel: each package's page shows which do.
    • " + "
    • Install a release that has one: the lists below name it where the scan found one.
    • " + "
    • Give the build what it needs: a compiler and the package's system libraries.
    • " + "
    " + '
    " + ) + sections = "".join( + _platform_section(pl, g["source"], page_names, newest, pythons) for pl, g in grouped.items() + ) + missing = "".join( + _fold(f"{PLATFORM_NAMES[pl]}: {len(g['missing']):,}", g["missing"], page_names, newest, missing_id(pl)) + for pl, g in grouped.items() + if g["missing"] + ) + content = ( + ways + + '

    By platform

    ' + "

    How many of the top packages have no wheel that fits, per platform. Regular Pythons are " + f"{e(', '.join(pythons))}: free-threaded builds and Pyodide aren't counted.

    " + + _summary_table(grouped, newest) + + "
    " + + sections + + '

    No matching distribution found

    ' + "

    These have no wheel that fits and no source to build, so pip has nothing to install. An unpinned install " + "falls back to an older release that has a file for the platform, if there is one (named where the scan " + "found it); otherwise pip stops with "No matching distribution found".

    " + + (missing or "

    None on any platform in this scan.

    ") + + "
    " + + '

    What this counts

    ' + "

    Each package's latest release on PyPI, checked the way pip and uv pick files, for each Python and " + "platform. A package builds from source on a target when no wheel it publishes fits there and it has a " + "source distribution. Dependencies aren't counted here: each package's page shows its whole install.

    " + f'

    Source data: data/coverage.json.

    ' + "
    " + f'

    Wheel coverage by platform · Check a repo' + f' · Search packages

    ' + ) + ld = build_pages.json_ld_block({ + "@context": "https://schema.org", + "@type": "CollectionPage", + "name": TITLE, + "description": summary, + "url": URL, + "isPartOf": {"@type": "WebSite", "name": "wheelgap tracker", "url": BASE}, + }) # fmt: skip + return f""" + + + + + + {e(TITLE)} + +{build_campaigns.og_tags(TITLE, summary, URL)} + +{build_campaigns.stylesheets(ROOT)} + + + +{build_campaigns.site_header(ROOT)} +
    +

    {e(TITLE)}

    +

    {lede}

    + {meta} +
    +
    {content}
    +{build_campaigns.FOOTER} +{ld} +""" + + +def build(coverage_path: Path, site: Path) -> Path: + try: + data = json.loads(coverage_path.read_text(encoding="utf-8")) + except (OSError, ValueError) as err: + sys.exit(f"build_failed_building_wheel: {coverage_path}: {err}") + if problems := check(data): + sys.exit(f"build_failed_building_wheel: {coverage_path}: " + "; ".join(problems[:5])) + page_names = {build_pages.canonical(p["name"]) for p in data["packages"]} + out = site / PATH + out.mkdir(parents=True, exist_ok=True) + path = out / "index.html" + path.write_text(page(data, page_names), encoding="utf-8") + build_campaigns.add_to_sitemap(site, [URL]) + return path + + +if __name__ == "__main__": + if len(sys.argv) != 3: + sys.exit("usage: build_failed_building_wheel.py COVERAGE SITE") + written = build(Path(sys.argv[1]), Path(sys.argv[2])) + print(f"failed building wheel: wrote {written}") diff --git a/scripts/build_install_builds.py b/scripts/build_install_builds.py index 1742abd..557a32e 100644 --- a/scripts/build_install_builds.py +++ b/scripts/build_install_builds.py @@ -5,7 +5,8 @@ python3 scripts/build_install_builds.py data/coverage.json _site Writes /platforms/install-builds/index.html and adds it to /sitemap.xml, so run it after build_pages.py, which -writes the sitemap, and after build_lockdown_page.py, whose page it links once it's built. Plain HTML, no JavaScript, under the site's usual CSP; every value from the file is escaped. A +writes the sitemap, and after build_lockdown_page.py and build_failed_building_wheel.py, whose pages it links once +they're built. Plain HTML, no JavaScript, under the site's usual CSP; every value from the file is escaped. A file of another shape stops with an error, so the publish step can warn and leave the page out. """ @@ -141,8 +142,9 @@ def _floors(data: dict) -> str: return f"glibc {t.get('glibc')}, musl {t.get('musl')}, macOS {t.get('macos')}" -def page(data: dict, page_names: set[str], lockdown: bool = False) -> str: - """lockdown: whether the Lockdown page (build_lockdown_page.py) is in the site, so the page links it.""" +def page(data: dict, page_names: set[str], lockdown: bool = False, hub: bool = False) -> str: + """lockdown: whether the Lockdown page (build_lockdown_page.py) is in the site, so the page links it. hub: the same + for the "Failed building wheel?" hub (build_failed_building_wheel.py).""" e = html.escape built = counts(data) total = len(data["packages"]) @@ -190,6 +192,12 @@ def page(data: dict, page_names: set[str], lockdown: bool = False) -> str: + f"

    The {min(len(main), LIMITS):,} most downloaded of the {len(main):,} packages that build from source " "there, and on how many of the targets above each does.

    " + build_platform_pages.rows_fold(_list(main, page_names, data), min(len(main), LIMITS)) + + ( + f'

    Every package that builds from source, on each platform, with the release that has a wheel: ' + f'Failed building wheel?

    ' + if hub + else "" + ) + "" + '

    What this counts

    ' "

    Each package's latest release on PyPI, checked the way pip and uv pick files, for each Python and " @@ -220,7 +228,8 @@ def build(coverage_path: Path, site: Path) -> Path: path = out / "index.html" # The Lockdown page is built first (scan.yml); linked only once it's there, so a failed build leaves no dead link. lockdown = (site / "lockdown" / "index.html").is_file() - path.write_text(page(data, page_names, lockdown), encoding="utf-8") + hub = (site / "failed-building-wheel" / "index.html").is_file() + path.write_text(page(data, page_names, lockdown, hub), encoding="utf-8") build_campaigns.add_to_sitemap(site, [URL]) return path diff --git a/scripts/build_pages.py b/scripts/build_pages.py index 51760d2..869e7a5 100644 --- a/scripts/build_pages.py +++ b/scripts/build_pages.py @@ -305,13 +305,32 @@ def gap_platforms(package: dict, targets: list[dict], statuses: tuple[str, ...] return [pl for pl in PLATFORM_NAMES if pl in found] +# The "Failed building wheel?" hub (build_failed_building_wheel.py), from a package page. The publish step builds it +# from the same coverage.json, right after these pages, and stops if it can't, so the link is never dead. +HUB = "../../failed-building-wheel/" + + +def hub_line(platforms: list[str], *, builds: bool) -> str: + """The answer's link back to the hub's list for each platform in `platforms` where the package has the page's error + (the hub's anchors: the platform for building from source, missing- for no distribution).""" + if not platforms: + return "" + e = html.escape + anchor = "" if builds else "missing-" + links = join_names([f'{e(PLATFORM_NAMES[pl])}' for pl in platforms]) + what = "build from source" if builds else "have no matching distribution" + return f"

    All the top packages that {what} on {links}.

    \n" + + def answer_html( - name: str, version: str, python: str, example: str, platforms: list[str], *, builds: bool + name: str, version: str, python: str, example: str, platforms: list[str], *, builds: bool, + hub: list[str] | None = None, ) -> tuple[str, str]: """The short answer for someone who arrived with the install's error ("Failed building wheel for NAME", or pip's "No matching distribution found" where there's no sdist to build): why it happens, where it does for this package (`platforms`, on a regular Python), the ways out, and a command for `python` on `example`, a platform where that - Python has the error.""" + Python has the error. hub: the platforms whose list on the "Failed building wheel?" hub the answer links (those + where a regular Python has the page's error).""" e = html.escape where = ", ".join(PLATFORM_NAMES[pl] for pl in platforms) if builds: @@ -351,6 +370,7 @@ def answer_html( f"

    {ways}

    \n" f"

    {e(tool_intro)}

    \n" f"
    {e(command)}
    \n" + f"{hub_line(hub or [], builds=builds)}" "
    \n" ) error = "Failed building wheel for" if builds else "No matching distribution found for" @@ -754,7 +774,8 @@ def page( example_python = preferred if preferred in pythons else max(pythons, key=install_results.python_key) example_platform = next(pl for pl in PLATFORM_NAMES if (example_python, pl) in kind) where = [pl for pl in PLATFORM_NAMES if any(p == pl for _, p, _ in cells)] - answer, faq = answer_html(name, version, example_python, example_platform, where, builds=builds) + hub = [pl for pl in PLATFORM_NAMES if any(p == pl for _, p in kind)] + answer, faq = answer_html(name, version, example_python, example_platform, where, builds=builds, hub=hub) campaign_links = [] for status, campaign in campaigns or []: link = f'{e(campaign["title"])}' diff --git a/site/index.html b/site/index.html index da378f5..cae0b59 100644 --- a/site/index.html +++ b/site/index.html @@ -458,7 +458,7 @@

    Build lab: no wheel, but does it build?