|
7 | 7 | import mimetypes
|
8 | 8 | import os
|
9 | 9 | import shutil
|
| 10 | +from pathlib import Path |
10 | 11 | from typing import Dict, Iterable, List, Optional
|
11 | 12 |
|
12 | 13 | from pip._vendor.packaging.utils import canonicalize_name
|
|
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
|
@@ -481,20 +466,19 @@ def _complete_partial_requirements(
|
481 | 466 | for link, (filepath, _) in batch_download:
|
482 | 467 | logger.debug("Downloading link %s to %s", link, filepath)
|
483 | 468 | req = links_to_fully_download[link]
|
| 469 | + # Record the downloaded file path so wheel reqs can extract a Distribution |
| 470 | + # in .get_dist(). |
484 | 471 | req.local_file_path = filepath
|
485 |
| - # TODO: This needs fixing for sdists |
486 |
| - # This is an emergency fix for #11847, which reports that |
487 |
| - # distributions get downloaded twice when metadata is loaded |
488 |
| - # from a PEP 658 standalone metadata file. Setting _downloaded |
489 |
| - # fixes this for wheels, but breaks the sdist case (tests |
490 |
| - # test_download_metadata). As PyPI is currently only serving |
491 |
| - # metadata for wheels, this is not an immediate issue. |
492 |
| - # Fixing the problem properly looks like it will require a |
493 |
| - # complete refactoring of the `prepare_linked_requirements_more` |
494 |
| - # logic, and I haven't a clue where to start on that, so for now |
495 |
| - # I have fixed the issue *just* for wheels. |
496 |
| - if req.is_wheel: |
497 |
| - self._downloaded[req.link.url] = filepath |
| 472 | + # Record that the file is downloaded so we don't do it again in |
| 473 | + # _prepare_linked_requirement(). |
| 474 | + self._downloaded[req.link.url] = filepath |
| 475 | + |
| 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. |
| 480 | + if not req.is_wheel: |
| 481 | + req.needs_unpacked_archive(Path(filepath)) |
498 | 482 |
|
499 | 483 | # This step is necessary to ensure all lazy wheels are processed
|
500 | 484 | # successfully by the 'download', 'wheel', and 'install' commands.
|
|
0 commit comments