Skip to content

Commit

Permalink
Remove direct usage of distutils
Browse files Browse the repository at this point in the history
  • Loading branch information
t20100 committed Sep 7, 2023
1 parent 45ded90 commit 6e9be65
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import sysconfig
import tempfile
import platform
from setuptools import setup, Extension
from setuptools import setup, Distribution, Extension
from setuptools.command.build_ext import build_ext
from setuptools.command.sdist import sdist
from setuptools.command.build_py import build_py
Expand All @@ -48,8 +48,6 @@
from setuptools.errors import CompileError
except ImportError:
from distutils.errors import CompileError
import distutils.ccompiler
import distutils.sysconfig
from wheel.bdist_wheel import bdist_wheel, get_platform

logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -86,6 +84,24 @@ def get_tag(self):

# Probe host capabilities and manage build config

def get_compiler(compiler):
"""Returns an initialized compiler
Taken from https://github.com/pypa/setuptools/issues/2806#issuecomment-961805789
"""
d = Distribution()
build_ext = Distribution().get_command_obj("build_ext")
build_ext.compiler = compiler
build_ext.finalize_options()
# register an extension to ensure a compiler is created
build_ext.extensions = [Extension("ignored", ["ignored.c"])]
# disable building fake extensions
build_ext.build_extensions = lambda: None
# run to populate self.compiler
build_ext.run()
return build_ext.compiler


def check_compile_flags(compiler, *flags, extension='.c'):
"""Try to compile an empty file to check for compiler args
Expand Down Expand Up @@ -128,9 +144,7 @@ class HostConfig:
"""Machine architecture description from cpuinfo parser"""

def __init__(self, compiler=None):
compiler = distutils.ccompiler.new_compiler(compiler, force=True)
distutils.sysconfig.customize_compiler(compiler)
self.__compiler = compiler
self.__compiler = get_compiler(compiler)

# Set architecture specific compile args
if self.ARCH in ('X86_32', 'X86_64', 'MIPS_64'):
Expand Down

0 comments on commit 6e9be65

Please sign in to comment.