@@ -24,7 +24,7 @@ load("//python/private:version_label.bzl", "version_label")
2424load (":attrs.bzl" , "use_isolated" )
2525load (":evaluate_markers.bzl" , "evaluate_markers" , EVALUATE_MARKERS_SRCS = "SRCS" )
2626load (":hub_repository.bzl" , "hub_repository" )
27- load (":parse_requirements.bzl" , "parse_requirements" )
27+ load (":parse_requirements.bzl" , "host_platform" , " parse_requirements" , "select_requirement " )
2828load (":parse_whl_name.bzl" , "parse_whl_name" )
2929load (":pip_repository_attrs.bzl" , "ATTRS" )
3030load (":render_pkg_aliases.bzl" , "whl_alias" )
@@ -212,6 +212,7 @@ def _create_whl_repos(
212212 logger = logger ,
213213 )
214214
215+ repository_platform = host_platform (module_ctx )
215216 for whl_name , requirements in requirements_by_platform .items ():
216217 # We are not using the "sanitized name" because the user
217218 # would need to guess what name we modified the whl name
@@ -318,6 +319,38 @@ def _create_whl_repos(
318319 exposed_packages [whl_name ] = None
319320 continue
320321
322+ if not pip_attr .parse_all_requirements_files :
323+ requirement = select_requirement (
324+ requirements ,
325+ platform = None if pip_attr .download_only else repository_platform ,
326+ )
327+ if not requirement :
328+ # Sometimes the package is not present for host platform if there
329+ # are whls specified only in particular requirements files, in that
330+ # case just continue, however, if the download_only flag is set up,
331+ # then the user can also specify the target platform of the wheel
332+ # packages they want to download, in that case there will be always
333+ # a requirement here, so we will not be in this code branch.
334+ continue
335+ elif get_index_urls :
336+ logger .warn (lambda : "falling back to pip for installing the right file for {}" .format (requirement .requirement_line ))
337+
338+ whl_library_args ["requirement" ] = requirement .requirement_line
339+ if requirement .extra_pip_args :
340+ whl_library_args ["extra_pip_args" ] = requirement .extra_pip_args
341+
342+ # We sort so that the lock-file remains the same no matter the order of how the
343+ # args are manipulated in the code going before.
344+ repo_name = "{}_{}" .format (pip_name , whl_name )
345+ whl_libraries [repo_name ] = dict (whl_library_args .items ())
346+ whl_map .setdefault (whl_name , []).append (
347+ whl_alias (
348+ repo = repo_name ,
349+ version = major_minor ,
350+ ),
351+ )
352+ continue
353+
321354 for requirement in requirements :
322355 is_exposed = is_exposed or requirement .is_exposed
323356 if get_index_urls :
@@ -730,6 +763,20 @@ find in case extra indexes are specified.
730763""" ,
731764 default = True ,
732765 ),
766+ "parse_all_requirements_files" : attr .bool (
767+ default = False ,
768+ doc = """\
769+ A temporary flag to enable users to make `pip` extension result always
770+ the same independent of the whether transitive dependencies use {bzl:attr}`experimental_index_url` or not.
771+
772+ This enables users to migrate to a solution that fixes
773+ [#2268](https://github.com/bazelbuild/rules_python/issues/2268).
774+
775+ ::::{deprecated} 0.38.0
776+ This is a transition flag and will be removed in a subsequent release.
777+ ::::
778+ """ ,
779+ ),
733780 "python_version" : attr .string (
734781 mandatory = True ,
735782 doc = """
0 commit comments