Skip to content

Commit

Permalink
Merge pull request #276 from t20100/remove-distutils
Browse files Browse the repository at this point in the history
Removed import of `distutils`
  • Loading branch information
kif authored Sep 7, 2023
2 parents c0d8610 + 16e398b commit cab208c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package/debian11/control
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Build-Depends: debhelper-compat (= 12),
libgomp1,
python3-all-dev,
python3-h5py,
python3-setuptools
python3-setuptools,
python3-wheel
Standards-Version: 4.1.3
Homepage: https://github.com/silx-kit/hdf5plugin

Expand Down
28 changes: 21 additions & 7 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 Expand Up @@ -1337,7 +1351,7 @@ def make_distribution(self):
package_dir={'': 'src'},
ext_modules=extensions,
install_requires=['h5py'],
setup_requires=['setuptools'],
setup_requires=['setuptools', 'wheel'],
extras_require={'dev': ['sphinx', 'sphinx_rtd_theme']},
cmdclass=cmdclass,
libraries=libraries,
Expand Down

0 comments on commit cab208c

Please sign in to comment.