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
13 changes: 13 additions & 0 deletions e2e/prebuilt_override/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "prebuilt-wheel-override"
version = "0.1.0"
description = "Prebuilt wheel download hook for end-to-end tests"
requires-python = ">=3.12"
dependencies = []

[project.entry-points."fromager.project_overrides"]
setuptools = "package_plugins.prebuilt_setuptools"
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Download setuptools wheels for the hook-prebuilt end-to-end test."""

import logging
import pathlib

from packaging.requirements import Requirement
from packaging.version import Version

from fromager import context, downloads, packagesettings

logger = logging.getLogger(__name__)


def download_source(
ctx: context.WorkContext,
req: Requirement,
version: Version,
download_url: str,
sdists_downloads_dir: pathlib.Path,
) -> packagesettings.DownloadedSource:
"""Download a prebuilt wheel and return its path and artifact kind."""
logger.info("download_source hook downloading %s==%s", req.name, version)
path = downloads.download_wheel(
destination_dir=ctx.wheels_prebuilt,
url=download_url,
)
return packagesettings.DownloadedSource(
path=path, kind=packagesettings.DownloadKind.prebuilt_wheel
)
3 changes: 3 additions & 0 deletions e2e/source_settings_hook_prebuilt/setuptools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source:
provider: hook-prebuilt
index_url: https://pypi.org/simple/
6 changes: 6 additions & 0 deletions e2e/source_settings_hook_sdist/stevedore.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source:
provider: hook-sdist
build_sdist: tarball
# GitHub archives have no git metadata for pbr to determine the version.
env:
PBR_VERSION: "${__version__}"
82 changes: 81 additions & 1 deletion e2e/test_build_source_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#
# The git profile resolves stevedore tags on GitHub and builds from a
# git checkout. The archive profile resolves on PyPI and downloads a
# tarball from a URL template.
# tarball from a URL template. The hook profiles use installed plugins
# to resolve a source archive and download a prebuilt wheel.

SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "$SCRIPTDIR/common.sh"
Expand Down Expand Up @@ -141,4 +142,83 @@ expect_file "$BUILT_SDIST"
expect_file "sdists-repo/downloads/${DIST}-${VERSION}.tar.gz"
expect_ignored_index_url "$OUTDIR/build-archive.log"

# 5. Bootstrap with a hook-sdist resolver supplied by an installed plugin.
pip install "$SCRIPTDIR/github_override_example"
remove_dist
fromager \
$NETWORK_ISOLATION \
--log-file="$OUTDIR/bootstrap-hook-sdist.log" \
--sdists-repo="$OUTDIR/sdists-repo" \
--wheels-repo="$OUTDIR/wheels-repo" \
--work-dir="$OUTDIR/work-dir" \
--settings-dir="$SCRIPTDIR/source_settings_hook_sdist" \
bootstrap "${DIST}==${VERSION}"

expect_file "$WHEEL"
expect_file "$BUILT_SDIST"
if ! grep -q "stevedore: found get_resolver_provider override" "$OUTDIR/bootstrap-hook-sdist.log"; then
echo "FAIL: hook-sdist did not use the resolver hook" 1>&2
pass=false
fi

if ! python3 - "$OUTDIR/work-dir/build-order.json" "$DIST" "$VERSION" <<'EOF'
import json
import sys

path, dist, version = sys.argv[1:]
with open(path) as f:
entries = [e for e in json.load(f) if e["dist"] == dist]
assert len(entries) == 1, entries
entry = entries[0]
assert entry["version"] == version, entry
assert entry["source_provider"] == "hook-sdist", entry
assert entry["source_url_type"] == "override", entry
assert entry["prebuilt"] is False, entry
assert entry["source_url"].startswith(
"https://github.com/python-wheel-build/stevedore-test-repo/archive/refs/tags/"
), entry
EOF
then
echo "FAIL: build order does not record the hook-sdist source" 1>&2
pass=false
fi

# 6. Bootstrap a hook-prebuilt wheel without an existing wheel cache.
pip install "$SCRIPTDIR/prebuilt_override"
fromager \
--log-file="$OUTDIR/bootstrap-hook-prebuilt.log" \
--sdists-repo="$OUTDIR/sdists-repo" \
--wheels-repo="$OUTDIR/hook-wheels-repo" \
--work-dir="$OUTDIR/hook-work-dir" \
--settings-dir="$SCRIPTDIR/source_settings_hook_prebuilt" \
bootstrap "setuptools==75.8.0"

expect_file "hook-wheels-repo/prebuilt/setuptools-75.8.0-py3-none-any.whl"
if ! grep -q "download_source hook downloading setuptools==75.8.0" "$OUTDIR/bootstrap-hook-prebuilt.log"; then
echo "FAIL: hook-prebuilt did not call the download hook" 1>&2
pass=false
fi

if ! python3 - "$OUTDIR/hook-work-dir/build-order.json" <<'EOF'
import json
import sys

with open(sys.argv[1]) as f:
entries = [e for e in json.load(f) if e["dist"] == "setuptools"]
assert len(entries) == 1, entries
entry = entries[0]
assert entry["version"] == "75.8.0", entry
assert entry["source_provider"] == "hook-prebuilt", entry
assert entry["source_url_type"] == "prebuilt", entry
assert entry["prebuilt"] is True, entry
assert entry["source_url"].startswith("https://files.pythonhosted.org/"), entry
assert entry["source_url"].split("#")[0].endswith(
"/setuptools-75.8.0-py3-none-any.whl"
), entry
EOF
then
echo "FAIL: build order does not record the hook-prebuilt wheel" 1>&2
pass=false
fi

$pass
Loading