Skip to content

Commit 77df02f

Browse files
authored
Updating setup.py to work with python 3.12 (#106)
1 parent b1809a0 commit 77df02f

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

setup.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
import imp
1+
try:
2+
from imp import load_source
3+
except ImportError:
4+
import importlib.util
5+
import importlib.machinery
6+
7+
def load_source(modname, filename):
8+
loader = importlib.machinery.SourceFileLoader(modname, filename)
9+
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
10+
module = importlib.util.module_from_spec(spec)
11+
# The module is always executed and not cached in sys.modules.
12+
# Uncomment the following line to cache the module.
13+
# sys.modules[module.__name__] = module
14+
loader.exec_module(module)
15+
return module
16+
17+
218
import os
319

420
try:
@@ -16,8 +32,8 @@
1632
README = ''
1733
CHANGES = ''
1834

19-
# Use imp to avoid sift/__init__.py
20-
version_mod = imp.load_source('__tmp', os.path.join(here, 'sift/version.py'))
35+
# Use imp/importlib to avoid sift/__init__.py
36+
version_mod = load_source('__tmp', os.path.join(here, 'sift/version.py'))
2137

2238
setup(
2339
name='Sift',

0 commit comments

Comments
 (0)