Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 90 additions & 6 deletions scripts/build_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,65 @@ def note_text(text: str) -> str:
)


def gap_platforms(package: dict, targets: list[dict]) -> list[str]:
"""Platforms where some target builds from source or can't install, in PLATFORM_NAMES order."""
def gap_platforms(package: dict, targets: list[dict], statuses: tuple[str, ...] = GAP) -> list[str]:
"""Platforms where some target builds from source or can't install (or has one of `statuses`), in PLATFORM_NAMES
order."""
if package.get("error"):
return []
found = {t["platform"] for t, r in zip(targets, package["results"]) if r in GAP}
found = {t["platform"] for t, r in zip(targets, package["results"]) if r in statuses}
return [pl for pl in PLATFORM_NAMES if pl in found]


def answer_html(
name: str, version: str, python: str, example: str, platforms: list[str], *, builds: bool
) -> 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."""
e = html.escape
where = ", ".join(PLATFORM_NAMES[pl] for pl in platforms)
if builds:
why = (
f"pip and uv install a prebuilt wheel when one fits your platform and Python. Where none fits, they "
f"download {e(name)}'s source and build it on your machine, which needs a compiler and the libraries it "
f"links against, and stops with "Failed building wheel for {e(name)}" when they're missing. {e(name)} "
f"{e(version)} builds from source or can't install on: {e(where)} (the table shows which Python)."
)
ways = (
"The ways out, easiest first: use a Python and platform that has a wheel (the table); install a release "
"that has one (the table names it where there is one); or give the build what it needs."
)
else:
why = (
f"pip and uv install a prebuilt wheel when one fits your platform and Python, and build from source when "
f"none does. {e(name)} {e(version)} has no wheel that fits on {e(where)} and no source to build (the "
f"table shows which Python). An unpinned install there falls back to an older release that has a file for "
f"it, which may build from source (the table names the last release with a wheel where there is one). With "
f"no such release, or with {e(name)}=={e(version)} pinned, pip stops with "No matching distribution "
f"found for {e(name)}"."
)
ways = (
"The ways out: use a Python and platform that has a wheel (the table), or a release that has one (the "
"table names it where there is one)."
)
if builds:
tool_intro = "When a whole install fails, this finds which dependency it was and the release with a wheel:"
command = f"pip install -r requirements.txt 2>&1 | uvx wheelgap --from-log - -p {python} -t {example}"
else:
tool_intro = "To find every dependency like this before you install, on the platforms you ship to:"
command = f"uvx wheelgap requirements.txt -p {python} -t {example}"
return (
' <section class="notes" id="why-it-fails">\n'
" <h2>Why the install fails, and the fix</h2>\n"
f" <p>{why}</p>\n"
f" <p>{ways}</p>\n"
f" <p>{e(tool_intro)}</p>\n"
f" <pre><code>{e(command)}</code></pre>\n"
" </section>\n"
)


def add_note_url(name: str, platforms: list[str], today: str, exists: bool) -> str:
"""GitHub's new-file page for notes/<name>.toml with a template, or its editor if the file exists."""
if exists: # GitHub can't create a file that's already there, and can't pre-fill the editor
Expand Down Expand Up @@ -652,9 +703,42 @@ def page(
if any((gap_wheels or {}).get((canonical(name), version, target)) == "yanked" for target in gap_targets)
else ""
)
title = f"{name} wheel coverage: Linux, Alpine, macOS, Windows, ARM, Pyodide"
url = f"{BASE_URL}p/{canonical(name)}/"
summary = describe(package, columns, python, targets)
# A package that builds from source somewhere is searched for by its error, not by "wheel coverage": people (and
# their coding agents) paste "Failed building wheel for NAME" into a search box.
# Only regular Pythons on native platforms count. Not Pyodide: nobody's pip builds there. Not free-threaded: a gap
# only on 3.14t would title the page with an error the summary under it (regular Python) says nobody gets.
cells = (
[]
if package.get("error")
else [
(t["python"], t["platform"], r)
for t, r in zip(targets, package["results"])
if r in GAP and t["platform"] != "pyodide" and not t["python"].endswith("t")
]
)
builds = any(r == "source" for _, _, r in cells)
if builds:
title = f"Failed building wheel for {name}? Where pip builds it from source, and the fix"
heading = f"Failed building wheel for {name}?"
elif cells: # no sdist either: pip never builds it
title = f"No matching distribution found for {name}? Where pip can't install it, and the fix"
heading = f"No matching distribution found for {name}?"
else:
title = f"{name} wheel coverage: Linux, Alpine, macOS, Windows, ARM, Pyodide"
heading = f"{name} wheel coverage"
answer = ""
if cells:
# The example command names a Python and platform that really has the page's error: the Python the summary
# answers for when it has one, else the newest that does, and that Python's first such platform.
kind = [(py, pl) for py, pl, r in cells if r == ("source" if builds else "missing")]
preferred = install_results.install_python(package, targets) or python
pythons = {py for py, _ in kind}
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 = answer_html(name, version, example_python, example_platform, where, builds=builds)
campaign_links = []
for status, campaign in campaigns or []:
link = f'<a href="../../campaigns/{e(campaign["id"])}/">{e(campaign["title"])}</a>'
Expand Down Expand Up @@ -770,10 +854,10 @@ def cell(py: str, pl: str) -> str:
<body>
{build_campaigns.site_header("../../")}
<header class="wrap" id="page_content">
<h1>{e(name)} wheel coverage</h1>
<h1>{e(heading)}</h1>
<p>{e(summary)}</p>
<p class="meta">From the wheelgap {e(str(scan["wheelgap"]))} scan of {e(str(scan["generated"])[:10])}.</p>
</header>
{answer} </header>
<main class="wrap">
<div class="card">
<p class="sub"><strong class="card-release">{e(name)} <span class="ver">{e(version)}</span></strong> · {sub}</p>
Expand Down
58 changes: 57 additions & 1 deletion tests/test_package_jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def meta(prefix, key):
return match.group(1)

assert meta("property", "og:type") == "website"
assert meta("property", "og:title") == "numpy wheel coverage: Linux, Alpine, macOS, Windows, ARM, Pyodide"
# The fixture builds from source on one platform, so the title is the error people search for.
assert meta("property", "og:title") == "Failed building wheel for numpy? Where pip builds it from source, and the fix"
assert meta("property", "og:url") == "https://wheelgap.github.io/tracker/p/numpy/"
assert meta("property", "og:image") == "https://wheelgap.github.io/tracker/og.png"
assert meta("property", "og:image:width") == "1280"
Expand Down Expand Up @@ -118,3 +119,58 @@ def test_one_heading_and_the_badge_folded():
assert '<strong class="card-release">' in page
assert '<details class="fold">\n <summary><h2>Badge for your README</h2></summary>' in page
assert 'class="eyebrow"' not in page


def test_title_and_answer_follow_the_error_people_search_for():
def page(results, platforms):
data = scan()
data["targets"] = [{"label": f"3.13 {pl}", "python": "3.13", "platform": pl} for pl in platforms]
data["packages"][0]["results"] = results
return build(data)

built = page(["wheel", "source"], ["linux-x86_64", "win-arm64"])
assert "<h1>Failed building wheel for numpy?</h1>" in built
assert "--from-log - -p 3.13 -t win-arm64" in built

none_to_build = page(["wheel", "missing"], ["linux-x86_64", "win-arm64"])
assert "<h1>No matching distribution found for numpy?</h1>" in none_to_build
assert "uvx wheelgap requirements.txt -p 3.13 -t win-arm64" in none_to_build
assert "--from-log" not in none_to_build

covered = page(["wheel", "wheel"], ["linux-x86_64", "win-arm64"])
assert "<h1>numpy wheel coverage</h1>" in covered
assert "why-it-fails" not in covered


def _page(results, labels, name="numpy", version="2.3.1"):
data = scan(name, version)
data["targets"] = [{"label": label, "python": label.split()[0], "platform": label.split()[1]} for label in labels]
data["packages"][0]["results"] = results
return build(data)


def test_the_example_command_names_a_python_and_platform_with_the_error():
# linux-x86_64's gap is free-threaded only; 3.13's own gap is on win-arm64, so that's the command.
built = _page(["source", "wheel", "source"], ["3.13t linux-x86_64", "3.13 linux-x86_64", "3.13 win-arm64"])
assert "--from-log - -p 3.13 -t win-arm64" in built
assert "Windows ARM64" in built and "Linux x86_64 (the table" not in built


def test_gaps_only_on_free_threaded_or_pyodide_keep_the_coverage_title():
free_threaded = _page(["source", "wheel"], ["3.13t linux-x86_64", "3.13 linux-x86_64"])
assert "<h1>numpy wheel coverage</h1>" in free_threaded and "why-it-fails" not in free_threaded
pyodide = _page(["source", "wheel"], ["3.13 pyodide", "3.13 linux-x86_64"])
assert "<h1>numpy wheel coverage</h1>" in pyodide and "why-it-fails" not in pyodide


def test_no_matching_distribution_mentions_the_fallback_to_an_older_release():
built = _page(["wheel", "missing"], ["3.13 linux-x86_64", "3.13 win-arm64"])
assert "falls back to an older release" in built
assert "numpy==2.3.1 pinned" in built


def test_the_answer_escapes_the_package_name_once():
built = _page(["wheel", "source"], ["3.13 linux-x86_64", "3.13 win-arm64"], name="a&b<x>", version="1&2")
assert "<h1>Failed building wheel for a&amp;b&lt;x&gt;?</h1>" in built
assert "Failed building wheel for a&amp;b&lt;x&gt;&quot;" in built
assert "&amp;amp;" not in built and "<x>" not in built