Changeset 10892:0baeb90e4e08 in orange for Orange/__init__.py


Ignore:
Timestamp:
05/25/12 19:31:09 (2 years ago)
Author:
mitar
Branch:
default
Message:

Enable loading add-ons deeper into the Orange namespace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/__init__.py

    r10889 r10892  
    4040        try: 
    4141            module = entry_point.load() 
    42             if '.' not in entry_point.name: 
    43                 globals_dict[entry_point.name] = module 
    44             sys.modules['Orange.%s' % (entry_point.name,)] = module 
     42            # Dot is not allowed in an entry point name (it should 
     43            # be a Python identifier, because it is used as a class 
     44            # name), so we are using __ instead 
     45            name = entry_point.name.replace('__', '.') 
     46            if '.' not in name: 
     47                globals_dict[name] = module 
     48            else: 
     49                path, mod = name.rsplit('.', 1) 
     50                parent_module = sys.modules['Orange.%s' % (path,)] 
     51                setattr(parent_module, mod, module) 
     52            sys.modules['Orange.%s' % (name,)] = module 
    4553        except ImportError, err: 
    4654            warnings.warn("Importing add-on '%s' failed: %s" % (entry_point.name, err), UserWarning, 2) 
     
    4856            warnings.warn("Loading add-on '%s' failed because of a missing dependency: '%s'" % (entry_point.name, err), UserWarning, 2) 
    4957        except Exception, err: 
    50             warning.warn("An exception occurred during the loading of '%s':\n%r" %(entry_point.name, err), UserWarning, 2) 
     58            warnings.warn("An exception occurred during the loading of '%s':\n%r" %(entry_point.name, err), UserWarning, 2) 
    5159 
    5260 
Note: See TracChangeset for help on using the changeset viewer.