swc-installation-test-2.py: Add import_module for older Pythons
authorW. Trevor King <wking@tremily.us>
Sun, 30 Dec 2012 17:57:49 +0000 (12:57 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 1 Jan 2013 14:49:47 +0000 (09:49 -0500)
importlib is new in Python 2.7 / 3.1.  Add a minimal workaround for
earlier versions.

swc-installation-test-2.py

index 69ef169bc20b3a3de20100f5214fa2ac9279d49c..0617550f64f8e0ecd1f41f30d8a3c7f9310ae8c7 100755 (executable)
@@ -25,7 +25,19 @@ of Python that you have installed with 'swc-installation-test-1.py'.
 from __future__ import print_function  # for Python 2.6 compatibility
 
 import distutils.ccompiler as _distutils_ccompiler
-import importlib as _importlib
+try:  # Python 2.7 and 3.x
+    import importlib as _importlib
+except ImportError:  # Python 2.6 and earlier
+    class _Importlib (object):
+        """Minimal workarounds for functions we need
+        """
+        @staticmethod
+        def import_module(name):
+            module = __import__(name)
+            for n in name.split('.')[1:]:
+                module = getattr(module, n)
+            return module
+    _importlib = _Importlib()
 import logging as _logging
 import os as _os
 import platform as _platform