Skip to content
Closed
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
39 changes: 31 additions & 8 deletions Formula/s/sagemath-deps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ class SagemathDeps < Formula
url "https://github.com/sagemath/sage/archive/refs/tags/11.0.beta6.tar.gz"
sha256 "bb767ddc886d29f036ba56b8a92e238e316b37baa5b3f96fc6d2f9108a1827e1"
license "GPL-2.0-or-later"
revision 2

bottle do
root_url "https://github.com/dimpase/homebrew-tap/releases/download/sagemath-deps-11.0.beta6_2"
sha256 cellar: :any, arm64_tahoe: "ed0a760cdd9d0b96cbf91cd308c547687abde5b7a01e39762116b4f9ad5d112e"
sha256 cellar: :any, arm64_linux: "3ec342aff2a4d46c1bd789edb27e83f5e803c98e2092f97fe781aa43c35db97f"
sha256 cellar: :any, x86_64_linux: "77ac7fc0adc609eb0bb03b55f0ab2e1170030a54dc66f6769ec7058e099f57dd"
end
revision 3

# Keep build tools installed when this dependency environment is bottled.
# They are also needed to build sagelib separately from a checkout.
Expand Down Expand Up @@ -455,6 +448,12 @@ def write_development_environment(python_version)
def write_python_paths(python_version, site_packages)
private_site = opt_libexec/"python#{python_version}"/site_packages
global_site = HOMEBREW_PREFIX/site_packages
# Meson's dedicated site is pure Python but may use another Python minor.
# Resolve its opt prefix at startup so Meson upgrades keep working, while
# packages installed in the development venv retain precedence.
(libexec/"python#{python_version}"/site_packages/"homebrew-meson.pth").write <<~EOS
import glob, sys; sys.path.extend(p for p in glob.glob('#{formula_opt_prefix("meson")}/lib/python*/site-packages') if p not in sys.path)
EOS
# Prefer these resources to Homebrew's other Python packages, while allowing
# a development venv to override them with its own installed packages.
# Linux Python also supplies packages (including wheel) in its own keg.
Expand Down Expand Up @@ -568,6 +567,28 @@ def version():
assert pathlib.Path(dist.locate_file("")).resolve() == root, (name, dist.locate_file(""))
assert not list(root.glob("sagemath-[0-9]*.dist-info")), "sagelib must be installed separately"
import Cython, mesonpy, memory_allocator, jinja2, packaging
import mesonbuild.coredata
import subprocess
from packaging.requirements import Requirement
from packaging.specifiers import SpecifierSet

# Use the real, compatible Meson bottle, including its metadata.
meson = importlib.metadata.distribution("meson")
meson_root = pathlib.Path("#{formula_opt_prefix("meson")}").resolve()
meson_site = pathlib.Path(meson.locate_file("")).resolve()
assert meson_site.is_relative_to(meson_root)
assert list((meson_root / "lib").glob("python*/site-packages")) == [meson_site]
assert pathlib.Path(mesonbuild.coredata.__file__).resolve().parent.parent == meson_site
meson_cli_version = subprocess.check_output([str(meson_root / "bin/meson"), "--version"], text=True).strip()
assert meson.version == mesonbuild.coredata.version == meson_cli_version
assert meson.metadata["Requires-Python"]
assert SpecifierSet(meson.metadata["Requires-Python"]).contains(".".join(map(str, sys.version_info[:3])))
assert "Root-Is-Purelib: true" in meson.read_text("WHEEL")
assert {p.name for p in meson_site.iterdir()} == {"mesonbuild", f"meson-{meson.version}.dist-info"}
for raw in importlib.metadata.requires("meson-python"):
requirement = Requirement(raw)
if requirement.name == "meson" and (requirement.marker is None or requirement.marker.evaluate()):
assert requirement.specifier.contains(meson.version)
import cysignals, gmpy2, numpy, scipy, matplotlib, PIL, ipykernel, ipywidgets
import networkx, requests
import elliptic_curve_databases, graph_databases, polytope_databases
Expand Down Expand Up @@ -627,6 +648,8 @@ def version():
# Packages deliberately installed in the venv must override the baseline.
(venv/site_packages/"sympy.py").write "VENV_OVERRIDE = True\n"
system venv/"bin/python", "-c", "import sympy; assert sympy.VENV_OVERRIDE"
(venv/site_packages/"mesonbuild.py").write "VENV_OVERRIDE = True\n"
system venv/"bin/python", "-c", "import mesonbuild; assert mesonbuild.VENV_OVERRIDE"
end
end
end
2 changes: 1 addition & 1 deletion scripts/sage-bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
raise "ARM64 runner required" if Hardware::CPU.arch != :arm64

root = Formulary.factory("dimpase/tap/sagemath-deps")
raise "Published sagemath-deps 11.0.beta6_2 required" if root.pkg_version.to_s != "11.0.beta6_2"
raise "Published sagemath-deps 11.0.beta6_3 required" if root.pkg_version.to_s != "11.0.beta6_3"

