mailr15783 - /1.3/multi/misc.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on April 18, 2012 - 22:25:
Author: bugman
Date: Wed Apr 18 22:25:11 2012
New Revision: 15783

URL: http://svn.gna.org/viewcvs/relax?rev=15783&view=rev
Log:
Prepared the multi-processor package for the import mechanisms of Python 3.

This new mechanism is present in Python 2.7 now, and the code falls back to 
the old method when not
present.


Modified:
    1.3/multi/misc.py

Modified: 1.3/multi/misc.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/multi/misc.py?rev=15783&r1=15782&r2=15783&view=diff
==============================================================================
--- 1.3/multi/misc.py (original)
+++ 1.3/multi/misc.py Wed Apr 18 22:25:11 2012
@@ -28,6 +28,10 @@
 """
 
 # Python module imports.
+try:
+    import importlib
+except:
+    importlib = None
 import sys
 import traceback, textwrap
 
@@ -45,22 +49,30 @@
 
     result = None
 
-    # Import the module.
-    module = __import__(module_path, globals(), locals(), [])
-
-    # Debugging.
-    verbosity = Verbosity()
-    if verbosity.level() > 2:
-        print('loaded module %s' % module_path)
-
-    #FIXME: needs more failure checking
-    if module != None:
-        result = [module]
-        components = module_path.split('.')
-        for component in components[1:]:
-            module = getattr(module, component)
-            result.append(module)
-    return result
+    # Import the module using the new Python 2.7 way.
+    if importlib != None:
+        module = importlib.import_module(module_path)
+
+        # Return the module as a list.
+        return [module]
+
+    # Import the module using the old way.
+    else:
+        module = __import__(module_path, globals(), locals(), [])
+
+        # Debugging.
+        verbosity = Verbosity()
+        if verbosity.level() > 2:
+            print('loaded module %s' % module_path)
+
+        #FIXME: needs more failure checking
+        if module != None:
+            result = [module]
+            components = module_path.split('.')
+            for component in components[1:]:
+                module = getattr(module, component)
+                result.append(module)
+        return result
 
 
 def raise_unimplemented(method):




Related Messages


Powered by MHonArc, Updated Thu Apr 19 00:40:02 2012