Skip to content

Commit 493bba8

Browse files
Fix linting issues and update news file
- Fix line length issues in _envs.py docstrings - Fix mypy return type error for _iter_meta_path_distributions - Remove debug print statements from factory.py - Update news file to include meta_path finder support - All linting checks now pass
1 parent 5baac08 commit 493bba8

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Optimize dependency resolution performance by caching parsed dependencies and extras to avoid redundant parsing operations during candidate evaluation.
1+
Optimize dependency resolution performance by caching parsed dependencies and extras to avoid redundant parsing operations during candidate evaluation. Also add support for discovering distributions from sys.meta_path finders to enable in-memory package installations.

src/pip/_internal/metadata/importlib/_envs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _find_impl(self, location: str) -> Iterator[FoundResult]:
7777
yield dist, info_location
7878

7979
def find_meta_path_distributions(self) -> Iterator[FoundResult]:
80-
"""Find distributions from sys.meta_path finders (e.g., in-memory distributions)."""
80+
"""Find distributions from sys.meta_path finders."""
8181
try:
8282
# Get all distributions without specifying a path, which includes
8383
# distributions from sys.meta_path finders
@@ -154,13 +154,15 @@ def _iter_distributions(self) -> Iterator[BaseDistribution]:
154154
for location in self._paths:
155155
yield from finder.find(location)
156156
yield from finder.find_legacy_editables(location)
157-
158-
# Also check for distributions from sys.meta_path finders (e.g., in-memory distributions)
157+
158+
# Also check for distributions from sys.meta_path finders
159159
# This is backwards compatible - if no custom finders exist, this does nothing
160160
yield from self._iter_meta_path_distributions(finder)
161161

162-
def _iter_meta_path_distributions(self, finder: _DistributionFinder) -> None:
163-
"""Yield distributions from sys.meta_path finders (e.g., in-memory distributions)."""
162+
def _iter_meta_path_distributions(
163+
self, finder: _DistributionFinder
164+
) -> Iterator[Distribution]:
165+
"""Yield distributions from sys.meta_path finders."""
164166
for dist, info_location in finder.find_meta_path_distributions():
165167
if info_location is None:
166168
installed_location: BasePath | None = None

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,26 +281,22 @@ def _get_installed_candidate() -> Candidate | None:
281281
try:
282282
# Don't use the installed distribution if its version
283283
# does not fit the current dependency graph.
284-
version_check = specifier.contains(installed_dist.version, prereleases=True)
285-
print(f"DEBUG: specifier {specifier} contains {installed_dist.version} = {version_check}")
284+
version_check = specifier.contains(
285+
installed_dist.version, prereleases=True
286+
)
286287
if not version_check:
287-
print(f"DEBUG: Returning None due to version specifier mismatch")
288288
return None
289289
except InvalidVersion as e:
290-
print(f"DEBUG: InvalidVersion error: {e}")
291290
raise InvalidInstalledPackage(dist=installed_dist, invalid_exc=e)
292291

293292
candidate = self._make_candidate_from_dist(
294293
dist=installed_dist,
295294
extras=extras,
296295
template=template,
297296
)
298-
print(f"DEBUG: Created candidate = {candidate}")
299297
# The candidate is a known incompatibility. Don't use it.
300298
if id(candidate) in incompatible_ids:
301-
print(f"DEBUG: Returning None due to incompatible candidate")
302299
return None
303-
print(f"DEBUG: Returning candidate = {candidate}")
304300
return candidate
305301

306302
def iter_index_candidate_infos() -> Iterator[IndexCandidateInfo]:

tests/functional/test_install.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2586,7 +2586,7 @@ def find_distributions(self, context=None):
25862586
custom_module_path = script.site_packages_path / "setup_custom_finder.py"
25872587
with open(custom_module_path, "w") as f:
25882588
f.write(sitecustomize_text)
2589-
2589+
25902590
# Create a .pth file that imports our module
25912591
pth_content = "import setup_custom_finder"
25922592
pth_file = script.site_packages_path / "setup_custom_finder.pth"

0 commit comments

Comments
 (0)