Ignore:
Timestamp:
01/25/13 17:42:19 (15 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Changed discovery to run from arbitrary entry points iterator/group.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/registry/discovery.py

    r11282 r11285  
    99import glob 
    1010import logging 
    11 import itertools 
    1211import types 
    1312import pkgutil 
     
    2120 
    2221from . import VERSION_HEX 
    23  
     22from . import cache, WidgetRegistry 
    2423 
    2524log = logging.getLogger(__name__) 
     
    5352 
    5453 
    55 WIDGETS_ENTRY = "orange.widgets" 
    56  
    57  
    58 # This could also be achieved by declaring the entry point in 
    59 # Orange's setup.py 
    60 def default_entry_point(): 
    61     """Return a default orange.widgets entry point for loading 
    62     default Orange Widgets. 
    63  
    64     """ 
    65     dist = pkg_resources.get_distribution("Orange") 
    66     ep = pkg_resources.EntryPoint("Orange Widgets", "Orange.OrangeWidgets", 
    67                                   dist=dist) 
    68     return ep 
    69  
    70  
    71 def widgets_entry_points(): 
    72     """Return an EntryPoint iterator for all 'orange.widget' entry 
    73     points including the default Orange Widgets. 
    74  
    75     """ 
    76     ep_iter = pkg_resources.iter_entry_points(WIDGETS_ENTRY) 
    77     chain = [[default_entry_point()], 
    78              ep_iter 
    79              ] 
    80     return itertools.chain(*chain) 
    81  
    82  
    8354class WidgetDiscovery(object): 
    84     """Base widget discovery runner. 
     55    """ 
     56    Base widget discovery runner. 
    8557    """ 
    8658 
     
    9365            self.cached_descriptions["!VERSION"] = version 
    9466 
    95     def run(self): 
    96         """Run the widget discovery process. 
    97         """ 
    98         for entry_point in widgets_entry_points(): 
     67    def run(self, entry_points_iter): 
     68        """ 
     69        Run the widget discovery process from an entry point iterator 
     70        (yielding :class:`pkg_resources.EntryPoint` instances). 
     71 
     72        """ 
     73        if isinstance(entry_points_iter, basestring): 
     74            entry_points_iter = \ 
     75                pkg_resources.iter_entry_points(entry_points_iter) 
     76 
     77        for entry_point in entry_points_iter: 
    9978            try: 
    10079                point = entry_point.load() 
    10180            except pkg_resources.DistributionNotFound: 
    102                 log.error("Could not load %r (unsatisfied dependencies).", 
    103                           entry_point.name, exc_info=True) 
     81                log.error("Could not load '%s' (unsatisfied dependencies).", 
     82                          entry_point, exc_info=True) 
    10483                continue 
    10584            except ImportError: 
    106                 log.error("An ImportError occurred while loading an " 
    107                           "entry point", exc_info=True) 
     85                log.error("An ImportError occurred while loading " 
     86                          "entry point '%s'", entry_point, exc_info=True) 
    10887                continue 
    10988            except Exception: 
    110                 log.error("An exception occurred while loading an " 
    111                           "entry point", exc_info=True) 
     89                log.error("An exception occurred while loading " 
     90                          "entry point '%s'", entry_point, exc_info=True) 
    11291                continue 
    11392 
     
    557536 
    558537 
    559 def run_discovery(cached=False): 
    560     """Run the default widget discovery and return the WidgetRegisty 
     538def run_discovery(entry_point, cached=False): 
     539    """ 
     540    Run the default widget discovery and return a :class:`WidgetRegistry` 
    561541    instance. 
    562542 
    563543    """ 
    564     from . import cache, WidgetRegistry 
    565544    reg_cache = {} 
    566545    if cached: 
Note: See TracChangeset for help on using the changeset viewer.