@@ -121,33 +121,27 @@ def _create_whl_repos(*, module_ctx, pip_attr, whl_map, whl_overrides, config_se
121
121
))
122
122
python_interpreter_target = INTERPRETER_LABELS [python_name ]
123
123
124
- if pip_attr .experimental_whl_platform :
125
- pip_name = "{}_{}_{}" .format (
126
- hub_name ,
127
- pip_attr .experimental_whl_platform ,
128
- version_label (pip_attr .python_version ),
129
- )
130
- else :
131
- pip_name = "{}_{}" .format (
132
- hub_name ,
133
- version_label (pip_attr .python_version ),
134
- )
124
+ pip_name = "{}_{}" .format (
125
+ hub_name ,
126
+ version_label (pip_attr .python_version ),
127
+ )
135
128
136
129
major_minor = _major_minor_version (pip_attr .python_version )
137
130
target_platforms = pip_attr .experimental_target_platforms
138
131
platform_config_settings = []
132
+ default_version = _major_minor_version (DEFAULT_PYTHON_VERSION )
133
+
139
134
if pip_attr .experimental_whl_platform :
140
135
# NOTE @aignas 2024-02-16: Right now the download is extremely inefficient, because
141
136
# we have to download wheels for the target platform from scratch even though some
142
137
# of the wheels for the target platform could already be reused because they are
143
138
# multi-platform.
144
139
#
145
- # In order to improve this we would have to make `whl_library` support accessing its
146
- # deps via the hub_repo aliases (so that it references `@pip//foo` and does not need
147
- # to know if `foo` is target_platform specific or not. One more thing would be to
148
- # somehow know in advance the filename of the `whl` for the `whl_library` that we are
149
- # going to create. That way we could create only a single `whl_library` for all python
150
- # versions/platforms at once, thus simplifying the hub repo layout.
140
+ # In order to improve this we would have to somehow know in advance the
141
+ # filename of the `whl` for the `whl_library` that we are going to
142
+ # create. That way we could create only a single `whl_library` for all
143
+ # python versions/platforms at once, thus simplifying the hub repo
144
+ # layout.
151
145
requirements_lock = pip_attr .requirements_lock
152
146
if not requirements_lock or pip_attr .requirements_windows or pip_attr .requirements_darwin or pip_attr .requirements_linux :
153
147
fail ("only requirements_lock can be specified when platform is used" )
@@ -178,7 +172,6 @@ def _create_whl_repos(*, module_ctx, pip_attr, whl_map, whl_overrides, config_se
178
172
# Handle default version matching as well, so that we could use the
179
173
# platform specific wheels if they match the right platform without
180
174
# transitioning to a specific python version.
181
- default_version = _major_minor_version (DEFAULT_PYTHON_VERSION )
182
175
if default_version == major_minor :
183
176
platform_config_setting_name = "is_{}_{}" .format (
184
177
platforms [0 ].os ,
@@ -195,13 +188,7 @@ def _create_whl_repos(*, module_ctx, pip_attr, whl_map, whl_overrides, config_se
195
188
)
196
189
platform_config_settings .append ("//:" + platform_config_setting_name )
197
190
198
- target_platforms = [
199
- "cp{}_{}_{}" .format (
200
- version_label (major_minor ),
201
- platforms [0 ].os ,
202
- platforms [0 ].cpu ,
203
- ),
204
- ]
191
+ target_platforms = ["cp{}_{}_{}" .format (version_label (major_minor ), platforms [0 ].os , platforms [0 ].cpu )]
205
192
else :
206
193
platform_config_setting_name = "is_python_{}" .format (major_minor )
207
194
@@ -214,6 +201,9 @@ def _create_whl_repos(*, module_ctx, pip_attr, whl_map, whl_overrides, config_se
214
201
visibility = ["//:__subpackages__" ],
215
202
)
216
203
platform_config_settings .append ("//:" + platform_config_setting_name )
204
+ if default_version == major_minor :
205
+ platform_config_settings .append ("//conditions:default" )
206
+ config_settings_map [hub_name ]["//conditions:default" ] = "//conditions:default"
217
207
requirements_lock = locked_requirements_label (module_ctx , pip_attr )
218
208
219
209
# Parse the requirements file directly in starlark to get the information
@@ -261,7 +251,7 @@ def _create_whl_repos(*, module_ctx, pip_attr, whl_map, whl_overrides, config_se
261
251
for whl_name in group_whls
262
252
}
263
253
264
- group_repo = "%s__groups" % (pip_name ,)
254
+ group_repo = "%s__% s__groups" % (pip_name , pip_attr . experimental_whl_platform )
265
255
group_library (
266
256
name = group_repo ,
267
257
repo_prefix = pip_name + "_" ,
@@ -279,17 +269,24 @@ def _create_whl_repos(*, module_ctx, pip_attr, whl_map, whl_overrides, config_se
279
269
group_deps = requirement_cycles .get (group_name , [])
280
270
281
271
repo_name = "{}_{}" .format (pip_name , whl_name )
272
+ if pip_attr .experimental_whl_platform :
273
+ repo_name = "{}__{}" .format (repo_name , pip_attr .experimental_whl_platform )
274
+ whl_pip_name = "{}_{}" .format (pip_name , pip_attr .experimental_whl_platform )
275
+ else :
276
+ whl_pip_name = pip_name
277
+
282
278
whl_library (
283
279
name = repo_name ,
284
280
requirement = requirement_line ,
285
- repo = pip_name ,
286
- repo_prefix = pip_name + "_" ,
281
+ repo = whl_pip_name ,
282
+ repo_prefix = whl_pip_name + "_" ,
287
283
annotation = annotation ,
288
284
whl_patches = {
289
285
p : json .encode (args )
290
286
for p , args in whl_overrides .get (whl_name , {}).items ()
291
287
},
292
288
experimental_target_platforms = target_platforms ,
289
+ experimental_use_hub_for_deps = hub_name ,
293
290
python_interpreter = pip_attr .python_interpreter ,
294
291
python_interpreter_target = python_interpreter_target ,
295
292
quiet = pip_attr .quiet ,
@@ -481,7 +478,14 @@ def _pip_impl(module_ctx):
481
478
482
479
for hub_name , whl_map in hub_whl_map .items ():
483
480
build_file_contents = BUILD_FILE_CONTENTS
484
- config_settings = config_settings_map .get (hub_name , {}).values ()
481
+ has_default = False
482
+ config_settings = []
483
+ for value in config_settings_map .get (hub_name , {}).values ():
484
+ if value == "//conditions:default" :
485
+ has_default = True
486
+ continue
487
+ config_settings .append (value )
488
+
485
489
if config_settings :
486
490
self , _ , _ = str (Label ("//:MODULE.bazel" )).partition ("//" )
487
491
build_file_contents = "\n " .join ([
@@ -501,6 +505,7 @@ def _pip_impl(module_ctx):
501
505
for key , value in whl_map .items ()
502
506
},
503
507
default_version = _major_minor_version (DEFAULT_PYTHON_VERSION ),
508
+ render_default_version = not has_default ,
504
509
)
505
510
506
511
def _pip_parse_ext_attrs ():
0 commit comments