From: Oleg Broytman Date: Thu, 7 Feb 2019 13:42:40 +0000 (+0300) Subject: Build(setup.py): Use `importlib` instead of deprecated `imp` for Python 3.4+ X-Git-Tag: 3.1.0~18 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=2669a8358e1364311bfbcba500f1b19a5aa2c491;p=mimedecode.git Build(setup.py): Use `importlib` instead of deprecated `imp` for Python 3.4+ --- diff --git a/setup.py b/setup.py index 6ca31b8..6c7aa1c 100755 --- 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("mimedecode requires Python 2.7 or 3.4+") versionpath = join(abspath(dirname(__file__)), "mimedecode", "__version__.py") mimedecode_version = load_source("mimedecode_version", versionpath)