Skip to content

Commit

Permalink
discovery: Ensure back-compatibility
Browse files Browse the repository at this point in the history
Allow clients to pass pkg_resources.Distribution since it was part of
public interface.
  • Loading branch information
ales-erjavec committed Nov 10, 2023
1 parent 904fdea commit 0799ee5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions orangecanvas/registry/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import abc
import os
import sys
import stat
import logging
import types
import pkgutil
Expand All @@ -27,7 +26,7 @@
from . import VERSION_HEX
from . import cache, WidgetRegistry
from . import utils
from ..utils.pkgmeta import entry_points
from ..utils.pkgmeta import entry_points, Distribution

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,6 +71,13 @@ def default_category_for_module(module):
)


def _dist_name(dist: Distribution) -> str:
try:
return dist.name
except AttributeError: # pkg_resources.Distribution
return dist.project_name


class WidgetDiscovery(object):
"""
Base widget discovery runner.
Expand Down Expand Up @@ -213,7 +219,7 @@ def process_category_package(self, category, name=None, distribution=None):
cat_desc.name = default_category_name_for_module(category)

if distribution is not None:
cat_desc.project_name = distribution.project_name
cat_desc.project_name = _dist_name(distribution)

self.handle_category(cat_desc)

Expand Down Expand Up @@ -352,7 +358,7 @@ def widget_description(self, module, widget_name=None,
desc.category = category_name

if distribution is not None:
desc.project_name = distribution.project_name
desc.project_name = _dist_name(distribution)

return desc

Expand All @@ -372,7 +378,7 @@ def cache_insert(self, module, mtime, description, distribution=None,
project_name = project_version = None

if distribution is not None:
project_name = distribution.project_name
project_name = _dist_name(distribution)
project_version = distribution.version

exc_type = exc_val = None
Expand Down Expand Up @@ -415,7 +421,7 @@ def cache_has_valid_entry(self, mod_path, distribution=None):
return False

if distribution is not None:
if entry.project_name != distribution.project_name or \
if entry.project_name != _dist_name(distribution) or \
entry.project_version != distribution.version:
return False

Expand Down

0 comments on commit 0799ee5

Please sign in to comment.