summaryrefslogtreecommitdiff
path: root/setuptools/command/build_ext.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/command/build_ext.py')
-rw-r--r--setuptools/command/build_ext.py24
1 files changed, 8 insertions, 16 deletions
diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py
index 03b6f346..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)]
@@ -254,7 +242,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, importlib.util" +
+ if_dl(", dl"),
" __file__ = pkg_resources.resource_filename"
"(__name__,%r)"
% os.path.basename(ext._file_name),
@@ -266,7 +255,10 @@ class build_ext(_build_ext):
" try:",
" os.chdir(os.path.dirname(__file__))",
if_dl(" sys.setdlopenflags(dl.RTLD_NOW)"),
- " imp.load_dynamic(__name__,__file__)",
+ " 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)",