@@ -234,7 +234,7 @@ def _package_srcs(
234234 platforms .keys (),
235235 ))
236236
237- dist = _add_dists (
237+ dist , can_fallback = _add_dists (
238238 requirement = r ,
239239 target_platform = platforms .get (target_platform ),
240240 index_urls = index_urls .get (name ),
@@ -244,14 +244,16 @@ def _package_srcs(
244244
245245 if extract_url_srcs and dist :
246246 req_line = r .srcs .requirement
247- else :
247+ elif can_fallback :
248248 dist = struct (
249249 url = "" ,
250250 filename = "" ,
251251 sha256 = "" ,
252252 yanked = False ,
253253 )
254254 req_line = r .srcs .requirement_line
255+ else :
256+ continue
255257
256258 key = (
257259 dist .filename ,
@@ -337,14 +339,22 @@ def _add_dists(*, requirement, index_urls, target_platform, logger = None):
337339 index_urls: The result of simpleapi_download.
338340 target_platform: The target_platform information.
339341 logger: A logger for printing diagnostic info.
342+
343+ Returns:
344+ (dist, can_fallback_to_pip): a struct with distribution details and how to fetch
345+ it and a boolean flag to tell the other layers if we should add an entry to
346+ fallback for pip if there are no supported whls found - if there is an sdist, we
347+ can attempt the fallback, otherwise better to not, because the pip command will
348+ fail and the error message will be confusing. What is more that would lead to
349+ breakage of the bazel query.
340350 """
341351
342352 if requirement .srcs .url :
343353 if not requirement .srcs .filename :
344354 logger .debug (lambda : "Could not detect the filename from the URL, falling back to pip: {}" .format (
345355 requirement .srcs .url ,
346356 ))
347- return None
357+ return None , True
348358
349359 # Handle direct URLs in requirements
350360 dist = struct (
@@ -355,12 +365,12 @@ def _add_dists(*, requirement, index_urls, target_platform, logger = None):
355365 )
356366
357367 if dist .filename .endswith (".whl" ):
358- return dist
368+ return dist , False
359369 else :
360- return dist
370+ return dist , False
361371
362372 if not index_urls :
363- return None
373+ return None , True
364374
365375 whls = []
366376 sdist = None
@@ -413,4 +423,4 @@ def _add_dists(*, requirement, index_urls, target_platform, logger = None):
413423 whl_abi_tags = target_platform .whl_abi_tags ,
414424 whl_platform_tags = target_platform .whl_platform_tags ,
415425 logger = logger ,
416- ) or sdist
426+ ) or sdist , sdist != None
0 commit comments