Skip to content

Commit

Permalink
MNT: do not use the deprecated imp module
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tacaswell committed May 1, 2023
1 parent 26f7a9c commit 0588435
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pythran/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from tempfile import mkdtemp, NamedTemporaryFile
import gast as ast
import imp
import importlib
import logging
import os.path
import shutil
Expand Down Expand Up @@ -441,8 +441,11 @@ def import_pythrancode(pythrancode, **kwargs):
tmpfile = None
try:
tmpfile = compile_pythrancode(module_name, pythrancode, **kwargs)
module_description = imp.find_module(module_name, ["."])
return imp.load_module(module_name, *module_description)
spec = importlib.util.spec_from_file_location(module_name, tmpfile)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)
return module
finally:
if tmpfile is not None:
os.remove(tmpfile)
Expand Down

0 comments on commit 0588435

Please sign in to comment.