@@ -440,18 +440,27 @@ def _prepare_file(self, finder, req_to_install):
440
440
# otherwise a result is guaranteed.
441
441
assert req_to_install .link
442
442
try :
443
- if req_to_install .link .is_wheel and \
444
- self .wheel_download_dir :
445
- # when doing 'pip wheel`
443
+ download_dir = self .download_dir
444
+ # We always delete unpacked sdists after pip ran.
445
+ autodelete_unpacked = True
446
+ if req_to_install .link .is_wheel \
447
+ and self .wheel_download_dir :
448
+ # when doing 'pip wheel` we download wheels to a
449
+ # dedicated dir.
446
450
download_dir = self .wheel_download_dir
447
- do_download = True
448
- else :
449
- download_dir = self .download_dir
450
- do_download = self .is_download
451
+ if req_to_install .link .is_wheel :
452
+ if download_dir :
453
+ # When downloading, we only unpack wheels to get
454
+ # metadata.
455
+ autodelete_unpacked = True
456
+ else :
457
+ # When installing a wheel, we use the unpacked
458
+ # wheel.
459
+ autodelete_unpacked = False
451
460
unpack_url (
452
461
req_to_install .link , req_to_install .source_dir ,
453
- download_dir , do_download , session = self . session ,
454
- )
462
+ download_dir , autodelete_unpacked ,
463
+ session = self . session )
455
464
except requests .HTTPError as exc :
456
465
logger .critical (
457
466
'Could not install requirement %s because '
0 commit comments