Skip to content

Commit

Permalink
Relax VenvInspectInformation attribute typing (#1087)
Browse files Browse the repository at this point in the history
Thanks!
  • Loading branch information
aanghelidi authored Oct 20, 2023
1 parent ac64740 commit 1dfd295
Showing 1 changed file with 12 additions and 6 deletions.
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

0 comments on commit 1dfd295

Please sign in to comment.