rows = []
formulae_by_name = {}
Expand Down
54 changes: 51 additions & 3 deletions scripts/sage-validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
# Check distutils before another import can activate setuptools' import hook.
MODULES = (
"distutils", "Cython", "mesonpy", "memory_allocator", "jinja2", "packaging",
"distutils", "Cython", "mesonpy", "mesonbuild.coredata", "memory_allocator", "jinja2", "packaging",
"cysignals", "cypari2", "gmpy2", "numpy", "scipy", "matplotlib", "PIL",
"ppl", "cvxopt", "fpylll", "lrcalc", "primecountpy", "sympy",
"networkx", "IPython", "ipykernel", "ipywidgets",
Expand Down Expand Up @@ -64,6 +64,13 @@ def prepare(root, artifacts):
assert not venv.exists(), "Validation requires a fresh environment"
subprocess.run([uv, "venv", "--no-project", "--no-config", "--offline",
"--python", sys.executable, str(venv)], check=True)
# Seed pip offline from the bottled Python's bundled wheel. Its check runs
# inside Python and sees the private sites exposed by executable .pth hooks.
# uv's static package inventory does not follow those hooks.
seeded = subprocess.run([str(venv / "bin/python"), "-I", "-B", "-m", "ensurepip", "--default-pip"],
check=False, text=True, capture_output=True)
(artifacts / "ensurepip.log").write_text(seeded.stdout + seeded.stderr)
seeded.check_returncode()

sites = []
relative = Path("lib/python3.14/site-packages")
Expand All @@ -75,7 +82,7 @@ def prepare(root, artifacts):
# Homebrew's sitecustomize redirects the interpreter's bundled
# pip/wheel site to the global site, exposing unrelated installations.
# uv and the bottled build backend do not need that interpreter site.
if keg == python_keg:
if keg == python_keg or row["name"] == "meson":
continue
for path in [keg / "libexec/python3.14" / relative,
keg / relative, keg / "libexec" / relative]:
Expand All @@ -86,10 +93,32 @@ def prepare(root, artifacts):
assert not (path / "sage").exists(), f"Old Sage in {path}"
if not any(entry["path"] == str(path) for entry in sites):
sites.append({"path": str(path), "formula": row["name"], "keg": str(keg)})
# Meson's dedicated pure-Python site can use a different Python minor.
# Audit only that bottle's site; the sagemath-deps private .pth must expose
# it itself, without processing any .pth files inside the Meson bottle.
meson = by_name["meson"]
meson_keg = Path(meson["keg"]).resolve(strict=True)
assert meson["receipt"]["source"]["tap"] == "homebrew/core", meson
meson_sites = list((meson_keg / "lib").glob("python*/site-packages"))
assert len(meson_sites) == 1, meson_sites
meson_site = meson_sites[0].resolve(strict=True)
assert meson_site.is_relative_to(meson_keg)
metadata_dirs = list(meson_site.glob("meson-*.dist-info"))
assert len(metadata_dirs) == 1, metadata_dirs
assert metadata_dirs[0].resolve(strict=True).is_relative_to(meson_keg)
assert (meson_site / "mesonbuild").resolve(strict=True).is_relative_to(meson_keg)
assert {p.name for p in meson_site.iterdir()} == {"mesonbuild", metadata_dirs[0].name}
dist = importlib.metadata.Distribution.at(metadata_dirs[0])
assert dist.metadata["Name"] == "meson"
assert "Root-Is-Purelib: true" in dist.read_text("WHEEL")
assert "Tag: py3-none-any" in dist.read_text("WHEEL")
sites.append({"path": str(meson_site), "formula": "meson", "keg": str(meson_keg),
"append_only": True})
# Process each private site's .pth files, including setuptools' distutils
# import hook, just as Python does for an ordinary installed site directory.
(venv / relative / "bottled-sage-dependencies.pth").write_text(
"".join(f"import site; site.addsitedir({entry['path']!r})\n" for entry in sites))
"".join(f"import site; site.addsitedir({entry['path']!r})\n"
for entry in sites if not entry.get("append_only")))
write_json(artifacts / "python-sites.json", sites)
subprocess.run([str(venv / "bin/python"), "-I", __file__, "check-before-build"], check=True)

Expand Down Expand Up @@ -128,6 +157,18 @@ def check_python(root, artifacts, built=False):
path = Path(module.__file__).resolve()
assert any(path.is_relative_to(site) for site in allowed), (name, path)
origins[name] = str(path)
meson = importlib.metadata.distribution("meson")
meson_site = next(Path(entry["path"]).resolve() for entry in sites if entry["formula"] == "meson")
assert Path(meson.locate_file("")).resolve() == meson_site
assert Path(origins["mesonbuild.coredata"]).parent.parent == meson_site
from mesonbuild import coredata
from packaging.specifiers import SpecifierSet

assert meson.version == coredata.version
assert SpecifierSet(meson.metadata["Requires-Python"]).contains(".".join(map(str, sys.version_info[:3])))
meson_keg = next(Path(entry["keg"]) for entry in sites if entry["formula"] == "meson")
meson_cli = subprocess.check_output([str(meson_keg / "bin/meson"), "--version"], text=True).strip()
assert meson_cli == meson.version
if built:
import sage.all
import sage.version
Expand Down Expand Up @@ -164,6 +205,13 @@ def check_python(root, artifacts, built=False):
"distributions": sorted((d.metadata["Name"], d.version, str(d.locate_file("")))
for d in importlib.metadata.distributions()),
})
pip = importlib.metadata.distribution("pip")
assert Path(pip.locate_file("")).resolve().is_relative_to(venv)
result = subprocess.run([sys.executable, "-I", "-B", "-m", "pip", "check"],
check=False, text=True, capture_output=True)
suffix = "after" if built else "before"
(artifacts / f"pip-check-{suffix}.log").write_text(result.stdout + result.stderr)
result.check_returncode()
print("Python and native-feature provenance checks passed" if built else "Isolated bottle imports passed")


Expand Down
Loading