Skip to content

Commit

Permalink
Merge pull request #2297 from radarhere/master
Browse files Browse the repository at this point in the history
Change load_module to exec_module
  • Loading branch information
jaraco committed Aug 12, 2020
2 parents 7fbca8c + 3af54b4 commit 6224065
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/2297.misc.rst
@@ -0,0 +1 @@
Once again, in stubs prefer exec_module to the deprecated load_module.
7 changes: 4 additions & 3 deletions setuptools/command/bdist_egg.py
Expand Up @@ -55,11 +55,12 @@ def write_stub(resource, pyfile):
_stub_template = textwrap.dedent("""
def __bootstrap__():
global __bootstrap__, __loader__, __file__
import sys, pkg_resources
from importlib.machinery import ExtensionFileLoader
import sys, pkg_resources, importlib.util
__file__ = pkg_resources.resource_filename(__name__, %r)
__loader__ = None; del __bootstrap__, __loader__
ExtensionFileLoader(__name__,__file__).load_module()
spec = importlib.util.spec_from_file_location(__name__,__file__)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
__bootstrap__()
""").lstrip()
with open(pyfile, 'w') as f:
Expand Down
10 changes: 6 additions & 4 deletions setuptools/command/build_ext.py
Expand Up @@ -254,8 +254,8 @@ def write_stub(self, output_dir, ext, compile=False):
'\n'.join([
"def __bootstrap__():",
" global __bootstrap__, __file__, __loader__",
" import sys, os, pkg_resources" + if_dl(", dl"),
" from importlib.machinery import ExtensionFileLoader",
" import sys, os, pkg_resources, importlib.util" +
if_dl(", dl"),
" __file__ = pkg_resources.resource_filename"
"(__name__,%r)"
% os.path.basename(ext._file_name),
Expand All @@ -267,8 +267,10 @@ def write_stub(self, output_dir, ext, compile=False):
" try:",
" os.chdir(os.path.dirname(__file__))",
if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"),
" ExtensionFileLoader(__name__,",
" __file__).load_module()",
" spec = importlib.util.spec_from_file_location(",
" __name__, __file__)",
" mod = importlib.util.module_from_spec(spec)",
" spec.loader.exec_module(mod)",
" finally:",
if_dl(" sys.setdlopenflags(old_flags)"),
" os.chdir(old_dir)",
Expand Down

0 comments on commit 6224065

Please sign in to comment.