Skip to content

Commit

Permalink
Fix support for Python 3.12 by supporting imp and importlib
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Aug 17, 2023
1 parent 5addf14 commit 32b67e3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 32b67e3

Please sign in to comment.