@@ -188,19 +188,35 @@ def parse_requirements(
188188 for p in r .target_platforms :
189189 requirement_target_platforms [p ] = None
190190
191+ package_srcs = _package_srcs (
192+ name = name ,
193+ reqs = reqs ,
194+ index_urls = index_urls ,
195+ platforms = platforms ,
196+ extract_url_srcs = extract_url_srcs ,
197+ logger = logger ,
198+ )
199+
200+ # FIXME @aignas 2025-11-24: we can get the list of target platforms here
201+ #
202+ # However it is likely that we may stop exposing packages like torch in here
203+ # which do not have wheels for all osx platforms.
204+ #
205+ # If users specify the target platforms accurately, then it is a different
206+ # (better) story, but we may not be able to guarantee this
207+ #
208+ # target_platforms = [
209+ # p
210+ # for dist in package_srcs
211+ # for p in dist.target_platforms
212+ # ]
213+
191214 item = struct (
192215 # Return normalized names
193216 name = normalize_name (name ),
194217 is_exposed = len (requirement_target_platforms ) == len (requirements ),
195218 is_multiple_versions = len (reqs .values ()) > 1 ,
196- srcs = _package_srcs (
197- name = name ,
198- reqs = reqs ,
199- index_urls = index_urls ,
200- platforms = platforms ,
201- extract_url_srcs = extract_url_srcs ,
202- logger = logger ,
203- ),
219+ srcs = package_srcs ,
204220 )
205221 ret .append (item )
206222 if not item .is_exposed and logger :
@@ -234,7 +250,7 @@ def _package_srcs(
234250 platforms .keys (),
235251 ))
236252
237- dist = _add_dists (
253+ dist , can_fallback = _add_dists (
238254 requirement = r ,
239255 target_platform = platforms .get (target_platform ),
240256 index_urls = index_urls .get (name ),
@@ -244,14 +260,16 @@ def _package_srcs(
244260
245261 if extract_url_srcs and dist :
246262 req_line = r .srcs .requirement
247- else :
263+ elif can_fallback :
248264 dist = struct (
249265 url = "" ,
250266 filename = "" ,
251267 sha256 = "" ,
252268 yanked = False ,
253269 )
254270 req_line = r .srcs .requirement_line
271+ else :
272+ continue
255273
256274 key = (
257275 dist .filename ,
@@ -337,14 +355,22 @@ def _add_dists(*, requirement, index_urls, target_platform, logger = None):
337355 index_urls: The result of simpleapi_download.
338356 target_platform: The target_platform information.
339357 logger: A logger for printing diagnostic info.
358+
359+ Returns:
360+ (dist, can_fallback_to_pip): a struct with distribution details and how to fetch
361+ it and a boolean flag to tell the other layers if we should add an entry to
362+ fallback for pip if there are no supported whls found - if there is an sdist, we
363+ can attempt the fallback, otherwise better to not, because the pip command will
364+ fail and the error message will be confusing. What is more that would lead to
365+ breakage of the bazel query.
340366 """
341367
342368 if requirement .srcs .url :
343369 if not requirement .srcs .filename :
344370 logger .debug (lambda : "Could not detect the filename from the URL, falling back to pip: {}" .format (
345371 requirement .srcs .url ,
346372 ))
347- return None
373+ return None , True
348374
349375 # Handle direct URLs in requirements
350376 dist = struct (
@@ -354,13 +380,10 @@ def _add_dists(*, requirement, index_urls, target_platform, logger = None):
354380 yanked = False ,
355381 )
356382
357- if dist .filename .endswith (".whl" ):
358- return dist
359- else :
360- return dist
383+ return dist , False
361384
362385 if not index_urls :
363- return None
386+ return None , True
364387
365388 whls = []
366389 sdist = None
@@ -403,7 +426,14 @@ def _add_dists(*, requirement, index_urls, target_platform, logger = None):
403426
404427 if not target_platform :
405428 # The pipstar platforms are undefined here, so we cannot do any matching
406- return sdist
429+ return sdist , True
430+
431+ if not whls and not sdist :
432+ # If there are no suitable wheels to handle for now allow fallback to pip, it
433+ # may be a little bit more helpful when debugging? Most likely something is
434+ # going a bit wrong here, should we raise an error because the sha256 have most
435+ # likely mismatched? We are already printing a warning above.
436+ return None , True
407437
408438 # Select a single wheel that can work on the target_platform
409439 return select_whl (
@@ -413,4 +443,4 @@ def _add_dists(*, requirement, index_urls, target_platform, logger = None):
413443 whl_abi_tags = target_platform .whl_abi_tags ,
414444 whl_platform_tags = target_platform .whl_platform_tags ,
415445 logger = logger ,
416- ) or sdist
446+ ) or sdist , sdist != None
0 commit comments