Ignore:
Timestamp:
05/09/12 17:13:12 (2 years ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Using import instead of imp.load_source (so modules are not reloaded).
Removed adding of module directories to sys.path (widgets are always on
path - added by Orange.utils.addons or setuptools).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/orngRegistry.py

    r10838 r10865  
    136136 
    137137def readWidgets(directory, cachedWidgetDescriptions, prototype=False, silent=False, addOn=None, defaultCategory=None, module=None): 
    138     import sys, imp 
     138    import sys 
    139139    global hasErrors, splashWindow, widgetsWithError, widgetsWithErrorPrototypes 
    140140     
     
    173173            widgets.append((cachedDescription.name, cachedDescription)) 
    174174            continue 
    175          
    176175        if module: 
    177176            data = pkg_resources.resource_string(module.__name__, filename) 
     
    196195                splashWindow.setMask(logo.mask()) 
    197196                splashWindow.show() 
    198                  
     197 
    199198            splashWindow.showMessage("Registering widget %s" % meta.name, Qt.AlignHCenter + Qt.AlignBottom) 
    200199            qApp.processEvents() 
    201              
    202             # We import modules using imp.load_source to avoid storing them in sys.modules, 
    203             # but we need to append the path to sys.path in case the module would want to load 
    204             # something 
    205             if dirname: 
    206                 dirnameInPath = dirname in sys.path 
    207                 if not dirnameInPath: 
    208                     sys.path.append(dirname) 
     200 
    209201            if module: 
    210                 # TODO: We could optimize this probably with loading the module in a way which would not need filename directly 
    211                 wmod = imp.load_source("%s.%s" % (module.__name__, widgname), pkg_resources.resource_filename(module.__name__, filename)) 
    212             else: 
    213                 wmod = imp.load_source(widgname, filename) 
    214             if dirname and not dirnameInPath and dirname in sys.path: # I have no idea, why we need this, but it seems to disappear sometimes?! 
    215                 sys.path.remove(dirname) 
    216             widgClass = wmod.__dict__[widgname] 
     202                import_name = "%s.%s" % (module.__name__, widgname) 
     203            else: 
     204                import_name = widgname 
     205            wmod = __import__(import_name, fromlist=[""]) 
     206 
     207            wmodFilename = wmod.__file__ 
     208            if os.path.splitext(wmodFilename)[1] != "py": 
     209                # Replace .pyc, .pyo with bare .py extension 
     210                # (used as key in cachedWidgetDescription) 
     211                wmodFilename = os.path.splitext(wmodFilename)[0] + ".py" 
    217212 
    218213            # Evaluate the input/output list (all tuple items are strings) 
     
    241236 
    242237            widgetInfo = WidgetDescription( 
    243                              name =meta.name, 
     238                             name = meta.name, 
    244239                             time = datetime, 
    245240                             fileName = widgname, 
    246241                             module = module.__name__ if module else None, 
    247                              fullName = wmod.__file__, 
     242                             fullName = wmodFilename, 
    248243                             directory = directory, 
    249244                             addOn = addOn, 
Note: See TracChangeset for help on using the changeset viewer.