@@ -202,8 +202,12 @@ def _create_whl_repos(
202
202
logger = logger ,
203
203
)
204
204
205
- for whl_name , requirements in requirements_by_platform .items ():
206
- group_name = whl_group_mapping .get (whl_name )
205
+ exposed_packages = {}
206
+ for whl in requirements_by_platform :
207
+ if whl .is_exposed :
208
+ exposed_packages [whl .name ] = None
209
+
210
+ group_name = whl_group_mapping .get (whl .name )
207
211
group_deps = requirement_cycles .get (group_name , [])
208
212
209
213
# Construct args separately so that the lock file can be smaller and does not include unused
@@ -214,7 +218,7 @@ def _create_whl_repos(
214
218
maybe_args = dict (
215
219
# The following values are safe to omit if they have false like values
216
220
add_libdir_to_library_search_path = pip_attr .add_libdir_to_library_search_path ,
217
- annotation = whl_modifications .get (whl_name ),
221
+ annotation = whl_modifications .get (whl . name ),
218
222
download_only = pip_attr .download_only ,
219
223
enable_implicit_namespace_pkgs = pip_attr .enable_implicit_namespace_pkgs ,
220
224
environment = pip_attr .environment ,
@@ -226,7 +230,7 @@ def _create_whl_repos(
226
230
python_interpreter_target = python_interpreter_target ,
227
231
whl_patches = {
228
232
p : json .encode (args )
229
- for p , args in whl_overrides .get (whl_name , {}).items ()
233
+ for p , args in whl_overrides .get (whl . name , {}).items ()
230
234
},
231
235
)
232
236
if not enable_pipstar :
@@ -245,119 +249,99 @@ def _create_whl_repos(
245
249
if v != default
246
250
})
247
251
248
- for requirement in requirements :
249
- for repo_name , ( args , config_setting ) in _whl_repos (
250
- requirement = requirement ,
252
+ for src in whl . srcs :
253
+ repo = _whl_repo (
254
+ src = src ,
251
255
whl_library_args = whl_library_args ,
252
256
download_only = pip_attr .download_only ,
253
257
netrc = pip_attr .netrc ,
254
258
auth_patterns = pip_attr .auth_patterns ,
255
259
python_version = major_minor ,
256
- multiple_requirements_for_whl = len ( requirements ) > 1. ,
260
+ is_multiple_versions = whl . is_multiple_versions ,
257
261
enable_pipstar = enable_pipstar ,
258
- ).items ():
259
- repo_name = "{}_{}" .format (pip_name , repo_name )
260
- if repo_name in whl_libraries :
261
- fail ("Attempting to creating a duplicate library {} for {}" .format (
262
- repo_name ,
263
- whl_name ,
264
- ))
262
+ )
265
263
266
- whl_libraries [repo_name ] = args
267
- whl_map .setdefault (whl_name , {})[config_setting ] = repo_name
264
+ repo_name = "{}_{}" .format (pip_name , repo .repo_name )
265
+ if repo_name in whl_libraries :
266
+ fail ("Attempting to creating a duplicate library {} for {}" .format (
267
+ repo_name ,
268
+ whl .name ,
269
+ ))
270
+
271
+ whl_libraries [repo_name ] = repo .args
272
+ whl_map .setdefault (whl .name , {})[repo .config_setting ] = repo_name
268
273
269
274
return struct (
270
275
whl_map = whl_map ,
271
- exposed_packages = {
272
- whl_name : None
273
- for whl_name , requirements in requirements_by_platform .items ()
274
- if len ([r for r in requirements if r .is_exposed ]) > 0
275
- },
276
+ exposed_packages = exposed_packages ,
276
277
extra_aliases = extra_aliases ,
277
278
whl_libraries = whl_libraries ,
278
279
)
279
280
280
- def _whl_repos (* , requirement , whl_library_args , download_only , netrc , auth_patterns , multiple_requirements_for_whl = False , python_version , enable_pipstar = False ):
281
- ret = {}
282
-
283
- dists = requirement .whls
284
- if not download_only and requirement .sdist :
285
- dists = dists + [requirement .sdist ]
286
-
287
- for distribution in dists :
288
- args = dict (whl_library_args )
289
- if netrc :
290
- args ["netrc" ] = netrc
291
- if auth_patterns :
292
- args ["auth_patterns" ] = auth_patterns
293
-
294
- if not distribution .filename .endswith (".whl" ):
295
- # pip is not used to download wheels and the python
296
- # `whl_library` helpers are only extracting things, however
297
- # for sdists, they will be built by `pip`, so we still
298
- # need to pass the extra args there.
299
- args ["extra_pip_args" ] = requirement .extra_pip_args
300
-
301
- # This is no-op because pip is not used to download the wheel.
302
- args .pop ("download_only" , None )
303
-
304
- args ["requirement" ] = requirement .line
305
- args ["urls" ] = [distribution .url ]
306
- args ["sha256" ] = distribution .sha256
307
- args ["filename" ] = distribution .filename
308
- if not enable_pipstar :
309
- args ["experimental_target_platforms" ] = [
310
- # Get rid of the version fot the target platforms because we are
311
- # passing the interpreter any way. Ideally we should search of ways
312
- # how to pass the target platforms through the hub repo.
313
- p .partition ("_" )[2 ]
314
- for p in requirement .target_platforms
315
- ]
316
-
317
- # Pure python wheels or sdists may need to have a platform here
318
- target_platforms = None
319
- if distribution .filename .endswith (".whl" ) and not distribution .filename .endswith ("-any.whl" ):
320
- pass
321
- elif multiple_requirements_for_whl :
322
- target_platforms = requirement .target_platforms
323
-
324
- repo_name = whl_repo_name (
325
- distribution .filename ,
326
- distribution .sha256 ,
327
- )
328
- ret [repo_name ] = (
329
- args ,
330
- whl_config_setting (
281
+ def _whl_repo (* , src , whl_library_args , is_multiple_versions , download_only , netrc , auth_patterns , python_version , enable_pipstar = False ):
282
+ args = dict (whl_library_args )
283
+ args ["requirement" ] = src .requirement_line
284
+ is_whl = src .filename .endswith (".whl" )
285
+
286
+ if src .extra_pip_args and not is_whl :
287
+ # pip is not used to download wheels and the python
288
+ # `whl_library` helpers are only extracting things, however
289
+ # for sdists, they will be built by `pip`, so we still
290
+ # need to pass the extra args there, so only pop this for whls
291
+ args ["extra_pip_args" ] = src .extra_pip_args
292
+
293
+ if not src .url or (not is_whl and download_only ):
294
+ # Fallback to a pip-installed wheel
295
+ target_platforms = src .target_platforms if is_multiple_versions else []
296
+ return struct (
297
+ repo_name = pypi_repo_name (
298
+ normalize_name (src .distribution ),
299
+ * target_platforms
300
+ ),
301
+ args = args ,
302
+ config_setting = whl_config_setting (
331
303
version = python_version ,
332
- filename = distribution .filename ,
333
- target_platforms = target_platforms ,
304
+ target_platforms = target_platforms or None ,
334
305
),
335
306
)
336
307
337
- if ret :
338
- return ret
339
-
340
- # Fallback to a pip-installed wheel
341
- args = dict (whl_library_args ) # make a copy
342
- args ["requirement" ] = requirement .line
343
- if requirement .extra_pip_args :
344
- args ["extra_pip_args" ] = requirement .extra_pip_args
308
+ # This is no-op because pip is not used to download the wheel.
309
+ args .pop ("download_only" , None )
310
+
311
+ if netrc :
312
+ args ["netrc" ] = netrc
313
+ if auth_patterns :
314
+ args ["auth_patterns" ] = auth_patterns
315
+
316
+ args ["urls" ] = [src .url ]
317
+ args ["sha256" ] = src .sha256
318
+ args ["filename" ] = src .filename
319
+ if not enable_pipstar :
320
+ args ["experimental_target_platforms" ] = [
321
+ # Get rid of the version fot the target platforms because we are
322
+ # passing the interpreter any way. Ideally we should search of ways
323
+ # how to pass the target platforms through the hub repo.
324
+ p .partition ("_" )[2 ]
325
+ for p in src .target_platforms
326
+ ]
327
+
328
+ # Pure python wheels or sdists may need to have a platform here
329
+ target_platforms = None
330
+ if is_whl and not src .filename .endswith ("-any.whl" ):
331
+ pass
332
+ elif is_multiple_versions :
333
+ target_platforms = src .target_platforms
345
334
346
- target_platforms = requirement .target_platforms if multiple_requirements_for_whl else []
347
- repo_name = pypi_repo_name (
348
- normalize_name (requirement .distribution ),
349
- * target_platforms
350
- )
351
- ret [repo_name ] = (
352
- args ,
353
- whl_config_setting (
335
+ return struct (
336
+ repo_name = whl_repo_name (src .filename , src .sha256 ),
337
+ args = args ,
338
+ config_setting = whl_config_setting (
354
339
version = python_version ,
355
- target_platforms = target_platforms or None ,
340
+ filename = src .filename ,
341
+ target_platforms = target_platforms ,
356
342
),
357
343
)
358
344
359
- return ret
360
-
361
345
def parse_modules (
362
346
module_ctx ,
363
347
_fail = fail ,
0 commit comments