32
32
33
33
if MYPY_CHECK_RUNNING :
34
34
from typing import (
35
- Any , Callable , Iterable , List , Optional , Pattern , Text , Union ,
35
+ Any , Callable , Iterable , List , Optional , Pattern , Text , Tuple ,
36
36
)
37
37
38
38
from pip ._internal .cache import WheelCache
@@ -263,6 +263,37 @@ def _build_wheel_pep517(
263
263
return os .path .join (tempd , wheel_name )
264
264
265
265
266
+ def _collect_buildset (
267
+ requirements , # type: Iterable[InstallRequirement]
268
+ wheel_cache , # type: WheelCache
269
+ check_binary_allowed , # type: BinaryAllowedPredicate
270
+ need_wheel , # type: bool
271
+ ):
272
+ # type: (...) -> List[Tuple[InstallRequirement, str]]
273
+ """Return the list of InstallRequirement that need to be built,
274
+ with the persistent or temporary cache directory where the built
275
+ wheel needs to be stored.
276
+ """
277
+ buildset = []
278
+ cache_available = bool (wheel_cache .cache_dir )
279
+ for req in requirements :
280
+ if not should_build (
281
+ req ,
282
+ need_wheel = need_wheel ,
283
+ check_binary_allowed = check_binary_allowed ,
284
+ ):
285
+ continue
286
+ if (
287
+ cache_available and
288
+ should_cache (req , check_binary_allowed )
289
+ ):
290
+ cache_dir = wheel_cache .get_path_for_link (req .link )
291
+ else :
292
+ cache_dir = wheel_cache .get_ephem_path_for_link (req .link )
293
+ buildset .append ((req , cache_dir ))
294
+ return buildset
295
+
296
+
266
297
def _always_true (_ ):
267
298
# type: (Any) -> bool
268
299
return True
@@ -292,8 +323,6 @@ def __init__(
292
323
self .build_options = build_options or []
293
324
self .global_options = global_options or []
294
325
self .check_binary_allowed = check_binary_allowed
295
- # file names of built wheel names
296
- self .wheel_filenames = [] # type: List[Union[bytes, Text]]
297
326
298
327
def _build_one (
299
328
self ,
@@ -389,29 +418,12 @@ def build(
389
418
(not should_unpack and self ._wheel_dir )
390
419
)
391
420
392
- buildset = []
393
- cache_available = bool (self .wheel_cache .cache_dir )
394
-
395
- for req in requirements :
396
- if not should_build (
397
- req ,
398
- need_wheel = not should_unpack ,
399
- check_binary_allowed = self .check_binary_allowed ,
400
- ):
401
- continue
402
-
403
- if (
404
- cache_available and
405
- should_cache (req , self .check_binary_allowed )
406
- ):
407
- output_dir = self .wheel_cache .get_path_for_link (req .link )
408
- else :
409
- output_dir = self .wheel_cache .get_ephem_path_for_link (
410
- req .link
411
- )
412
-
413
- buildset .append ((req , output_dir ))
414
-
421
+ buildset = _collect_buildset (
422
+ requirements ,
423
+ wheel_cache = self .wheel_cache ,
424
+ check_binary_allowed = self .check_binary_allowed ,
425
+ need_wheel = not should_unpack ,
426
+ )
415
427
if not buildset :
416
428
return []
417
429
@@ -426,9 +438,9 @@ def build(
426
438
427
439
with indent_log ():
428
440
build_success , build_failure = [], []
429
- for req , output_dir in buildset :
441
+ for req , cache_dir in buildset :
430
442
try :
431
- ensure_dir (output_dir )
443
+ ensure_dir (cache_dir )
432
444
except OSError as e :
433
445
logger .warning (
434
446
"Building wheel for %s failed: %s" ,
@@ -437,7 +449,7 @@ def build(
437
449
build_failure .append (req )
438
450
continue
439
451
440
- wheel_file = self ._build_one (req , output_dir )
452
+ wheel_file = self ._build_one (req , cache_dir )
441
453
if wheel_file :
442
454
if should_unpack :
443
455
# XXX: This is mildly duplicative with prepare_files,
@@ -467,10 +479,7 @@ def build(
467
479
# copy from cache to target directory
468
480
try :
469
481
ensure_dir (self ._wheel_dir )
470
- shutil .copy (
471
- os .path .join (output_dir , wheel_file ),
472
- self ._wheel_dir ,
473
- )
482
+ shutil .copy (wheel_file , self ._wheel_dir )
474
483
except OSError as e :
475
484
logger .warning (
476
485
"Building wheel for %s failed: %s" ,
0 commit comments