@@ -24,7 +24,7 @@ load("//python/private:repo_utils.bzl", "repo_utils")
2424load ("//python/private:semver.bzl" , "semver" )
2525load ("//python/private:version_label.bzl" , "version_label" )
2626load (":attrs.bzl" , "use_isolated" )
27- load (":evaluate_markers.bzl" , "evaluate_markers " )
27+ load (":evaluate_markers.bzl" , "evaluate_markers_py" , EVALUATE_MARKERS_SRCS = "SRCS " )
2828load (":hub_repository.bzl" , "hub_repository" , "whl_config_settings_to_json" )
2929load (":parse_requirements.bzl" , "parse_requirements" )
3030load (":parse_whl_name.bzl" , "parse_whl_name" )
@@ -71,6 +71,7 @@ def _create_whl_repos(
7171 whl_overrides ,
7272 available_interpreters = INTERPRETER_LABELS ,
7373 minor_mapping = MINOR_MAPPING ,
74+ evaluate_markers = evaluate_markers_py ,
7475 get_index_urls = None ):
7576 """create all of the whl repositories
7677
@@ -85,6 +86,7 @@ def _create_whl_repos(
8586 used during the `repository_rule` and must be always compatible with the host.
8687 minor_mapping: {type}`dict[str, str]` The dictionary needed to resolve the full
8788 python version used to parse package METADATA files.
89+ evaluate_markers: the function used to evaluate the markers.
8890
8991 Returns a {type}`struct` with the following attributes:
9092 whl_map: {type}`dict[str, list[struct]]` the output is keyed by the
@@ -172,7 +174,28 @@ def _create_whl_repos(
172174 ),
173175 extra_pip_args = pip_attr .extra_pip_args ,
174176 get_index_urls = get_index_urls ,
175- evaluate_markers = evaluate_markers ,
177+ # NOTE @aignas 2024-08-02: , we will execute any interpreter that we find either
178+ # in the PATH or if specified as a label. We will configure the env
179+ # markers when evaluating the requirement lines based on the output
180+ # from the `requirements_files_by_platform` which should have something
181+ # similar to:
182+ # {
183+ # "//:requirements.txt": ["cp311_linux_x86_64", ...]
184+ # }
185+ #
186+ # We know the target python versions that we need to evaluate the
187+ # markers for and thus we don't need to use multiple python interpreter
188+ # instances to perform this manipulation. This function should be executed
189+ # only once by the underlying code to minimize the overhead needed to
190+ # spin up a Python interpreter.
191+ evaluate_markers = lambda module_ctx , requirements : evaluate_markers (
192+ module_ctx ,
193+ requirements = requirements ,
194+ python_interpreter = pip_attr .python_interpreter ,
195+ python_interpreter_target = python_interpreter_target ,
196+ srcs = pip_attr ._evaluate_markers_srcs ,
197+ logger = logger ,
198+ ),
176199 logger = logger ,
177200 )
178201
@@ -193,6 +216,7 @@ def _create_whl_repos(
193216 enable_implicit_namespace_pkgs = pip_attr .enable_implicit_namespace_pkgs ,
194217 environment = pip_attr .environment ,
195218 envsubst = pip_attr .envsubst ,
219+ experimental_target_platforms = pip_attr .experimental_target_platforms ,
196220 group_deps = group_deps ,
197221 group_name = group_name ,
198222 pip_data_exclude = pip_attr .pip_data_exclude ,
@@ -281,6 +305,13 @@ def _whl_repos(*, requirement, whl_library_args, download_only, netrc, auth_patt
281305 args ["urls" ] = [distribution .url ]
282306 args ["sha256" ] = distribution .sha256
283307 args ["filename" ] = distribution .filename
308+ args ["experimental_target_platforms" ] = [
309+ # Get rid of the version fot the target platforms because we are
310+ # passing the interpreter any way. Ideally we should search of ways
311+ # how to pass the target platforms through the hub repo.
312+ p .partition ("_" )[2 ]
313+ for p in requirement .target_platforms
314+ ]
284315
285316 # Pure python wheels or sdists may need to have a platform here
286317 target_platforms = None
@@ -775,6 +806,13 @@ EXPERIMENTAL: this may be removed without notice.
775806 doc = """\
776807 A dict of labels to wheel names that is typically generated by the whl_modifications.
777808The labels are JSON config files describing the modifications.
809+ """ ,
810+ ),
811+ "_evaluate_markers_srcs" : attr .label_list (
812+ default = EVALUATE_MARKERS_SRCS ,
813+ doc = """\
814+ The list of labels to use as SRCS for the marker evaluation code. This ensures that the
815+ code will be re-evaluated when any of files in the default changes.
778816""" ,
779817 ),
780818 }, ** ATTRS )
0 commit comments