Skip to content

Commit 5190ef7

Browse files
authored
Merge pull request #12080 from mauritsvanrees/maurits-issue-12079-slow-importlib
2 parents 8a1eea4 + 6aef932 commit 5190ef7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

news/12079.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix slowness when using ``importlib.metadata`` (the default way for pip to read metadata in Python 3.11+) and there is a large overlap between already installed and to-be-installed packages.

src/pip/_internal/resolution/resolvelib/candidates.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def __init__(
341341
self.dist = dist
342342
self._ireq = _make_install_req_from_dist(dist, template)
343343
self._factory = factory
344+
self._version = None
344345

345346
# This is just logging some messages, so we can do it eagerly.
346347
# The returned dist would be exactly the same as self.dist because we
@@ -376,7 +377,9 @@ def name(self) -> str:
376377

377378
@property
378379
def version(self) -> CandidateVersion:
379-
return self.dist.version
380+
if self._version is None:
381+
self._version = self.dist.version
382+
return self._version
380383

381384
@property
382385
def is_editable(self) -> bool:

0 commit comments

Comments
 (0)