Skip to content

Commit b28e2c4

Browse files
committed
New resolver: Avoid polluting dest dir
Previously, during dependency resolution for `pip download -d <dir>` or `pip wheel -w <dir>`, distributions downloaded are always saved to <dir>, even for those are only used in backtracking and are not part of the returned requirement set.
1 parent 6887b07 commit b28e2c4

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

news/8827.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Avoid polluting the destination directory by resolution artifacts
2+
when the new resolver is used for ``pip download`` or ``pip wheel``.

src/pip/_internal/commands/download.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def run(self, options, args):
137137
for req in requirement_set.requirements.values():
138138
if not req.editable and req.satisfied_by is None:
139139
assert req.name is not None
140+
preparer.save_linked_requirement(req)
140141
downloaded.append(req.name)
141142
if downloaded:
142143
write_output('Successfully downloaded %s', ' '.join(downloaded))

src/pip/_internal/commands/wheel.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from optparse import Values
2222
from typing import List
2323

24+
from pip._internal.req.req_install import InstallRequirement
2425

2526
logger = logging.getLogger(__name__)
2627

@@ -156,10 +157,12 @@ def run(self, options, args):
156157
reqs, check_supported_wheels=True
157158
)
158159

159-
reqs_to_build = [
160-
r for r in requirement_set.requirements.values()
161-
if should_build_for_wheel_command(r)
162-
]
160+
reqs_to_build = [] # type: List[InstallRequirement]
161+
for req in requirement_set.requirements.values():
162+
if req.is_wheel:
163+
preparer.save_linked_requirement(req)
164+
elif should_build_for_wheel_command(req):
165+
reqs_to_build.append(req)
163166

164167
# build wheels
165168
build_successes, build_failures = build(

src/pip/_internal/operations/prepare.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -523,23 +523,33 @@ def _prepare_linked_requirement(self, req, parallel_builds):
523523
dist = _get_prepared_distribution(
524524
req, self.req_tracker, self.finder, self.build_isolation,
525525
)
526+
return dist
526527

527-
if self.download_dir is not None:
528-
if link.is_existing_dir():
529-
logger.info('Link is a directory, ignoring download_dir')
530-
elif local_file:
531-
download_location = os.path.join(
532-
self.download_dir, link.filename
533-
)
534-
if not os.path.exists(download_location):
535-
shutil.copy(local_file.path, download_location)
536-
download_path = display_path(download_location)
537-
logger.info('Saved %s', download_path)
538-
528+
def save_linked_requirement(self, req):
529+
# type: (InstallRequirement) -> None
530+
assert self.download_dir is not None
531+
assert req.link is not None
532+
link = req.link
539533
if link.is_vcs:
540534
# Make a .zip of the source_dir we already created.
541535
req.archive(self.download_dir)
542-
return dist
536+
return
537+
538+
if link.is_existing_dir():
539+
logger.debug(
540+
'Not copying link to destination directory '
541+
'since it is a directory: %s', link,
542+
)
543+
return
544+
if req.local_file_path is None:
545+
# No distribution was downloaded for this requirement.
546+
return
547+
548+
download_location = os.path.join(self.download_dir, link.filename)
549+
if not os.path.exists(download_location):
550+
shutil.copy(req.local_file_path, download_location)
551+
download_path = display_path(download_location)
552+
logger.info('Saved %s', download_path)
543553

544554
def prepare_editable_requirement(
545555
self,

0 commit comments

Comments
 (0)