]> git.phdru.name Git - m_librarian.git/commitdiff
Build(setup.py): Use `importlib` instead of deprecated `imp` for Python 3.4+
authorOleg Broytman <phd@phdru.name>
Thu, 7 Feb 2019 13:43:01 +0000 (16:43 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 7 Feb 2019 13:43:01 +0000 (16:43 +0300)
setup.py

index f6779b1eeea5e0fc44c0fd9dce8fe57c5784d35b..c423eee02c0167670a462e01e279ae837bb4f41a 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,24 @@
 #!/usr/bin/env python
 
-from imp import load_source
 from os.path import abspath, dirname, join
 from setuptools import setup
+import sys
+
+if sys.version_info[:2] == (2, 7):
+    from imp import load_source
+
+elif sys.version_info >= (3, 4):
+    from importlib.machinery import SourceFileLoader
+    import types
+
+    def load_source(fullname, path):
+        loader = SourceFileLoader(fullname, path)
+        loaded = types.ModuleType(loader.name)
+        loader.exec_module(loaded)
+        return loaded
+
+else:
+    raise ImportError("m_librarian requires Python 2.7 or 3.4+")
 
 versionpath = join(abspath(dirname(__file__)), 'm_librarian', '__version__.py')
 m_librarian_version = load_source('m_librarian_version', versionpath)