7
7
import mimetypes
8
8
import os
9
9
import shutil
10
- from typing import Dict , Iterable , List , Optional , Set
10
+ from pathlib import Path
11
+ from typing import Dict , Iterable , List , Optional
11
12
12
13
from pip ._vendor .packaging .utils import canonicalize_name
13
14
20
21
InstallationError ,
21
22
MetadataInconsistent ,
22
23
NetworkConnectionError ,
23
- PreviousBuildDirError ,
24
24
VcsHashUnsupported ,
25
25
)
26
26
from pip ._internal .index .package_finder import PackageFinder
47
47
display_path ,
48
48
hash_file ,
49
49
hide_url ,
50
- is_installable_dir ,
51
50
)
52
51
from pip ._internal .utils .temp_dir import TempDirectory
53
52
from pip ._internal .utils .unpacking import unpack_file
@@ -319,21 +318,7 @@ def _ensure_link_req_src_dir(
319
318
autodelete = True ,
320
319
parallel_builds = parallel_builds ,
321
320
)
322
-
323
- # If a checkout exists, it's unwise to keep going. version
324
- # inconsistencies are logged later, but do not fail the
325
- # installation.
326
- # FIXME: this won't upgrade when there's an existing
327
- # package unpacked in `req.source_dir`
328
- # TODO: this check is now probably dead code
329
- if is_installable_dir (req .source_dir ):
330
- raise PreviousBuildDirError (
331
- "pip can't proceed with requirements '{}' due to a"
332
- "pre-existing build directory ({}). This is likely "
333
- "due to a previous installation that failed . pip is "
334
- "being responsible and not assuming it can delete this. "
335
- "Please delete it and try again." .format (req , req .source_dir )
336
- )
321
+ req .ensure_pristine_source_checkout ()
337
322
338
323
def _get_linked_req_hashes (self , req : InstallRequirement ) -> Hashes :
339
324
# By the time this is called, the requirement's link should have
@@ -474,8 +459,6 @@ def _complete_partial_requirements(
474
459
assert req .link
475
460
links_to_fully_download [req .link ] = req
476
461
477
- reqs_with_newly_unpacked_source_dirs : Set [Link ] = set ()
478
-
479
462
batch_download = self ._batch_download (
480
463
links_to_fully_download .keys (),
481
464
temp_dir ,
@@ -490,28 +473,17 @@ def _complete_partial_requirements(
490
473
# _prepare_linked_requirement().
491
474
self ._downloaded [req .link .url ] = filepath
492
475
493
- # If this is an sdist, we need to unpack it and set the .source_dir
494
- # immediately after downloading, as _prepare_linked_requirement() assumes
495
- # the req is either not downloaded at all, or both downloaded and
496
- # unpacked. The downloading and unpacking is is typically done with
497
- # unpack_url(), but we separate the downloading and unpacking steps here in
498
- # order to use the BatchDownloader.
476
+ # If this is an sdist, we need to unpack it after downloading, but the
477
+ # .source_dir won't be set up until we are in _prepare_linked_requirement().
478
+ # Add the downloaded archive to the install requirement to unpack after
479
+ # preparing the source dir.
499
480
if not req .is_wheel :
500
- hashes = self ._get_linked_req_hashes (req )
501
- assert filepath == _check_download_dir (req .link , temp_dir , hashes )
502
- self ._ensure_link_req_src_dir (req , parallel_builds )
503
- unpack_file (filepath , req .source_dir )
504
- reqs_with_newly_unpacked_source_dirs .add (req .link )
481
+ req .needs_unpacked_archive (Path (filepath ))
505
482
506
483
# This step is necessary to ensure all lazy wheels are processed
507
484
# successfully by the 'download', 'wheel', and 'install' commands.
508
485
for req in partially_downloaded_reqs :
509
- self ._prepare_linked_requirement (
510
- req ,
511
- parallel_builds ,
512
- source_dir_exists_already = req .link
513
- in reqs_with_newly_unpacked_source_dirs ,
514
- )
486
+ self ._prepare_linked_requirement (req , parallel_builds )
515
487
516
488
def prepare_linked_requirement (
517
489
self , req : InstallRequirement , parallel_builds : bool = False
@@ -582,10 +554,7 @@ def prepare_linked_requirements_more(
582
554
)
583
555
584
556
def _prepare_linked_requirement (
585
- self ,
586
- req : InstallRequirement ,
587
- parallel_builds : bool ,
588
- source_dir_exists_already : bool = False ,
557
+ self , req : InstallRequirement , parallel_builds : bool
589
558
) -> BaseDistribution :
590
559
assert req .link
591
560
link = req .link
@@ -617,8 +586,7 @@ def _prepare_linked_requirement(
617
586
req .link = req .cached_wheel_source_link
618
587
link = req .link
619
588
620
- if not source_dir_exists_already :
621
- self ._ensure_link_req_src_dir (req , parallel_builds )
589
+ self ._ensure_link_req_src_dir (req , parallel_builds )
622
590
623
591
if link .is_existing_dir ():
624
592
local_file = None
0 commit comments