Skip to content

Commit d29ec6b

Browse files
fix(build): reuse pre-built wheels that carry a build number
Pre-built packages have an empty changelog build tag, which the reuse check treated as 0. A publisher build number higher than 0 then failed the job instead of downloading the wheel. Skip that comparison for pre-built packages and keep it for wheels Fromager builds. Co-Authored-By: Grok <grok@x.ai> Signed-off-by: Shanmukh Pawan <smoparth@redhat.com>
1 parent 1e3c39d commit d29ec6b

2 files changed

Lines changed: 75 additions & 24 deletions

File tree

‎src/fromager/commands/build.py‎

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -535,30 +535,37 @@ def _is_wheel_built(
535535
logger.debug("could not parse candidate wheel %s", url, exc_info=True)
536536
continue
537537

538-
# Keep hook validation errors visible instead of treating them as
539-
# a cache miss.
540-
expected_tag = wheels.get_build_tag(
541-
ctx=wkctx,
542-
req=req,
543-
version=candidate_version,
544-
wheel_tags=wheel_tags,
545-
)
546-
build_tag = expected_tag if expected_tag else (0, "")
547-
existing_build_tag = build_tag_from_name if build_tag_from_name else (0, "")
548-
if (
549-
existing_build_tag[0] > build_tag[0]
550-
and existing_build_tag[1] == build_tag[1]
551-
):
552-
raise ValueError(
553-
f"{dist_name}: changelog for version {candidate_version} is inconsistent. Found build tag {existing_build_tag} but expected {build_tag}"
538+
# The publisher owns the build number of a pre-built wheel.
539+
# Changelog tags apply only to wheels Fromager builds. An empty
540+
# pre-built tag would otherwise be treated as 0 and reject any
541+
# higher number before the wheel can be reused.
542+
if not pbi.pre_built:
543+
# Keep hook validation errors visible instead of treating them as
544+
# a cache miss.
545+
expected_tag = wheels.get_build_tag(
546+
ctx=wkctx,
547+
req=req,
548+
version=candidate_version,
549+
wheel_tags=wheel_tags,
554550
)
555-
if existing_build_tag != build_tag:
556-
logger.info(
557-
"candidate wheel build tag %s does not match expected build tag %s",
558-
existing_build_tag,
559-
build_tag,
551+
build_tag = expected_tag if expected_tag else (0, "")
552+
existing_build_tag = (
553+
build_tag_from_name if build_tag_from_name else (0, "")
560554
)
561-
continue
555+
if (
556+
existing_build_tag[0] > build_tag[0]
557+
and existing_build_tag[1] == build_tag[1]
558+
):
559+
raise ValueError(
560+
f"{dist_name}: changelog for version {candidate_version} is inconsistent. Found build tag {existing_build_tag} but expected {build_tag}"
561+
)
562+
if existing_build_tag != build_tag:
563+
logger.info(
564+
"candidate wheel build tag %s does not match expected build tag %s",
565+
existing_build_tag,
566+
build_tag,
567+
)
568+
continue
562569

563570
wheel_filename: pathlib.Path | None = None
564571
if wkctx.wheel_server_url and url.startswith(wkctx.wheel_server_url):

‎tests/test_cooldown.py‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,18 @@ def _context_for_existing_wheel(
901901
tmp_path: pathlib.Path,
902902
*,
903903
package_wheel_server_url: str | None = None,
904+
pre_built: bool = False,
904905
) -> context.WorkContext:
905906
settings_dir = tmp_path / "settings"
906907
settings_dir.mkdir()
907-
if package_wheel_server_url is not None:
908+
if package_wheel_server_url is not None or pre_built:
909+
variant_lines = ["variants:", " cpu:"]
910+
if pre_built:
911+
variant_lines.append(" pre_built: true")
912+
if package_wheel_server_url is not None:
913+
variant_lines.append(f" wheel_server_url: {package_wheel_server_url}")
908914
(settings_dir / "test-pkg.yaml").write_text(
909-
f"variants:\n cpu:\n wheel_server_url: {package_wheel_server_url}\n",
915+
"\n".join(variant_lines) + "\n",
910916
encoding="utf-8",
911917
)
912918
settings = packagesettings.Settings.from_files(
@@ -1080,6 +1086,44 @@ def test_is_wheel_built_propagates_inconsistent_build_tag(
10801086
build_command._is_wheel_built(ctx, "test-pkg", version)
10811087

10821088

1089+
def test_is_wheel_built_prebuilt_keeps_publisher_build_tag(
1090+
tmp_path: pathlib.Path,
1091+
monkeypatch: pytest.MonkeyPatch,
1092+
) -> None:
1093+
"""A pre-built wheel with a publisher build number is reused.
1094+
1095+
The changelog tag is empty for pre-built packages. That must not reject
1096+
a higher build number, and the highest published build number is used.
1097+
"""
1098+
ctx = _context_for_existing_wheel(
1099+
tmp_path,
1100+
package_wheel_server_url=_PACKAGE_WHEEL_SERVER,
1101+
pre_built=True,
1102+
)
1103+
version = Version("1.3.2")
1104+
older_name = "test_pkg-1.3.2-1-py3-none-any.whl"
1105+
newer_name = "test_pkg-1.3.2-2-py3-none-any.whl"
1106+
newer_url = f"{_PACKAGE_WHEEL_SERVER}test-pkg/{newer_name}"
1107+
downloaded: list[str] = []
1108+
monkeypatch.setattr(
1109+
build_command.wheels, "download_wheel", _record_download(downloaded)
1110+
)
1111+
1112+
with requests_mock.Mocker() as r:
1113+
r.get(
1114+
f"{_PACKAGE_WHEEL_SERVER}test-pkg/",
1115+
json=_wheel_index_for_filenames(
1116+
_PACKAGE_WHEEL_SERVER, [older_name, newer_name]
1117+
),
1118+
headers={"Content-Type": _PYPI_SIMPLE_JSON_CONTENT_TYPE},
1119+
)
1120+
found = build_command._is_wheel_built(ctx, "test-pkg", version)
1121+
1122+
assert found is not None
1123+
assert found.name == newer_name
1124+
assert downloaded == [newer_url]
1125+
1126+
10831127
def test_is_wheel_built_uses_package_wheel_server_url(
10841128
tmp_path: pathlib.Path,
10851129
monkeypatch: pytest.MonkeyPatch,

0 commit comments

Comments
 (0)