From 4516d87036f971a4c98900301b6354c0aae73dc8 Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Sun, 21 Jun 2020 16:39:53 -0600 Subject: Use importlib instead of imp in __bootstrap__ functions --- setuptools/command/build_ext.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'setuptools/command/build_ext.py') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 03b6f346..327fa063 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -254,7 +254,8 @@ class build_ext(_build_ext): '\n'.join([ "def __bootstrap__():", " 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" "(__name__,%r)" % os.path.basename(ext._file_name), @@ -266,7 +267,8 @@ class build_ext(_build_ext): " try:", " os.chdir(os.path.dirname(__file__))", if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"), - " imp.load_dynamic(__name__,__file__)", + " ExtensionFileLoader(__name__,", + " __file__).exec_module()", " finally:", if_dl(" sys.setdlopenflags(old_flags)"), " os.chdir(old_dir)", -- cgit v1.2.1 From 8b4ce333c093f459698c0545550269a393387c5f Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Sat, 11 Jul 2020 12:51:48 -0600 Subject: Change exec_module to load_module Fixes #2246 --- setuptools/command/build_ext.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'setuptools/command/build_ext.py') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 327fa063..0eb29adc 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -268,7 +268,7 @@ class build_ext(_build_ext): " os.chdir(os.path.dirname(__file__))", if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"), " ExtensionFileLoader(__name__,", - " __file__).exec_module()", + " __file__).load_module()", " finally:", if_dl(" sys.setdlopenflags(old_flags)"), " os.chdir(old_dir)", -- cgit v1.2.1 From 33c9d86af4dc1df04cf1b38a0102fe7e121173ec Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 10 Aug 2020 21:10:46 +1000 Subject: Change load_module to exec_module --- setuptools/command/build_ext.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'setuptools/command/build_ext.py') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 0eb29adc..89a0e328 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -254,8 +254,8 @@ class build_ext(_build_ext): '\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), @@ -267,8 +267,10 @@ class build_ext(_build_ext): " 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)", -- cgit v1.2.1 From fb7ab81a3d080422687bad71f9ae9d36eeefbee2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 16 Aug 2020 00:29:24 -0400 Subject: Remove Python 2 compatibility --- setuptools/command/build_ext.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'setuptools/command/build_ext.py') diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py index 89a0e328..03a72b4f 100644 --- a/setuptools/command/build_ext.py +++ b/setuptools/command/build_ext.py @@ -1,6 +1,7 @@ import os import sys import itertools +from importlib.machinery import EXTENSION_SUFFIXES from distutils.command.build_ext import build_ext as _du_build_ext from distutils.file_util import copy_file from distutils.ccompiler import new_compiler @@ -9,15 +10,6 @@ from distutils.errors import DistutilsError from distutils import log from setuptools.extension import Library -from setuptools.extern import six - -if six.PY2: - import imp - - EXTENSION_SUFFIXES = [ - s for s, _, tp in imp.get_suffixes() if tp == imp.C_EXTENSION] -else: - from importlib.machinery import EXTENSION_SUFFIXES try: # Attempt to use Cython for building extensions, if available @@ -115,11 +107,7 @@ class build_ext(_build_ext): filename = _build_ext.get_ext_filename(self, fullname) if fullname in self.ext_map: ext = self.ext_map[fullname] - use_abi3 = ( - not six.PY2 - and getattr(ext, 'py_limited_api') - and get_abi3_suffix() - ) + use_abi3 = getattr(ext, 'py_limited_api') and get_abi3_suffix() if use_abi3: so_ext = get_config_var('EXT_SUFFIX') filename = filename[:-len(so_ext)] -- cgit v1.2.1