Skip to content

Commit

Permalink
fix duplication issue in packages_distributions (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
thrau authored Jul 29, 2024
1 parent 8a5b759 commit ddf2a28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion plux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

name = "plux"

__version__ = "1.11.0"
__version__ = "1.11.1"

__all__ = [
"FunctionPlugin",
Expand Down
19 changes: 15 additions & 4 deletions plux/runtime/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import collections
import importlib.metadata
import inspect
import io
import os
Expand Down Expand Up @@ -34,12 +33,24 @@ def metadata_packages_distributions() -> t.Mapping[str, t.List[str]]:
@lru_cache()
def packages_distributions() -> t.Mapping[str, t.List[str]]:
"""
Cache wrapper around metadata.packages_distributions, which returns a mapping of top-level packages to
their distributions.
Cache wrapper around ``metadata.packages_distributions``, which returns a mapping of top-level packages to
their distributions. This index is created by scanning all ``top_level.txt`` metadata files in the path.
Unlike ``metadata.packages_distributions``, this implementation will contain a de-duplicated list of
distribution names per package. With editable installs, ``packages_distributions()`` may return the
distribution metadata for both the ``.egg-info`` in the linked source directory, and the ``.dist-info``
in the site-packages directory created by the editable install. Therefore, a distribution name may
appear twice for the same package, which is unhelpful information, so we deduplicate it here.
:return: package to distribution mapping
"""
return metadata_packages_distributions()
distributions = dict(metadata_packages_distributions())

for k in distributions.keys():
# remove duplicates occurrences of the same distribution name
distributions[k] = list(set(distributions[k]))

return distributions


def resolve_distribution_information(plugin_spec: PluginSpec) -> t.Optional[Distribution]:
Expand Down

0 comments on commit ddf2a28

Please sign in to comment.