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
@@ -317,21 +316,7 @@ def _ensure_link_req_src_dir(
317
316
autodelete = True ,
318
317
parallel_builds = parallel_builds ,
319
318
)
320
-
321
- # If a checkout exists, it's unwise to keep going. version
322
- # inconsistencies are logged later, but do not fail the
323
- # installation.
324
- # FIXME: this won't upgrade when there's an existing
325
- # package unpacked in `req.source_dir`
326
- # TODO: this check is now probably dead code
327
- if is_installable_dir (req .source_dir ):
328
- raise PreviousBuildDirError (
329
- "pip can't proceed with requirements '{}' due to a"
330
- "pre-existing build directory ({}). This is likely "
331
- "due to a previous installation that failed . pip is "
332
- "being responsible and not assuming it can delete this. "
333
- "Please delete it and try again." .format (req , req .source_dir )
334
- )
319
+ req .ensure_pristine_source_checkout ()
335
320
336
321
def _get_linked_req_hashes (self , req : InstallRequirement ) -> Hashes :
337
322
# By the time this is called, the requirement's link should have
@@ -472,8 +457,6 @@ def _complete_partial_requirements(
472
457
assert req .link
473
458
links_to_fully_download [req .link ] = req
474
459
475
- reqs_with_newly_unpacked_source_dirs : Set [Link ] = set ()
476
-
477
460
batch_download = self ._batch_download (
478
461
links_to_fully_download .keys (),
479
462
temp_dir ,
@@ -488,28 +471,17 @@ def _complete_partial_requirements(
488
471
# _prepare_linked_requirement().
489
472
self ._downloaded [req .link .url ] = filepath
490
473
491
- # If this is an sdist, we need to unpack it and set the .source_dir
492
- # immediately after downloading, as _prepare_linked_requirement() assumes
493
- # the req is either not downloaded at all, or both downloaded and
494
- # unpacked. The downloading and unpacking is is typically done with
495
- # unpack_url(), but we separate the downloading and unpacking steps here in
496
- # order to use the BatchDownloader.
474
+ # If this is an sdist, we need to unpack it after downloading, but the
475
+ # .source_dir won't be set up until we are in _prepare_linked_requirement().
476
+ # Add the downloaded archive to the install requirement to unpack after
477
+ # preparing the source dir.
497
478
if not req .is_wheel :
498
- hashes = self ._get_linked_req_hashes (req )
499
- assert filepath == _check_download_dir (req .link , temp_dir , hashes )
500
- self ._ensure_link_req_src_dir (req , parallel_builds )
501
- unpack_file (filepath , req .source_dir )
502
- reqs_with_newly_unpacked_source_dirs .add (req .link )
479
+ req .needs_unpacked_archive (Path (filepath ))
503
480
504
481
# This step is necessary to ensure all lazy wheels are processed
505
482
# successfully by the 'download', 'wheel', and 'install' commands.
506
483
for req in partially_downloaded_reqs :
507
- self ._prepare_linked_requirement (
508
- req ,
509
- parallel_builds ,
510
- source_dir_exists_already = req .link
511
- in reqs_with_newly_unpacked_source_dirs ,
512
- )
484
+ self ._prepare_linked_requirement (req , parallel_builds )
513
485
514
486
def prepare_linked_requirement (
515
487
self , req : InstallRequirement , parallel_builds : bool = False
@@ -580,10 +552,7 @@ def prepare_linked_requirements_more(
580
552
)
581
553
582
554
def _prepare_linked_requirement (
583
- self ,
584
- req : InstallRequirement ,
585
- parallel_builds : bool ,
586
- source_dir_exists_already : bool = False ,
555
+ self , req : InstallRequirement , parallel_builds : bool
587
556
) -> BaseDistribution :
588
557
assert req .link
589
558
link = req .link
@@ -615,8 +584,7 @@ def _prepare_linked_requirement(
615
584
req .link = req .cached_wheel_source_link
616
585
link = req .link
617
586
618
- if not source_dir_exists_already :
619
- self ._ensure_link_req_src_dir (req , parallel_builds )
587
+ self ._ensure_link_req_src_dir (req , parallel_builds )
620
588
621
589
if link .is_existing_dir ():
622
590
local_file = None
0 commit comments