@@ -24,7 +24,7 @@ load("//python/private:repo_utils.bzl", "repo_utils")
24
24
load ("//python/private:semver.bzl" , "semver" )
25
25
load ("//python/private:version_label.bzl" , "version_label" )
26
26
load (":attrs.bzl" , "use_isolated" )
27
- load (":evaluate_markers.bzl" , "evaluate_markers " )
27
+ load (":evaluate_markers.bzl" , "evaluate_markers_py" , EVALUATE_MARKERS_SRCS = "SRCS " )
28
28
load (":hub_repository.bzl" , "hub_repository" , "whl_config_settings_to_json" )
29
29
load (":parse_requirements.bzl" , "parse_requirements" )
30
30
load (":parse_whl_name.bzl" , "parse_whl_name" )
@@ -71,6 +71,7 @@ def _create_whl_repos(
71
71
whl_overrides ,
72
72
available_interpreters = INTERPRETER_LABELS ,
73
73
minor_mapping = MINOR_MAPPING ,
74
+ evaluate_markers = evaluate_markers_py ,
74
75
get_index_urls = None ):
75
76
"""create all of the whl repositories
76
77
@@ -85,6 +86,7 @@ def _create_whl_repos(
85
86
used during the `repository_rule` and must be always compatible with the host.
86
87
minor_mapping: {type}`dict[str, str]` The dictionary needed to resolve the full
87
88
python version used to parse package METADATA files.
89
+ evaluate_markers: the function used to evaluate the markers.
88
90
89
91
Returns a {type}`struct` with the following attributes:
90
92
whl_map: {type}`dict[str, list[struct]]` the output is keyed by the
@@ -172,7 +174,28 @@ def _create_whl_repos(
172
174
),
173
175
extra_pip_args = pip_attr .extra_pip_args ,
174
176
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
+ ),
176
199
logger = logger ,
177
200
)
178
201
@@ -193,6 +216,7 @@ def _create_whl_repos(
193
216
enable_implicit_namespace_pkgs = pip_attr .enable_implicit_namespace_pkgs ,
194
217
environment = pip_attr .environment ,
195
218
envsubst = pip_attr .envsubst ,
219
+ experimental_target_platforms = pip_attr .experimental_target_platforms ,
196
220
group_deps = group_deps ,
197
221
group_name = group_name ,
198
222
pip_data_exclude = pip_attr .pip_data_exclude ,
@@ -281,6 +305,13 @@ def _whl_repos(*, requirement, whl_library_args, download_only, netrc, auth_patt
281
305
args ["urls" ] = [distribution .url ]
282
306
args ["sha256" ] = distribution .sha256
283
307
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
+ ]
284
315
285
316
# Pure python wheels or sdists may need to have a platform here
286
317
target_platforms = None
@@ -775,6 +806,13 @@ EXPERIMENTAL: this may be removed without notice.
775
806
doc = """\
776
807
A dict of labels to wheel names that is typically generated by the whl_modifications.
777
808
The 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.
778
816
""" ,
779
817
),
780
818
}, ** ATTRS )
0 commit comments