Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax VenvInspectInformation attribute typing #1087

Merged
merged 5 commits into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/pipx/venv_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import textwrap
from pathlib import Path
from typing import Dict, List, NamedTuple, Optional, Set, Tuple
from typing import Collection, Dict, List, NamedTuple, Optional, Set, Tuple

from packaging.requirements import Requirement
from packaging.utils import canonicalize_name
Expand All @@ -19,7 +19,7 @@


class VenvInspectInformation(NamedTuple):
distributions: List[metadata.Distribution]
distributions: Collection[metadata.Distribution]
env: Dict[str, str]
bin_path: Path

Expand All @@ -34,7 +34,7 @@ class VenvMetadata(NamedTuple):


def get_dist(
package: str, distributions: List[metadata.Distribution]
package: str, distributions: Collection[metadata.Distribution]
) -> Optional[metadata.Distribution]:
"""Find matching distribution in the canonicalized sense."""
for dist in distributions:
Expand Down Expand Up @@ -237,10 +237,16 @@ def inspect_venv(
venv_python_path
)

# Collect the generator created from metadata.distributions()
# (see `itertools.chain.from_iterable`) into a tuple because we
# need to iterate over it multiple times in `_dfs_package_apps`.

# Tuple is chosen over a list because the program only iterate over
# the distributions and never modify it.
distributions = tuple(metadata.distributions(path=venv_sys_path))

venv_inspect_info = VenvInspectInformation(
bin_path=venv_bin_path,
env=venv_env,
distributions=list(metadata.distributions(path=venv_sys_path)),
bin_path=venv_bin_path, env=venv_env, distributions=distributions
)

root_dist = get_dist(root_req.name, venv_inspect_info.distributions)
Expand Down