Commit eb7436b3 authored by Anthony Sottile's avatar Anthony Sottile Committed by Paul Ganssle

Fix some usage of deprecated `imp` module

parent 05f42a2c
Remove some usage of the deprecated ``imp`` module.
import os import os
import sys import sys
import itertools import itertools
import imp
from distutils.command.build_ext import build_ext as _du_build_ext from distutils.command.build_ext import build_ext as _du_build_ext
from distutils.file_util import copy_file from distutils.file_util import copy_file
from distutils.ccompiler import new_compiler from distutils.ccompiler import new_compiler
...@@ -12,6 +11,13 @@ from distutils import log ...@@ -12,6 +11,13 @@ from distutils import log
from setuptools.extension import Library from setuptools.extension import Library
from setuptools.extern import six 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: try:
# Attempt to use Cython for building extensions, if available # Attempt to use Cython for building extensions, if available
from Cython.Distutils.build_ext import build_ext as _build_ext from Cython.Distutils.build_ext import build_ext as _build_ext
...@@ -64,7 +70,7 @@ if_dl = lambda s: s if have_rtld else '' ...@@ -64,7 +70,7 @@ if_dl = lambda s: s if have_rtld else ''
def get_abi3_suffix(): def get_abi3_suffix():
"""Return the file extension for an abi3-compliant Extension()""" """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 if '.abi3' in suffix: # Unix
return suffix return suffix
elif suffix == '.pyd': # Windows elif suffix == '.pyd': # Windows
......
import os import os
import imp import sys
from itertools import product, starmap from itertools import product, starmap
import distutils.command.install_lib as orig import distutils.command.install_lib as orig
...@@ -74,10 +74,10 @@ class install_lib(orig.install_lib): ...@@ -74,10 +74,10 @@ class install_lib(orig.install_lib):
yield '__init__.pyc' yield '__init__.pyc'
yield '__init__.pyo' yield '__init__.pyo'
if not hasattr(imp, 'get_tag'): if not hasattr(sys, 'implementation'):
return 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 + '.pyc'
yield base + '.pyo' yield base + '.pyo'
yield base + '.opt-1.pyc' yield base + '.opt-1.pyc'
......
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