Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move download copying out of unpacking functions #7510

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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