diff --git a/e2e/prebuilt_override/pyproject.toml b/e2e/prebuilt_override/pyproject.toml new file mode 100644 index 00000000..d2a980b5 --- /dev/null +++ b/e2e/prebuilt_override/pyproject.toml @@ -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" diff --git a/e2e/prebuilt_override/src/package_plugins/prebuilt_setuptools.py b/e2e/prebuilt_override/src/package_plugins/prebuilt_setuptools.py new file mode 100644 index 00000000..b995363d --- /dev/null +++ b/e2e/prebuilt_override/src/package_plugins/prebuilt_setuptools.py @@ -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 + ) diff --git a/e2e/source_settings_hook_prebuilt/setuptools.yaml b/e2e/source_settings_hook_prebuilt/setuptools.yaml new file mode 100644 index 00000000..b1a4aa14 --- /dev/null +++ b/e2e/source_settings_hook_prebuilt/setuptools.yaml @@ -0,0 +1,3 @@ +source: + provider: hook-prebuilt + index_url: https://pypi.org/simple/ diff --git a/e2e/source_settings_hook_sdist/stevedore.yaml b/e2e/source_settings_hook_sdist/stevedore.yaml new file mode 100644 index 00000000..0e95dd12 --- /dev/null +++ b/e2e/source_settings_hook_sdist/stevedore.yaml @@ -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__}" diff --git a/e2e/test_build_source_config.sh b/e2e/test_build_source_config.sh index 57640f00..6534f403 100755 --- a/e2e/test_build_source_config.sh +++ b/e2e/test_build_source_config.sh @@ -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" @@ -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