Skip to content

Commit c22e3d5

Browse files
committed
fix an edge case
1 parent a4566b1 commit c22e3d5

File tree

2 files changed

+45
-15
lines changed

2 files changed

+45
-15
lines changed

python/private/pypi/extension.bzl

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ def _create_whl_repos(
266266
logger = logger,
267267
)
268268

269+
use_downloader = {
270+
normalize_name(s): False
271+
for s in pip_attr.simpleapi_skip
272+
}
269273
exposed_packages = {}
270274
for whl in requirements_by_platform:
271275
if whl.is_exposed:
@@ -313,17 +317,26 @@ def _create_whl_repos(
313317
if v != default
314318
})
315319

316-
for src in whl.srcs:
320+
for src in sorted(whl.srcs, key = lambda x: x.filename):
317321
repo = _whl_repo(
318322
src = src,
319323
whl_library_args = whl_library_args,
320324
download_only = pip_attr.download_only,
321325
netrc = pip_attr.netrc,
326+
# NOTE @aignas 2025-07-07: we guard against an edge-case where there
327+
# are more platforms defined than there are wheels for and users
328+
# disallow building from sdist.
329+
use_downloader = use_downloader.get(
330+
whl.name,
331+
get_index_urls != None, # defaults to True if the get_index_urls is defined
332+
),
322333
auth_patterns = pip_attr.auth_patterns,
323334
python_version = major_minor,
324335
is_multiple_versions = whl.is_multiple_versions,
325336
enable_pipstar = config.enable_pipstar,
326337
)
338+
if repo == None:
339+
continue
327340

328341
repo_name = "{}_{}".format(pip_name, repo.repo_name)
329342
if repo_name in whl_libraries:
@@ -342,7 +355,17 @@ def _create_whl_repos(
342355
whl_libraries = whl_libraries,
343356
)
344357

345-
def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, netrc, auth_patterns, python_version, enable_pipstar = False):
358+
def _whl_repo(
359+
*,
360+
src,
361+
whl_library_args,
362+
is_multiple_versions,
363+
download_only,
364+
netrc,
365+
auth_patterns,
366+
python_version,
367+
use_downloader,
368+
enable_pipstar = False):
346369
args = dict(whl_library_args)
347370
args["requirement"] = src.requirement_line
348371
is_whl = src.filename.endswith(".whl")
@@ -355,19 +378,24 @@ def _whl_repo(*, src, whl_library_args, is_multiple_versions, download_only, net
355378
args["extra_pip_args"] = src.extra_pip_args
356379

357380
if not src.url or (not is_whl and download_only):
358-
# Fallback to a pip-installed wheel
359-
target_platforms = src.target_platforms if is_multiple_versions else []
360-
return struct(
361-
repo_name = pypi_repo_name(
362-
normalize_name(src.distribution),
363-
*target_platforms
364-
),
365-
args = args,
366-
config_setting = whl_config_setting(
367-
version = python_version,
368-
target_platforms = target_platforms or None,
369-
),
370-
)
381+
if download_only and use_downloader:
382+
# If the user did not allow using sdists and we are using the downloader
383+
# and we are not using simpleapi_skip for this
384+
return None
385+
else:
386+
# Fallback to a pip-installed wheel
387+
target_platforms = src.target_platforms if is_multiple_versions else []
388+
return struct(
389+
repo_name = pypi_repo_name(
390+
normalize_name(src.distribution),
391+
*target_platforms
392+
),
393+
args = args,
394+
config_setting = whl_config_setting(
395+
version = python_version,
396+
target_platforms = target_platforms or None,
397+
),
398+
)
371399

372400
# This is no-op because pip is not used to download the wheel.
373401
args.pop("download_only", None)

tests/pypi/extension/extension_tests.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,14 @@ def _test_torch_experimental_index_url(env):
414414
("linux", "aarch64"): ["linux_*_aarch64", "manylinux_*_aarch64"],
415415
("osx", "aarch64"): ["macosx_*_arm64"],
416416
("windows", "x86_64"): ["win_amd64"],
417+
("windows", "aarch64"): ["win_arm64"], # this should be ignored
417418
}.items()
418419
],
419420
parse = [
420421
_parse(
421422
hub_name = "pypi",
422423
python_version = "3.12",
424+
download_only = True,
423425
experimental_index_url = "https://torch.index",
424426
requirements_lock = "universal.txt",
425427
),

0 commit comments

Comments
 (0)