From 873ffdb61eb461b4c71ab7e12151864b49a23f3a Mon Sep 17 00:00:00 2001 From: cerenkov Date: Sun, 19 May 2024 00:58:08 +0800 Subject: [PATCH] Update setup.py: compatibility for older python versions --- setup.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/setup.py b/setup.py index 470c99ed..ea984671 100755 --- a/setup.py +++ b/setup.py @@ -5,18 +5,21 @@ PACKAGE_NAME = 'you_get' PROJ_METADATA = '%s.json' % PROJ_NAME -import importlib.util -import importlib.machinery - -def load_source(modname, filename): - loader = importlib.machinery.SourceFileLoader(modname, filename) - spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) - module = importlib.util.module_from_spec(spec) - # The module is always executed and not cached in sys.modules. - # Uncomment the following line to cache the module. - # sys.modules[module.__name__] = module - loader.exec_module(module) - return module +import sys +if (sys.version_info >= (3, 12)): + import importlib.util + import importlib.machinery + def load_source(modname, filename): + loader = importlib.machinery.SourceFileLoader(modname, filename) + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) + module = importlib.util.module_from_spec(spec) + # The module is always executed and not cached in sys.modules. + # Uncomment the following line to cache the module. + # sys.modules[module.__name__] = module + loader.exec_module(module) + return module +else: + from imp import load_source import os, json here = os.path.abspath(os.path.dirname(__file__))