diff options
author | mattip <matti.picus@gmail.com> | 2020-01-04 22:47:47 +0200 |
---|---|---|
committer | mattip <matti.picus@gmail.com> | 2020-01-05 10:56:58 +0200 |
commit | 18af8e00711f62a5aa2c9b0c4f1225be49877a38 (patch) | |
tree | 27ed84bc3ab4af6e3559f199a73153fe52da0b72 | |
parent | c1f1bc9ce8e4e2936e80d9bfafc3d8e03237a84b (diff) | |
download | numpy-18af8e00711f62a5aa2c9b0c4f1225be49877a38.tar.gz |
MAINT: add --std=c99 in setup.py, not distutils
-rw-r--r-- | numpy/distutils/ccompiler.py | 5 | ||||
-rw-r--r-- | numpy/distutils/tests/test_ccompiler.py | 22 | ||||
-rwxr-xr-x | setup.py | 42 |
3 files changed, 40 insertions, 29 deletions
diff --git a/numpy/distutils/ccompiler.py b/numpy/distutils/ccompiler.py index ef29189f7..04d85e365 100644 --- a/numpy/distutils/ccompiler.py +++ b/numpy/distutils/ccompiler.py @@ -530,11 +530,6 @@ def CCompiler_customize(self, dist, need_cxx=0): 'g++' in self.compiler[0] or 'clang' in self.compiler[0]): self._auto_depends = True - if 'gcc' in self.compiler[0] and not need_cxx: - # add std=c99 flag for gcc - # TODO: does this need to be more specific? - self.compiler.append('-std=c99') - self.compiler_so.append('-std=c99') elif os.name == 'posix': import tempfile import shutil diff --git a/numpy/distutils/tests/test_ccompiler.py b/numpy/distutils/tests/test_ccompiler.py deleted file mode 100644 index 72aa8227c..000000000 --- a/numpy/distutils/tests/test_ccompiler.py +++ /dev/null @@ -1,22 +0,0 @@ -from distutils.ccompiler import new_compiler - -from numpy.distutils.numpy_distribution import NumpyDistribution - -def test_ccompiler(): - ''' - scikit-image/scikit-image issue 4369 - We unconditionally add ``-std-c99`` to the gcc compiler in order - to support c99 with very old gcc compilers. However the same call - is used to get the flags for the c++ compiler, just with a kwarg. - Make sure in this case, where it would not be legal, the option is **not** added - ''' - dist = NumpyDistribution() - compiler = new_compiler() - compiler.customize(dist) - if hasattr(compiler, 'compiler') and 'gcc' in compiler.compiler[0]: - assert 'c99' in ' '.join(compiler.compiler) - - compiler = new_compiler() - compiler.customize(dist, need_cxx=True) - if hasattr(compiler, 'compiler') and 'gcc' in compiler.compiler[0]: - assert 'c99' not in ' '.join(compiler.compiler) @@ -23,6 +23,7 @@ import os import sys import subprocess import textwrap +import sysconfig if sys.version_info[:2] < (3, 6): @@ -225,6 +226,40 @@ class sdist_checked(sdist): sdist.run(self) +def get_build_overrides(): + """ + Custom build commands to add `--std=c99` to compilation + """ + from numpy.distutils.command.build_clib import build_clib + from numpy.distutils.command.build_ext import build_ext + + def _is_using_gcc(obj): + is_gcc = False + if obj.compiler.compiler_type == 'unix': + cc = sysconfig.get_config_var("CC") + if not cc: + cc = "" + compiler_name = os.path.basename(cc) + is_gcc = "gcc" in compiler_name + return is_gcc + + class new_build_clib(build_clib): + def build_a_library(self, build_info, lib_name, libraries): + if _is_using_gcc(self): + args = build_info.get('extra_compiler_args') or [] + args.append('--std=c99') + build_info['extra_compiler_args'] = args + build_clib.build_a_library(self, build_info, lib_name, libraries) + + class new_build_ext(build_ext): + def build_extension(self, ext): + if _is_using_gcc(self): + if '--std=c99' not in ext.extra_compile_args: + ext.extra_compile_args.append('--std=c99') + build_ext.build_extension(self, ext) + return new_build_clib, new_build_ext + + def generate_cython(): cwd = os.path.abspath(os.path.dirname(__file__)) print("Cythonizing sources") @@ -387,6 +422,8 @@ def setup_package(): 'f2py%s.%s = numpy.f2py.f2py2e:main' % sys.version_info[:2], ] + cmdclass={"sdist": sdist_checked, + } metadata = dict( name = 'numpy', maintainer = "NumPy Developers", @@ -405,8 +442,7 @@ def setup_package(): classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f], platforms = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"], test_suite='nose.collector', - cmdclass={"sdist": sdist_checked, - }, + cmdclass=cmdclass, python_requires='>=3.5', zip_safe=False, entry_points={ @@ -430,6 +466,8 @@ def setup_package(): generate_cython() metadata['configuration'] = configuration + # Customize extension building + cmdclass['build_clib'], cmdclass['build_ext'] = get_build_overrides() else: # Version number is added to metadata inside configuration() if build # is run. |