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
7 changes: 5 additions & 2 deletions application_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import sys
import traceback


def django_template():
Expand Down Expand Up @@ -91,8 +92,10 @@ def numpy_array():
sys.path.insert(0, sys.argv[2])
try:
CHECKS[sys.argv[1]]()
except Exception as exc:
outcome = {"status": "error", "detail": f"{type(exc).__name__}: {exc}"}
except Exception:
# The end of the traceback, with the wheel directory shortened.
lines = traceback.format_exc().replace(sys.argv[2], "<wheels>").strip().splitlines()
outcome = {"status": "error", "detail": "\n".join(lines[-15:])}
else:
outcome = {"status": "passed", "detail": ""}
print(json.dumps(outcome))
6 changes: 5 additions & 1 deletion applications.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Provision pinned third-party wheels and collect application results."""

import hashlib
import inspect
import json
import platform
import shutil
Expand All @@ -9,6 +10,8 @@
from urllib.request import urlopen
from zipfile import BadZipFile, ZipFile

from application_checks import CHECKS as SCENARIOS


@dataclass(frozen=True)
class Wheel:
Expand Down Expand Up @@ -108,5 +111,6 @@ def application_results(executables, directory, invoke, numpy):
except ValueError:
print(f"{runtime} returned unreadable output for {name}")
outcomes[runtime] = {"status": "blocked", "detail": ""}
results.append({"id": name, "package": package, "version": version, "outcomes": outcomes})
results.append({"id": name, "package": package, "version": version,
"code": inspect.getsource(SCENARIOS[name]), "outcomes": outcomes})
return results
9 changes: 8 additions & 1 deletion dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def render_applications(report, copy):
fragment = anchor("scenario", row["id"])
cells = [
f'<th scope="row">{permalink(fragment, copy)}<strong>{escape(row["package"])}</strong> {escape(row["version"])}'
f'<span class="scenario-title">{escape(title)}</span></th>'
f'<span class="scenario-title">{escape(title)}</span>{code_details(row.get("code"), copy)}</th>'
]
cells.extend(f'<td>{detailed_badge(row["outcomes"][runtime["id"]], copy)}</td>' for runtime in runtimes)
listing.append(f'<tr id="{escape(fragment)}">' + "".join(cells) + "</tr>")
Expand Down Expand Up @@ -317,6 +317,13 @@ def package_cell(outcome, copy):
f'</details><span class="blocker">{escape(copy["blockerVia"])} <code>{escape(blocker["name"])}</code></span>')


def code_details(code, copy):
"""The code of an application scenario, folded under its name."""
if not code:
return ""
return f'<details class="check"><summary>{escape(copy["scenarioCode"])}</summary><pre>{escape(code)}</pre></details>'


def check_details(row, copy):
"""The functional check a package runs after its import, when it has one."""
if not row.get("check"):
Expand Down
1 change: 1 addition & 0 deletions dashboard_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"importOnly": "Import only",
"noCheck": "Import only: no functional check yet",
"checkTitle": "Functional check",
"scenarioCode": "Code",
"checkLevels": "{functional} with a functional check · {imported} import only",
"copyReproduction": "Copy to reproduce",
"copied": "Copied",
Expand Down
7 changes: 4 additions & 3 deletions package_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@
raise ImportError(f"{name} resolved outside the package directory")
shipped = getattr(module, "__version__", "")
bundled = f"The interpreter ships its own {name} {shipped}: this release installs only its metadata."
except Exception as exc:
outcome = {"status": "importError", "detail": f"{type(exc).__name__}: {exc}"}
except Exception:
lines = traceback.format_exc().strip().splitlines()
outcome = {"status": "importError", "detail": "\\n".join(lines[-15:])}
else:
outcome = {"status": "passed", "detail": bundled.replace(" ", " "), "level": "functional" if check else "import"}
if check:
try:
exec(compile(check, "<functional check>", "exec"), {"__name__": "__check__"})
except Exception:
lines = traceback.format_exc().strip().splitlines()
outcome = {"status": "functionError", "detail": "\\n".join(lines[-6:]), "level": "functional"}
outcome = {"status": "functionError", "detail": "\\n".join(lines[-15:]), "level": "functional"}
print(json.dumps(outcome))
"""

Expand Down
5 changes: 5 additions & 0 deletions tests/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def report(**overrides):
}],
"applications": [{
"id": "numpy-array", "package": "NumPy", "version": "2.4.4",
"code": "def numpy_array():\n import numpy as np\n",
"outcomes": {"cpython": passed(),
"pypy": {"status": "otherAbi", "detail": "loads pp80"}},
}],
Expand Down Expand Up @@ -101,6 +102,10 @@ def test_the_former_french_page_redirects_to_english(self):
pages, _ = render(report())
self.assertIn('location.replace("../" + location.search + location.hash)', pages["fr"])

def test_shows_the_code_of_each_scenario(self):
pages, _ = render(report())
self.assertIn(f'<summary>{COPY["scenarioCode"]}</summary><pre>def numpy_array():', pages["en"])

def test_accepts_reports_without_optional_measurements(self):
legacy = report(applications=[], packages=None)
pages, _ = render(legacy)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_package_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,23 @@ def test_a_failing_check_is_a_functional_error(self):
self.assertEqual(outcome["status"], "functionError")
self.assertIn("AssertionError: wrong value", outcome["detail"])

def test_an_import_error_keeps_its_traceback(self):
import json
import subprocess
import sys
with TemporaryDirectory() as site:
Path(site, "demo").mkdir()
Path(site, "demo", "__init__.py").write_text("raise RuntimeError('broken on import')\n", encoding="utf-8")
Path(site, "demo-1.0.dist-info").mkdir()
Path(site, "demo-1.0.dist-info", "METADATA").write_text(
"Metadata-Version: 2.1\nName: demo\nVersion: 1.0\n", encoding="utf-8")
completed = subprocess.run([sys.executable, "-I", "-c", package_bench.IMPORT_PACKAGE, site, "demo", "1.0",
"demo", ""], capture_output=True, text=True, timeout=60)
outcome = json.loads(completed.stdout.splitlines()[-1])
self.assertEqual(outcome["status"], "importError")
self.assertIn("Traceback (most recent call last)", outcome["detail"])
self.assertIn("RuntimeError: broken on import", outcome["detail"])

def test_every_check_names_a_ranked_project(self):
import json
from smoke import SMOKE
Expand Down
Loading