Skip to content

Commit 594716a

Browse files
authored
Merge pull request #1051 from LalatenduMohanty/fix/1049-cache-lookup-bypass-hook
fix(bootstrap): don't call get_resolver_provider hook in cache lookups
2 parents 641a6c1 + 986fb38 commit 594716a

2 files changed

Lines changed: 45 additions & 3 deletions

File tree

src/fromager/bootstrapper.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,17 @@ def _download_wheel_from_cache(
11001100
f"checking if wheel was already uploaded to {self.cache_wheel_server_url}"
11011101
)
11021102
try:
1103-
wheel_url, _ = resolver.resolve(
1104-
ctx=self.ctx,
1105-
req=Requirement(f"{req.name}=={resolved_version}"),
1103+
# Use PyPIProvider directly for cache lookups, bypassing resolver
1104+
# hooks. Cache servers are always simple PyPI index servers.
1105+
pinned_req = Requirement(f"{req.name}=={resolved_version}")
1106+
provider = resolver.PyPIProvider(
11061107
sdist_server_url=self.cache_wheel_server_url,
11071108
include_sdists=False,
11081109
include_wheels=True,
1110+
constraints=self.ctx.constraints,
11091111
)
1112+
results = resolver.find_all_matching_from_provider(provider, pinned_req)
1113+
wheel_url, _ = results[0]
11101114
wheelfile_name = pathlib.Path(urlparse(wheel_url).path)
11111115
pbi = self.ctx.package_build_info(req)
11121116
expected_build_tag = pbi.build_tag(resolved_version)

tests/test_bootstrapper.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,41 @@ def mock_bootstrap_impl(
370370
success_key_10 = f"{canonicalize_name('testpkg')}==1.0"
371371
assert success_key_20 in tmp_context.dependency_graph.nodes
372372
assert success_key_10 in tmp_context.dependency_graph.nodes
373+
374+
375+
@patch("fromager.resolver.find_all_matching_from_provider")
376+
@patch("fromager.resolver.PyPIProvider")
377+
def test_download_wheel_from_cache_bypasses_hooks(
378+
mock_pypi_provider: Mock,
379+
mock_find_all: Mock,
380+
tmp_context: WorkContext,
381+
) -> None:
382+
"""Verify _download_wheel_from_cache uses PyPIProvider directly, not hooks."""
383+
bt = bootstrapper.Bootstrapper(tmp_context)
384+
bt.cache_wheel_server_url = "https://cache.example.com/simple/"
385+
386+
mock_provider = Mock()
387+
mock_pypi_provider.return_value = mock_provider
388+
# Raise so the except clause returns (None, None) before hitting
389+
# network calls later in the function.
390+
mock_find_all.side_effect = RuntimeError("no match")
391+
392+
with patch("fromager.overrides.find_and_invoke") as mock_override:
393+
result = bt._download_wheel_from_cache(
394+
req=Requirement("test-pkg"),
395+
resolved_version=Version("1.0.0"),
396+
)
397+
398+
assert result == (None, None)
399+
400+
# Hook system must NOT be called for cache lookups
401+
mock_override.assert_not_called()
402+
403+
# PyPIProvider must be instantiated directly
404+
mock_pypi_provider.assert_called_once_with(
405+
sdist_server_url="https://cache.example.com/simple/",
406+
include_sdists=False,
407+
include_wheels=True,
408+
constraints=tmp_context.constraints,
409+
)
410+
mock_find_all.assert_called_once_with(mock_provider, Requirement("test-pkg==1.0.0"))

0 commit comments

Comments
 (0)