Skip to content

Commit 327c295

Browse files
committed
Keep path to downloaded archive on InstallRequirement
Now we'll be able to transition other parts of the code to use pre-existing archives directly instead of relying on unpacked sources.
1 parent c565d7a commit 327c295

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/pip/_internal/operations/prepare.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def unpack_http_url(
143143
download_dir=None, # type: Optional[str]
144144
hashes=None, # type: Optional[Hashes]
145145
):
146-
# type: (...) -> None
146+
# type: (...) -> str
147147
temp_dir = TempDirectory(kind="unpack", globally_managed=True)
148148
# If a download dir is specified, is the file already downloaded there?
149149
already_downloaded_path = None
@@ -171,6 +171,8 @@ def unpack_http_url(
171171
):
172172
_copy_file(from_path, download_dir, link)
173173

174+
return from_path
175+
174176

175177
def _copy2_ignoring_special_files(src, dest):
176178
# type: (str, str) -> None
@@ -219,7 +221,7 @@ def unpack_file_url(
219221
download_dir=None, # type: Optional[str]
220222
hashes=None # type: Optional[Hashes]
221223
):
222-
# type: (...) -> None
224+
# type: (...) -> Optional[str]
223225
"""Unpack link into location.
224226
225227
If download_dir is provided and link points to a file, make a copy
@@ -233,7 +235,7 @@ def unpack_file_url(
233235
_copy_source_tree(link_path, location)
234236
if download_dir:
235237
logger.info('Link is a directory, ignoring download_dir')
236-
return
238+
return None
237239

238240
# If --require-hashes is off, `hashes` is either empty, the
239241
# link's embedded hash, or MissingHashes; it is required to
@@ -267,6 +269,8 @@ def unpack_file_url(
267269
):
268270
_copy_file(from_path, download_dir, link)
269271

272+
return from_path
273+
270274

271275
def unpack_url(
272276
link, # type: Link
@@ -275,7 +279,7 @@ def unpack_url(
275279
download_dir=None, # type: Optional[str]
276280
hashes=None, # type: Optional[Hashes]
277281
):
278-
# type: (...) -> None
282+
# type: (...) -> Optional[str]
279283
"""Unpack link.
280284
If link is a VCS link:
281285
if only_download, export into download_dir and ignore location
@@ -293,14 +297,15 @@ def unpack_url(
293297
# non-editable vcs urls
294298
if link.is_vcs:
295299
unpack_vcs_link(link, location)
300+
return None
296301

297302
# file urls
298303
elif link.is_file:
299-
unpack_file_url(link, location, download_dir, hashes=hashes)
304+
return unpack_file_url(link, location, download_dir, hashes=hashes)
300305

301306
# http urls
302307
else:
303-
unpack_http_url(
308+
return unpack_http_url(
304309
link,
305310
location,
306311
downloader,
@@ -500,7 +505,7 @@ def prepare_linked_requirement(
500505
download_dir = self.wheel_download_dir
501506

502507
try:
503-
unpack_url(
508+
local_path = unpack_url(
504509
link, req.source_dir, self.downloader, download_dir,
505510
hashes=hashes,
506511
)
@@ -515,6 +520,11 @@ def prepare_linked_requirement(
515520
'error {} for URL {}'.format(req, exc, link)
516521
)
517522

523+
# For use in later processing, preserve the file path on the
524+
# requirement.
525+
if local_path:
526+
req.local_file_path = local_path
527+
518528
if link.is_wheel:
519529
if download_dir:
520530
# When downloading, we only unpack wheels to get

src/pip/_internal/req/req_install.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ def __init__(
137137
# PEP 508 URL requirement
138138
link = Link(req.url)
139139
self.link = self.original_link = link
140+
# Path to any downloaded or already-existing package.
141+
self.local_file_path = None # type: Optional[str]
142+
if self.link and self.link.is_file:
143+
self.local_file_path = self.link.file_path
140144

141145
if extras:
142146
self.extras = extras

src/pip/_internal/wheel_builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ def build(
460460
)
461461
# Update the link for this.
462462
req.link = Link(path_to_url(wheel_file))
463+
req.local_file_path = req.link.file_path
463464
assert req.link.is_wheel
464465
# extract the wheel into the dir
465466
unpack_file(req.link.file_path, req.source_dir)

0 commit comments

Comments
 (0)