Changeset 10817:eafe1ac8ff9d in orange for Orange/__init__.py


Ignore:
Timestamp:
04/19/12 17:18:30 (2 years ago)
Author:
mitar
Branch:
default
Message:

Support for automatic importing of modules from add-ons.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/__init__.py

    r10711 r10817  
    22 
    33__version__ = "2.5a4" 
     4 
     5ADDONS_ENTRY_POINT = 'orange.addons' 
    46 
    57from . import orange 
     
    1315 
    1416import warnings 
     17import pkg_resources 
    1518 
    1619alreadyWarned = False 
     
    2528            UserWarning, 2) 
    2629        alreadyWarned = True 
     30 
     31def _import_addons(): 
     32    globals_dict = globals() 
     33    for entry_point in pkg_resources.iter_entry_points(ADDONS_ENTRY_POINT): 
     34        try: 
     35            module = entry_point.load() 
     36            if '.' not in entry_point.name: 
     37                globals_dict[entry_point.name] = module 
     38            sys.modules['Orange.%s' % (entry_point.name,)] = module 
     39        except ImportError, err: 
     40            warnings.warn("Importing add-on '%s' failed: %s" % (entry_point.name, err), UserWarning, 2) 
    2741 
    2842_import("utils") 
     
    133147_import("utils.render") 
    134148_import("utils.serverfiles") 
    135 # 
     149 
     150_import_addons() 
     151 
    136152try: 
    137153    from . import version 
     
    144160 
    145161del _import 
     162del _import_addons 
    146163del alreadyWarned 
    147164del disabledMsg 
Note: See TracChangeset for help on using the changeset viewer.