]> git.phdru.name Git - cookiecutter.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:39:57 +0000 (16:39 +0300)
committerOleg Broytman <phd@phdru.name>
Thu, 7 Feb 2019 13:39:57 +0000 (16:39 +0300)
project_template/setup.py

index 2ca49ae7358659578027b365a3afabbd58715527..8297efa6656c7c47a32c9c8d2f7051cf30a50c83 100755 (executable)
@@ -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("{project} requires Python 2.7 or 3.4+")
 
 versionpath = join(abspath(dirname(__file__)), '{project}', '__version__.py')
 {project}_version = load_source('{project}_version', versionpath)