From 32b67e3caf25df2a7b1958164aedd70724c5aceb Mon Sep 17 00:00:00 2001 From: wbond Date: Thu, 17 Aug 2023 07:27:34 -0400 Subject: [PATCH] Fix support for Python 3.12 by supporting imp and importlib --- tests/__init__.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/__init__.py b/tests/__init__.py index 88630930..0fd62740 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,10 +1,15 @@ # coding: utf-8 from __future__ import unicode_literals, division, absolute_import, print_function -import imp import os +import sys import unittest +if sys.version_info < (3,): + import imp +else: + import importlib + __version__ = '1.5.1' __version_info__ = (1, 5, 1) @@ -38,8 +43,12 @@ def _import_from(mod, path, mod_dir=None): return None try: - mod_info = imp.find_module(mod_dir, [path]) - return imp.load_module(mod, *mod_info) + if sys.version_info < (3,): + mod_info = imp.find_module(mod_dir, [path]) + return imp.load_module(mod, *mod_info) + else: + mod_info = importlib.machinery.PathFinder().find_spec(mod_dir, [path]) + return importlib.import_module(mod, *mod_info) except ImportError: return None