Skip to content

Commit 0588435

Browse files
committed
MNT: do not use the deprecated imp module
The `imp` module has been deprecated from py3.4 [1] and will be removed in py3.12 [2]. This patch is required to use pythran on the current main branch of Python. [1] https://docs.python.org/3.11/library/imp.html?highlight=imp#module-imp [2] python/cpython#98573
1 parent 26f7a9c commit 0588435

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pythran/toolchain.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
from tempfile import mkdtemp, NamedTemporaryFile
3535
import gast as ast
36-
import imp
36+
import importlib
3737
import logging
3838
import os.path
3939
import shutil
@@ -441,8 +441,11 @@ def import_pythrancode(pythrancode, **kwargs):
441441
tmpfile = None
442442
try:
443443
tmpfile = compile_pythrancode(module_name, pythrancode, **kwargs)
444-
module_description = imp.find_module(module_name, ["."])
445-
return imp.load_module(module_name, *module_description)
444+
spec = importlib.util.spec_from_file_location(module_name, tmpfile)
445+
module = importlib.util.module_from_spec(spec)
446+
sys.modules[module_name] = module
447+
spec.loader.exec_module(module)
448+
return module
446449
finally:
447450
if tmpfile is not None:
448451
os.remove(tmpfile)

0 commit comments

Comments
 (0)