From 3cc037209fc2217051d12d66d712e3566241ce1f Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 2 Dec 2019 13:23:40 +0100 Subject: [PATCH 1/6] Major rework of build to build snappy as a static lib first --- setup.py | 228 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 147 insertions(+), 81 deletions(-) diff --git a/setup.py b/setup.py index cd2b9481..0498f862 100644 --- a/setup.py +++ b/setup.py @@ -35,8 +35,10 @@ from setuptools import setup, Extension from setuptools.command.build_py import build_py as _build_py from setuptools.command.build_ext import build_ext +from setuptools.command.build_clib import build_clib from distutils.command.build import build -from distutils.errors import CompileError +from distutils import ccompiler, errors, sysconfig + logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -116,141 +118,197 @@ def initialize_options(self): self.cpp11 = True -class PluginBuildExt(build_ext): - """Build extension command for DLLs that are not Python modules +class BuildOptionsCommandMixIn(object): + """MixIn class for build command to check build options""" - This is actually only useful for Windows - """ + _options = {} + """Store build option states once for all""" - def get_export_symbols(self, ext): - """Overridden to remove PyInit_* export""" - return ext.export_symbols + def select_compiler_flags(self, flags): + """Removes compiler arguments that are not for the current one. - def get_ext_filename(self, ext_name): - """Overridden to use .dll as file extension""" - if sys.platform.startswith('win'): - return os.path.join(*ext_name.split('.')) + '.dll' - elif sys.platform.startswith('linux'): - return os.path.join(*ext_name.split('.')) + '.so' - elif sys.platform.startswith('darwin'): - return os.path.join(*ext_name.split('.')) + '.dylib' - else: - return build_ext.get_ext_filename(self, ext_name) + :param List[str] flags: All compiler arguments + :return: List of arguments for the current compiler + :rtype: List[str] + """ + prefix = '/' if self.__get_compiler().compiler_type == 'msvc' else '-' + return [flag for flag in flags if flag.startswith(prefix)] - def build_extensions(self): - """Overridden to tune extensions. + def has_option(self, option): + """Returns whether a build option is in use or not. - - check for OpenMP, SSE2, AVX2 availability - - select compile args for MSVC and others - - Set hdf5 directory + It checks if option is enabled and available. + + :param str option: Name of the option to get + :rtype: bool + """ + if not self._options: + self.__init_options() + return self._options[option] + + def __get_compiler(self): + """Returns a compiler object (creating one if needed) + + :rtype: distutils.ccompiler.CCompiler """ + compiler = self.compiler + if not isinstance(compiler, ccompiler.CCompiler): + compiler = ccompiler.new_compiler(compiler=compiler, force=True) + sysconfig.customize_compiler(compiler) + return compiler + + def __init_options(self): + """Initialize the options""" + self._options = { + 'cpp11': False, + 'sse2': False, + 'avx2': False, + 'openmp': False, + 'native': False, + } + build_cmd = self.distribution.get_command_obj("build") - compiler_type = self.compiler.compiler_type + compiler_type = self.__get_compiler().compiler_type # Check availability of compile flags if build_cmd.cpp11: if compiler_type == 'msvc': - with_cpp11 = sys.version_info[:2] >= (3, 5) + self._options['cpp11'] = sys.version_info[:2] >= (3, 5) else: - with_cpp11 = self.__check_compile_flag('-std=c++11', extension='.cpp') - else: - with_cpp11 = False + self._options['cpp11'] = self.__check_compile_flag( + '-std=c++11', extension='.cc') if build_cmd.sse2: if compiler_type == 'msvc': - with_sse2 = sys.version_info[0] >= 3 + self._options['sse2'] = sys.version_info[0] >= 3 else: - with_sse2 = self.__check_compile_flag('-msse2') - else: - with_sse2 = False + self._options['sse2'] = self.__check_compile_flag('-msse2') if build_cmd.avx2: if compiler_type == 'msvc': - with_avx2 = sys.version_info[:2] >= (3, 5) + self._options['avx2'] = sys.version_info[:2] >= (3, 5) else: - with_avx2 = self.__check_compile_flag('-mavx2') - else: - with_avx2 = False + self._options['avx2'] = self.__check_compile_flag('-mavx2') - with_openmp = bool(build_cmd.openmp) and self.__check_compile_flag( - '/openmp' if compiler_type == 'msvc' else '-fopenmp') + if build_cmd.openmp: + self._options['openmp'] = self.__check_compile_flag( + self.get_compiler_flag_prefix() + 'openmp') if build_cmd.native: + self._options['native'] = True is_cpu_sse2, is_cpu_avx2 = get_cpu_sse2_avx2() - with_sse2 = with_sse2 and is_cpu_sse2 - with_avx2 = with_avx2 and is_cpu_avx2 + self._options['sse2'] = self._options['sse2'] and is_cpu_sse2 + self._options['avx2'] = self._options['avx2'] and is_cpu_avx2 - logger.info("Building with C++11: %r", with_cpp11) - logger.info('Building with native option: %r', bool(build_cmd.native)) - logger.info("Building extensions with SSE2: %r", with_sse2) - logger.info("Building extensions with AVX2: %r", with_avx2) - logger.info("Building extensions with OpenMP: %r", with_openmp) + logger.info("Building with C++11: %r", self._options['cpp11']) + logger.info('Building with native option: %r', self._options['native']) + logger.info("Building with SSE2: %r", self._options['sse2']) + logger.info("Building with AVX2: %r", self._options['avx2']) + logger.info("Building with OpenMP: %r", self._options['openmp']) - prefix = '/' if compiler_type == 'msvc' else '-' + def __check_compile_flag(self, flag, extension='.c'): + """Try to compile an empty file to check for compiler args + :param str flag: Flag argument to pass to compiler + :param str extension: Source file extension (default: '.c') + :returns: Whether or not compilation was successful + :rtype: bool + """ + if sys.version_info[0] < 3: + return False # Not implemented for Python 2.7 + + with tempfile.TemporaryDirectory() as tmp_dir: + # Create empty source file + tmp_file = os.path.join(tmp_dir, 'source' + extension) + with open(tmp_file, 'w') as f: + f.write('int main (int argc, char **argv) { return 0; }\n') + + compiler = self.__get_compiler() + try: + compiler.compile([tmp_file], output_dir=tmp_dir, extra_postargs=[flag]) + except errors.CompileError: + return False + else: + return True + + +class PluginBuildExt(build_ext, BuildOptionsCommandMixIn): + """Build extension command for DLLs that are not Python modules""" + + def get_export_symbols(self, ext): + """Overridden to remove PyInit_* export""" + return ext.export_symbols + + def get_ext_filename(self, ext_name): + """Overridden to use .dll as file extension""" + if sys.platform.startswith('win'): + return os.path.join(*ext_name.split('.')) + '.dll' + elif sys.platform.startswith('linux'): + return os.path.join(*ext_name.split('.')) + '.so' + elif sys.platform.startswith('darwin'): + return os.path.join(*ext_name.split('.')) + '.dylib' + else: + return build_ext.get_ext_filename(self, ext_name) + + def build_extensions(self): + """Overridden to tune extensions. + + - check for OpenMP, SSE2, AVX2 availability + - select compile args for MSVC and others + - Set hdf5 directory + """ for e in self.extensions: if isinstance(e, HDF5PluginExtension): + build_cmd = self.distribution.get_command_obj("build") e.set_hdf5_dir(build_cmd.hdf5) - if with_cpp11: + if self.has_option('cpp11'): for name, value in e.cpp11.items(): attribute = getattr(e, name) attribute += value # Enable SSE2/AVX2 if available and add corresponding resources - if with_sse2: + if self.has_option('sse2'): e.extra_compile_args += ['-msse2'] # /arch:SSE2 is on by default for name, value in e.sse2.items(): attribute = getattr(e, name) attribute += value - if with_avx2: + if self.has_option('avx2'): e.extra_compile_args += ['-mavx2', '/arch:AVX2'] for name, value in e.avx2.items(): attribute = getattr(e, name) attribute += value - if not with_openmp: # Remove OpenMP flags + if not self.has_option('openmp'): # Remove OpenMP flags e.extra_compile_args = [ arg for arg in e.extra_compile_args if not arg.endswith('openmp')] e.extra_link_args = [ arg for arg in e.extra_link_args if not arg.endswith('openmp')] - if build_cmd.native: # Add -march=native + if self.has_option('native'): # Add -march=native e.extra_compile_args += ['-march=native'] # Remove flags that do not correspond to compiler - e.extra_compile_args = [ - arg for arg in e.extra_compile_args if arg.startswith(prefix)] - e.extra_link_args = [ - arg for arg in e.extra_link_args if arg.startswith(prefix)] + e.extra_compile_args = self.select_compiler_flags(e.extra_compile_args) + e.extra_link_args = self.select_compiler_flags(e.extra_link_args) build_ext.build_extensions(self) - def __check_compile_flag(self, flag, extension='.c'): - """Try to compile an empty file to check for compiler args - :param str flag: Flag argument to pass to compiler - :param str extension: Source file extension (default: '.c') - :returns: Whether or not compilation was successful - :rtype: bool - """ - if sys.version_info[0] < 3: - return False # Not implemented for Python 2.7 +class BuildCpp11Lib(build_clib, BuildOptionsCommandMixIn): + """Build C++11 static libraries only if available. - with tempfile.TemporaryDirectory() as tmp_dir: - # Create empty source file - tmp_file = os.path.join(tmp_dir, 'source' + extension) - with open(tmp_file, 'w') as f: - f.write('int main (int argc, char **argv) { return 0; }\n') + This is used for the snappy library. + """ - try: - self.compiler.compile([tmp_file], output_dir=tmp_dir, extra_postargs=[flag]) - except CompileError: - return False - else: - return True + def check_library_list(self, libraries): + # Filter out C++11 libraries if cpp11 option is False + with_cpp = self.has_option('cpp11') + libraries = [(name, info) for name, info in libraries + if with_cpp or '-std=c++11' not in info.get('cflags', [])] + build_clib.check_library_list(self, libraries) class HDF5PluginExtension(Extension): @@ -367,10 +425,13 @@ def prefix(directory, files): define_macros.append(('HAVE_LZ4', 1)) # snappy -cpp11_kwargs = { +snappy_lib = ('snappy', { 'sources': glob(blosc_dir + 'internal-complibs/snappy*/*.cc'), 'include_dirs': glob(blosc_dir + 'internal-complibs/snappy*'), - 'extra_compile_args': ['-std=c++11', '-lstdc++'], + 'cflags': ['-std=c++11']}) + +cpp11_kwargs = { + 'include_dirs': glob(blosc_dir + 'internal-complibs/snappy*'), 'define_macros': [('HAVE_SNAPPY', 1)], } @@ -414,10 +475,12 @@ def prefix(directory, files): ) -extensions=[lz4_plugin, - bithsuffle_plugin, - blosc_plugin, - ] +libraries = [snappy_lib] + +extensions = [lz4_plugin, + bithsuffle_plugin, + blosc_plugin, + ] # setup @@ -471,9 +534,11 @@ def find_package_modules(self, package, package_dir): "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", "Topic :: Software Development :: Libraries :: Python Modules", ] cmdclass = dict(build=Build, + build_clib=BuildCpp11Lib, build_ext=PluginBuildExt, build_py=build_py) if BDistWheel is not None: @@ -494,5 +559,6 @@ def find_package_modules(self, package, package_dir): install_requires=['h5py'], setup_requires=['setuptools'], cmdclass=cmdclass, + libraries=libraries, ) From 691cdf26b4ef4995dd8bb57f6b1bcb4f879e512f Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 2 Dec 2019 14:08:26 +0100 Subject: [PATCH 2/6] Fix missing method --- setup.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0498f862..fd4feb9c 100644 --- a/setup.py +++ b/setup.py @@ -124,6 +124,13 @@ class BuildOptionsCommandMixIn(object): _options = {} """Store build option states once for all""" + def get_compiler_flag_prefix(self): + """Returns compiler flags prefix character ('-' or '/') + + :rtype: str + """ + return '/' if self.__get_compiler().compiler_type == 'msvc' else '-' + def select_compiler_flags(self, flags): """Removes compiler arguments that are not for the current one. @@ -131,7 +138,7 @@ def select_compiler_flags(self, flags): :return: List of arguments for the current compiler :rtype: List[str] """ - prefix = '/' if self.__get_compiler().compiler_type == 'msvc' else '-' + prefix = self.get_compiler_flag_prefix() return [flag for flag in flags if flag.startswith(prefix)] def has_option(self, option): From f37ca2af0ccf74583747984aa73044836b16919d Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 2 Dec 2019 14:17:51 +0100 Subject: [PATCH 3/6] Add -lstdc++ to link --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index fd4feb9c..a77ce9d1 100644 --- a/setup.py +++ b/setup.py @@ -439,6 +439,7 @@ def prefix(directory, files): cpp11_kwargs = { 'include_dirs': glob(blosc_dir + 'internal-complibs/snappy*'), + 'extra_link_args': ['-lstdc++'], 'define_macros': [('HAVE_SNAPPY', 1)], } From 71a272a1b05b7ba3056c3846976c05bc6d561ed0 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Wed, 4 Dec 2019 15:53:09 +0100 Subject: [PATCH 4/6] rework compiler options detection and c++11 handling --- setup.py | 230 +++++++++++++++++++++---------------------------------- 1 file changed, 89 insertions(+), 141 deletions(-) diff --git a/setup.py b/setup.py index a77ce9d1..26c159d6 100644 --- a/setup.py +++ b/setup.py @@ -33,9 +33,8 @@ import sys import tempfile from setuptools import setup, Extension -from setuptools.command.build_py import build_py as _build_py +from setuptools.command.build_py import build_py from setuptools.command.build_ext import build_ext -from setuptools.command.build_clib import build_clib from distutils.command.build import build from distutils import ccompiler, errors, sysconfig @@ -87,6 +86,32 @@ def get_cpu_sse2_avx2(): # Plugins +def check_compile_flag(compiler, flag, extension='.c'): + """Try to compile an empty file to check for compiler args + + :param distutils.ccompiler.CCompiler compiler: The compiler to use + :param str flag: Flag argument to pass to compiler + :param str extension: Source file extension (default: '.c') + :returns: Whether or not compilation was successful + :rtype: bool + """ + if sys.version_info[0] < 3: + return False # Not implemented for Python 2.7 + + with tempfile.TemporaryDirectory() as tmp_dir: + # Create empty source file + tmp_file = os.path.join(tmp_dir, 'source' + extension) + with open(tmp_file, 'w') as f: + f.write('int main (int argc, char **argv) { return 0; }\n') + + try: + compiler.compile([tmp_file], output_dir=tmp_dir, extra_postargs=[flag]) + except errors.CompileError: + return False + else: + return True + + class Build(build): """Build command with extra options used by PluginBuildExt""" @@ -117,131 +142,66 @@ def initialize_options(self): self.avx2 = True self.cpp11 = True + def finalize_options(self): + build.finalize_options(self) -class BuildOptionsCommandMixIn(object): - """MixIn class for build command to check build options""" - - _options = {} - """Store build option states once for all""" - - def get_compiler_flag_prefix(self): - """Returns compiler flags prefix character ('-' or '/') - - :rtype: str - """ - return '/' if self.__get_compiler().compiler_type == 'msvc' else '-' - - def select_compiler_flags(self, flags): - """Removes compiler arguments that are not for the current one. - - :param List[str] flags: All compiler arguments - :return: List of arguments for the current compiler - :rtype: List[str] - """ - prefix = self.get_compiler_flag_prefix() - return [flag for flag in flags if flag.startswith(prefix)] - - def has_option(self, option): - """Returns whether a build option is in use or not. - - It checks if option is enabled and available. - - :param str option: Name of the option to get - :rtype: bool - """ - if not self._options: - self.__init_options() - return self._options[option] - - def __get_compiler(self): - """Returns a compiler object (creating one if needed) + # Check that build options are available + compiler = ccompiler.new_compiler(compiler=self.compiler, force=True) + sysconfig.customize_compiler(compiler) - :rtype: distutils.ccompiler.CCompiler - """ - compiler = self.compiler - if not isinstance(compiler, ccompiler.CCompiler): - compiler = ccompiler.new_compiler(compiler=compiler, force=True) - sysconfig.customize_compiler(compiler) - return compiler - - def __init_options(self): - """Initialize the options""" - self._options = { - 'cpp11': False, - 'sse2': False, - 'avx2': False, - 'openmp': False, - 'native': False, - } - - build_cmd = self.distribution.get_command_obj("build") - compiler_type = self.__get_compiler().compiler_type - - # Check availability of compile flags - - if build_cmd.cpp11: - if compiler_type == 'msvc': - self._options['cpp11'] = sys.version_info[:2] >= (3, 5) + if self.cpp11: + if compiler.compiler_type == 'msvc': + self.cpp11 = sys.version_info[:2] >= (3, 5) else: - self._options['cpp11'] = self.__check_compile_flag( - '-std=c++11', extension='.cc') - - if build_cmd.sse2: - if compiler_type == 'msvc': - self._options['sse2'] = sys.version_info[0] >= 3 + self.cpp1 = check_compile_flag( + compiler, '-std=c++11', extension='.cc') + if not self.cpp11: + logger.warning("C++11 disabled: not available") + + if self.sse2: + if compiler.compiler_type == 'msvc': + self.sse2 = sys.version_info[0] >= 3 else: - self._options['sse2'] = self.__check_compile_flag('-msse2') + self.sse2 = check_compile_flag(compiler, '-msse2') + if not self.sse2: + logger.warning("SSE2 disabled: not available") - if build_cmd.avx2: - if compiler_type == 'msvc': - self._options['avx2'] = sys.version_info[:2] >= (3, 5) + if self.avx2: + if compiler.compiler_type == 'msvc': + self.avx2 = sys.version_info[:2] >= (3, 5) else: - self._options['avx2'] = self.__check_compile_flag('-mavx2') + self.avx2 = check_compile_flag(compiler, '-mavx2') + if not self.avx2: + logger.warning("AVX2 disabled: not available") - if build_cmd.openmp: - self._options['openmp'] = self.__check_compile_flag( - self.get_compiler_flag_prefix() + 'openmp') + if self.openmp: + prefix = '/' if compiler.compiler_type == 'msvc' else '-' + self.openmp = check_compile_flag(compiler, prefix + 'openmp') + if not self.openmp: + logger.warning("OpenMP disabled: not available") - if build_cmd.native: - self._options['native'] = True + if self.native: is_cpu_sse2, is_cpu_avx2 = get_cpu_sse2_avx2() - self._options['sse2'] = self._options['sse2'] and is_cpu_sse2 - self._options['avx2'] = self._options['avx2'] and is_cpu_avx2 - - logger.info("Building with C++11: %r", self._options['cpp11']) - logger.info('Building with native option: %r', self._options['native']) - logger.info("Building with SSE2: %r", self._options['sse2']) - logger.info("Building with AVX2: %r", self._options['avx2']) - logger.info("Building with OpenMP: %r", self._options['openmp']) - - def __check_compile_flag(self, flag, extension='.c'): - """Try to compile an empty file to check for compiler args - - :param str flag: Flag argument to pass to compiler - :param str extension: Source file extension (default: '.c') - :returns: Whether or not compilation was successful - :rtype: bool - """ - if sys.version_info[0] < 3: - return False # Not implemented for Python 2.7 - - with tempfile.TemporaryDirectory() as tmp_dir: - # Create empty source file - tmp_file = os.path.join(tmp_dir, 'source' + extension) - with open(tmp_file, 'w') as f: - f.write('int main (int argc, char **argv) { return 0; }\n') - - compiler = self.__get_compiler() - try: - compiler.compile([tmp_file], output_dir=tmp_dir, extra_postargs=[flag]) - except errors.CompileError: - return False - else: - return True + self.sse2 = self.sse2 and is_cpu_sse2 + self.avx2 = self.avx2 and is_cpu_avx2 + + logger.info("Building with C++11: %r", bool(self.cpp11)) + logger.info('Building with native option: %r', bool(self.native)) + logger.info("Building with SSE2: %r", bool(self.sse2)) + logger.info("Building with AVX2: %r", bool(self.avx2)) + logger.info("Building with OpenMP: %r", bool(self.openmp)) + + # Filter out C++11 libraries if cpp11 option is False + self.distribution.libraries = [ + (name, info) for name, info in self.distribution.libraries + if self.cpp11 or '-std=c++11' not in info.get('cflags', [])] -class PluginBuildExt(build_ext, BuildOptionsCommandMixIn): - """Build extension command for DLLs that are not Python modules""" +class PluginBuildExt(build_ext): + """Build extension command for DLLs that are not Python modules + + It also handles extra compile arguments depending on the build options. + """ def get_export_symbols(self, ext): """Overridden to remove PyInit_* export""" @@ -270,54 +230,43 @@ def build_extensions(self): build_cmd = self.distribution.get_command_obj("build") e.set_hdf5_dir(build_cmd.hdf5) - if self.has_option('cpp11'): + if build_cmd.cpp11: for name, value in e.cpp11.items(): attribute = getattr(e, name) attribute += value # Enable SSE2/AVX2 if available and add corresponding resources - if self.has_option('sse2'): + if build_cmd.sse2: e.extra_compile_args += ['-msse2'] # /arch:SSE2 is on by default for name, value in e.sse2.items(): attribute = getattr(e, name) attribute += value - if self.has_option('avx2'): + if build_cmd.avx2: e.extra_compile_args += ['-mavx2', '/arch:AVX2'] for name, value in e.avx2.items(): attribute = getattr(e, name) attribute += value - if not self.has_option('openmp'): # Remove OpenMP flags + if not build_cmd.openmp: # Remove OpenMP flags e.extra_compile_args = [ arg for arg in e.extra_compile_args if not arg.endswith('openmp')] e.extra_link_args = [ arg for arg in e.extra_link_args if not arg.endswith('openmp')] - if self.has_option('native'): # Add -march=native + if build_cmd.native: # Add -march=native e.extra_compile_args += ['-march=native'] # Remove flags that do not correspond to compiler - e.extra_compile_args = self.select_compiler_flags(e.extra_compile_args) - e.extra_link_args = self.select_compiler_flags(e.extra_link_args) + prefix = '/' if self.compiler.compiler_type == 'msvc' else '-' + e.extra_compile_args = [flag for flag in e.extra_compile_args + if flag.startswith(prefix)] + e.extra_link_args = [flag for flag in e.extra_link_args + if flag.startswith(prefix)] build_ext.build_extensions(self) -class BuildCpp11Lib(build_clib, BuildOptionsCommandMixIn): - """Build C++11 static libraries only if available. - - This is used for the snappy library. - """ - - def check_library_list(self, libraries): - # Filter out C++11 libraries if cpp11 option is False - with_cpp = self.has_option('cpp11') - libraries = [(name, info) for name, info in libraries - if with_cpp or '-std=c++11' not in info.get('cflags', [])] - build_clib.check_library_list(self, libraries) - - class HDF5PluginExtension(Extension): """Extension adding specific things to build a HDF5 plugin""" @@ -505,12 +454,12 @@ def get_version(): return version.strictversion -class build_py(_build_py): +class BuildPy(build_py): """ Enhanced build_py which copies version.py to ._version.py """ def find_package_modules(self, package, package_dir): - modules = _build_py.find_package_modules(self, package, package_dir) + modules = build_py.find_package_modules(self, package, package_dir) if package == PROJECT: modules.append((PROJECT, '_version', 'version.py')) return modules @@ -546,9 +495,8 @@ def find_package_modules(self, package, package_dir): "Topic :: Software Development :: Libraries :: Python Modules", ] cmdclass = dict(build=Build, - build_clib=BuildCpp11Lib, build_ext=PluginBuildExt, - build_py=build_py) + build_py=BuildPy) if BDistWheel is not None: cmdclass['bdist_wheel'] = BDistWheel From 9f99573e2ebd1314d615cb56b968ee5ebd83f27e Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Wed, 4 Dec 2019 15:57:19 +0100 Subject: [PATCH 5/6] move init of variables at beginning of method --- setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 26c159d6..03069c00 100644 --- a/setup.py +++ b/setup.py @@ -225,9 +225,11 @@ def build_extensions(self): - select compile args for MSVC and others - Set hdf5 directory """ + build_cmd = self.distribution.get_command_obj("build") + prefix = '/' if self.compiler.compiler_type == 'msvc' else '-' + for e in self.extensions: if isinstance(e, HDF5PluginExtension): - build_cmd = self.distribution.get_command_obj("build") e.set_hdf5_dir(build_cmd.hdf5) if build_cmd.cpp11: @@ -258,7 +260,6 @@ def build_extensions(self): e.extra_compile_args += ['-march=native'] # Remove flags that do not correspond to compiler - prefix = '/' if self.compiler.compiler_type == 'msvc' else '-' e.extra_compile_args = [flag for flag in e.extra_compile_args if flag.startswith(prefix)] e.extra_link_args = [flag for flag in e.extra_link_args From a80ca943620cbe45318316431e9d27ec3f991007 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Wed, 4 Dec 2019 16:00:12 +0100 Subject: [PATCH 6/6] minimize diff --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 03069c00..f5027633 100644 --- a/setup.py +++ b/setup.py @@ -260,10 +260,10 @@ def build_extensions(self): e.extra_compile_args += ['-march=native'] # Remove flags that do not correspond to compiler - e.extra_compile_args = [flag for flag in e.extra_compile_args - if flag.startswith(prefix)] - e.extra_link_args = [flag for flag in e.extra_link_args - if flag.startswith(prefix)] + e.extra_compile_args = [ + arg for arg in e.extra_compile_args if arg.startswith(prefix)] + e.extra_link_args = [ + arg for arg in e.extra_link_args if arg.startswith(prefix)] build_ext.build_extensions(self)