Skip to content

Commit b3741ac

Browse files
authored
Merge pull request #7510 from chrahunt/refactor/operations-prepare-move-download-up
Move download copying out of unpacking functions
2 parents 2721712 + ce9ddbb commit b3741ac

File tree

1 file changed

+9
-25
lines changed

1 file changed

+9
-25
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,6 @@ def unpack_http_url(
165165
# downloading archives, they have to be unpacked to parse dependencies
166166
unpack_file(from_path, location, content_type)
167167

168-
# a download dir is specified; let's copy the archive there
169-
if download_dir and not os.path.exists(
170-
os.path.join(download_dir, link.filename)
171-
):
172-
_copy_file(from_path, download_dir, link)
173-
174168
return from_path
175169

176170

@@ -223,18 +217,13 @@ def unpack_file_url(
223217
):
224218
# type: (...) -> Optional[str]
225219
"""Unpack link into location.
226-
227-
If download_dir is provided and link points to a file, make a copy
228-
of the link file inside download_dir.
229220
"""
230221
link_path = link.file_path
231222
# If it's a url to a local directory
232223
if link.is_existing_dir():
233224
if os.path.isdir(location):
234225
rmtree(location)
235226
_copy_source_tree(link_path, location)
236-
if download_dir:
237-
logger.info('Link is a directory, ignoring download_dir')
238227
return None
239228

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

266-
# a download dir is specified and not already downloaded
267-
if download_dir and not os.path.exists(
268-
os.path.join(download_dir, link.filename)
269-
):
270-
_copy_file(from_path, download_dir, link)
271-
272255
return from_path
273256

274257

@@ -280,14 +263,7 @@ def unpack_url(
280263
hashes=None, # type: Optional[Hashes]
281264
):
282265
# type: (...) -> Optional[str]
283-
"""Unpack link.
284-
If link is a VCS link:
285-
if only_download, export into download_dir and ignore location
286-
else unpack into location
287-
for other types of link:
288-
- unpack into location
289-
- if download_dir, copy the file into download_dir
290-
- if only_download, mark location for deletion
266+
"""Unpack link into location, downloading if required.
291267
292268
:param hashes: A Hashes object, one of whose embedded hashes must match,
293269
or HashMismatch will be raised. If the Hashes is empty, no matches are
@@ -544,6 +520,14 @@ def prepare_linked_requirement(
544520
req, self.req_tracker, self.finder, self.build_isolation,
545521
)
546522

523+
if download_dir:
524+
if link.is_existing_dir():
525+
logger.info('Link is a directory, ignoring download_dir')
526+
elif local_path and not os.path.exists(
527+
os.path.join(download_dir, link.filename)
528+
):
529+
_copy_file(local_path, download_dir, link)
530+
547531
if self._download_should_save:
548532
# Make a .zip of the source_dir we already created.
549533
if link.is_vcs:

0 commit comments

Comments
 (0)