aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2019-08-17 21:41:39 +0000
committerGitHub <noreply@github.com>2019-08-17 21:41:39 +0000
commit2cd2fdcb69426de4bb9d63d638244f4ae6a1ca27 (patch)
tree7eb76398792eafeb4e0a675ec1a7094efa3c1e3f
parent05f42a2c14275937250c99478c94b20171d14aeb (diff)
parenteb7436b36f9967d1becd2b822da548bd59b35d05 (diff)
downloadexternal_python_setuptools-2cd2fdcb69426de4bb9d63d638244f4ae6a1ca27.tar.gz
external_python_setuptools-2cd2fdcb69426de4bb9d63d638244f4ae6a1ca27.tar.bz2
external_python_setuptools-2cd2fdcb69426de4bb9d63d638244f4ae6a1ca27.zip
Merge pull request #1798 from asottile/some_imp
Fix some usage of deprecated `imp` module
-rw-r--r--changelog.d/479.change.rst1
-rw-r--r--setuptools/command/build_ext.py10
-rw-r--r--setuptools/command/install_lib.py6
3 files changed, 12 insertions, 5 deletions
diff --git a/changelog.d/479.change.rst b/changelog.d/479.change.rst
new file mode 100644
index 00000000..d494c0fc
--- /dev/null
+++ b/changelog.d/479.change.rst
@@ -0,0 +1 @@
+Remove some usage of the deprecated ``imp`` module.
diff --git a/setuptools/command/build_ext.py b/setuptools/command/build_ext.py
index 60a8a32f..daa8e4fe 100644
--- a/setuptools/command/build_ext.py
+++ b/setuptools/command/build_ext.py
@@ -1,7 +1,6 @@
import os
import sys
import itertools
-import imp
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
@@ -12,6 +11,13 @@ 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
from Cython.Distutils.build_ext import build_ext as _build_ext
@@ -64,7 +70,7 @@ if_dl = lambda s: s if have_rtld else ''
def get_abi3_suffix():
"""Return the file extension for an abi3-compliant Extension()"""
- for suffix, _, _ in (s for s in imp.get_suffixes() if s[2] == imp.C_EXTENSION):
+ for suffix in EXTENSION_SUFFIXES:
if '.abi3' in suffix: # Unix
return suffix
elif suffix == '.pyd': # Windows
diff --git a/setuptools/command/install_lib.py b/setuptools/command/install_lib.py
index 2b31c3e3..07d65933 100644
--- a/setuptools/command/install_lib.py
+++ b/setuptools/command/install_lib.py
@@ -1,5 +1,5 @@
import os
-import imp
+import sys
from itertools import product, starmap
import distutils.command.install_lib as orig
@@ -74,10 +74,10 @@ class install_lib(orig.install_lib):
yield '__init__.pyc'
yield '__init__.pyo'
- if not hasattr(imp, 'get_tag'):
+ if not hasattr(sys, 'implementation'):
return
- base = os.path.join('__pycache__', '__init__.' + imp.get_tag())
+ base = os.path.join('__pycache__', '__init__.' + sys.implementation.cache_tag)
yield base + '.pyc'
yield base + '.pyo'
yield base + '.opt-1.pyc'