Skip to content

Commit

Permalink
Merge pull request #7510 from chrahunt/refactor/operations-prepare-mo…
Browse files Browse the repository at this point in the history
…ve-download-up

Move download copying out of unpacking functions
  • Loading branch information
chrahunt authored Dec 29, 2019
2 parents 2721712 + ce9ddbb commit b3741ac
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,6 @@ def unpack_http_url(
# downloading archives, they have to be unpacked to parse dependencies
unpack_file(from_path, location, content_type)

# a download dir is specified; let's copy the archive there
if download_dir and not os.path.exists(
os.path.join(download_dir, link.filename)
):
_copy_file(from_path, download_dir, link)

return from_path


Expand Down Expand Up @@ -223,18 +217,13 @@ def unpack_file_url(
):
# type: (...) -> Optional[str]
"""Unpack link into location.
If download_dir is provided and link points to a file, make a copy
of the link file inside download_dir.
"""
link_path = link.file_path
# If it's a url to a local directory
if link.is_existing_dir():
if os.path.isdir(location):
rmtree(location)
_copy_source_tree(link_path, location)
if download_dir:
logger.info('Link is a directory, ignoring download_dir')
return None

# If a download dir is specified, is the file already there and valid?
Expand Down Expand Up @@ -263,12 +252,6 @@ def unpack_file_url(
# archives, they have to be unpacked to parse dependencies
unpack_file(from_path, location, content_type)

# a download dir is specified and not already downloaded
if download_dir and not os.path.exists(
os.path.join(download_dir, link.filename)
):
_copy_file(from_path, download_dir, link)

return from_path


Expand All @@ -280,14 +263,7 @@ def unpack_url(
hashes=None, # type: Optional[Hashes]
):
# type: (...) -> Optional[str]
"""Unpack link.
If link is a VCS link:
if only_download, export into download_dir and ignore location
else unpack into location
for other types of link:
- unpack into location
- if download_dir, copy the file into download_dir
- if only_download, mark location for deletion
"""Unpack link into location, downloading if required.
:param hashes: A Hashes object, one of whose embedded hashes must match,
or HashMismatch will be raised. If the Hashes is empty, no matches are
Expand Down Expand Up @@ -544,6 +520,14 @@ def prepare_linked_requirement(
req, self.req_tracker, self.finder, self.build_isolation,
)

if download_dir:
if link.is_existing_dir():
logger.info('Link is a directory, ignoring download_dir')
elif local_path and not os.path.exists(
os.path.join(download_dir, link.filename)
):
_copy_file(local_path, download_dir, link)

if self._download_should_save:
# Make a .zip of the source_dir we already created.
if link.is_vcs:
Expand Down

0 comments on commit b3741ac

Please sign in to comment.