Commit 2a55538a authored by Jason R. Coombs's avatar Jason R. Coombs Committed by GitHub

Merge pull request #2071 from alexhenrie/imp

Use importlib instead of imp in __bootstrap__ functions
parents 145a78cd 4516d870
Replaced references to the deprecated imp package with references to importlib
...@@ -55,10 +55,11 @@ def write_stub(resource, pyfile): ...@@ -55,10 +55,11 @@ def write_stub(resource, pyfile):
_stub_template = textwrap.dedent(""" _stub_template = textwrap.dedent("""
def __bootstrap__(): def __bootstrap__():
global __bootstrap__, __loader__, __file__ global __bootstrap__, __loader__, __file__
import sys, pkg_resources, imp import sys, pkg_resources
from importlib.machinery import ExtensionFileLoader
__file__ = pkg_resources.resource_filename(__name__, %r) __file__ = pkg_resources.resource_filename(__name__, %r)
__loader__ = None; del __bootstrap__, __loader__ __loader__ = None; del __bootstrap__, __loader__
imp.load_dynamic(__name__,__file__) ExtensionFileLoader(__name__,__file__).exec_module()
__bootstrap__() __bootstrap__()
""").lstrip() """).lstrip()
with open(pyfile, 'w') as f: with open(pyfile, 'w') as f:
......
...@@ -254,7 +254,8 @@ class build_ext(_build_ext): ...@@ -254,7 +254,8 @@ class build_ext(_build_ext):
'\n'.join([ '\n'.join([
"def __bootstrap__():", "def __bootstrap__():",
" global __bootstrap__, __file__, __loader__", " global __bootstrap__, __file__, __loader__",
" import sys, os, pkg_resources, imp" + if_dl(", dl"), " import sys, os, pkg_resources" + if_dl(", dl"),
" from importlib.machinery import ExtensionFileLoader",
" __file__ = pkg_resources.resource_filename" " __file__ = pkg_resources.resource_filename"
"(__name__,%r)" "(__name__,%r)"
% os.path.basename(ext._file_name), % os.path.basename(ext._file_name),
...@@ -266,7 +267,8 @@ class build_ext(_build_ext): ...@@ -266,7 +267,8 @@ class build_ext(_build_ext):
" try:", " try:",
" os.chdir(os.path.dirname(__file__))", " os.chdir(os.path.dirname(__file__))",
if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"), if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"),
" imp.load_dynamic(__name__,__file__)", " ExtensionFileLoader(__name__,",
" __file__).exec_module()",
" finally:", " finally:",
if_dl(" sys.setdlopenflags(old_flags)"), if_dl(" sys.setdlopenflags(old_flags)"),
" os.chdir(old_dir)", " os.chdir(old_dir)",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment