Skip to content

Commit 1dbaf48

Browse files
morottirmmancomichard26
authored
When extracting a wheel, do not recheck parent directories (#12782)
Co-authored-by: rmorotti <[email protected]> Co-authored-by: Richard Si <[email protected]>
1 parent bf0e5f2 commit 1dbaf48

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

news/12782.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve pip install performance by only creating required parent
2+
directories once, instead of before extracting every file in the wheel.

src/pip/_internal/operations/install/wheel.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,6 @@ def _getinfo(self) -> ZipInfo:
358358
return self._zip_file.getinfo(self.src_record_path)
359359

360360
def save(self) -> None:
361-
# directory creation is lazy and after file filtering
362-
# to ensure we don't install empty dirs; empty dirs can't be
363-
# uninstalled.
364-
parent_dir = os.path.dirname(self.dest_path)
365-
ensure_dir(parent_dir)
366-
367361
# When we open the output file below, any existing file is truncated
368362
# before we start writing the new contents. This is fine in most
369363
# cases, but can cause a segfault if pip has loaded a shared
@@ -421,7 +415,7 @@ def make(
421415
return super().make(specification, options)
422416

423417

424-
def _install_wheel(
418+
def _install_wheel( # noqa: C901, PLR0915 function is too long
425419
name: str,
426420
wheel_zip: ZipFile,
427421
wheel_path: str,
@@ -580,7 +574,15 @@ def is_entrypoint_wrapper(file: "File") -> bool:
580574
script_scheme_files = map(ScriptFile, script_scheme_files)
581575
files = chain(files, script_scheme_files)
582576

577+
existing_parents = set()
583578
for file in files:
579+
# directory creation is lazy and after file filtering
580+
# to ensure we don't install empty dirs; empty dirs can't be
581+
# uninstalled.
582+
parent_dir = os.path.dirname(file.dest_path)
583+
if parent_dir not in existing_parents:
584+
ensure_dir(parent_dir)
585+
existing_parents.add(parent_dir)
584586
file.save()
585587
record_installed(file.src_record_path, file.dest_path, file.changed)
586588

0 commit comments

Comments
 (0)