From 3a1256691216e53576464942ee7e827cc55419e4 Mon Sep 17 00:00:00 2001 From: BenTenmann Date: Sun, 2 Jan 2022 11:22:27 +0000 Subject: [PATCH 1/2] fix: add openmp macOS --- .gitignore | 2 ++ pyproject.toml | 3 +++ setup.py | 66 +++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore index b09d791..80100b2 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ nosetests.xml .project .pydevproject .python-version +build-test.sh +.idea diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8fe2f47 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["setuptools>=42", "wheel"] +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index c0ef96a..00e30e4 100644 --- a/setup.py +++ b/setup.py @@ -1,20 +1,68 @@ -from setuptools import setup, Extension - +import logging import os +import platform +import shutil +import subprocess + +from setuptools import setup, Extension OPENMP_DISABLED = os.environ.get('OPENMP_DISABLED', False) -libraries=['clustalo', 'stdc++'] -extra_compile_args = [] +libraries = ['clustalo', 'stdc++'] + +# if not OPENMP_DISABLED: +# libraries.append('gomp') + + +class BuildFlags: + _tools_formulae = { + 'Darwin': ('brew', 'libomp'), + } + _args = { + 'Darwin': { + 'compiler': ['-Xpreprocessor', '-fopenmp'], + 'linker': ['-lomp'] + } + } + _default_args = { + 'compiler': ['-fopenmp'], + 'linker': ['-fopenmp'] + } + compiler: list + linker: list + + def __init__(self): + self._system = platform.system() + tool, formula = self._tools_formulae.get(self._system, ('apt', 'libomp-dev')) + args = self._args.get(self._system, self._default_args) + + not_found = self._libomp_check(tool, formula) + if not_found is not None: + logging.warning(f'{repr(not_found)} not found -- cannot compile parallelized code') + for key in args: + args[key] = [] + + for key, val in args.items(): + self.__setattr__(key, val) + + @staticmethod + def _libomp_check(tool, formula): + if shutil.which(tool) is None: + return tool + + formulae = subprocess.check_output([tool, 'list']).decode() + if formula not in formulae: + return formula + + return None -if not OPENMP_DISABLED: - libraries.append('gomp') - extra_compile_args.append('-fopenmp') +flags = BuildFlags() module = Extension('clustalo', - sources = ['clustalo.c'], + sources=['clustalo.c'], include_dirs=['/usr/include/clustalo', '/usr/local/include/clustalo'], libraries=libraries, - extra_compile_args=extra_compile_args) + extra_compile_args=flags.compiler, + extra_link_args=flags.linker) setup(name='clustalo', version='0.1.2', From 6a16073a3fee60d9bb41c0995f40b6afecdaf1b0 Mon Sep 17 00:00:00 2001 From: BenTenmann Date: Sun, 2 Jan 2022 12:05:35 +0000 Subject: [PATCH 2/2] fix: add library path --- setup.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 00e30e4..9d71ed4 100644 --- a/setup.py +++ b/setup.py @@ -9,9 +9,6 @@ OPENMP_DISABLED = os.environ.get('OPENMP_DISABLED', False) libraries = ['clustalo', 'stdc++'] -# if not OPENMP_DISABLED: -# libraries.append('gomp') - class BuildFlags: _tools_formulae = { @@ -60,6 +57,7 @@ def _libomp_check(tool, formula): module = Extension('clustalo', sources=['clustalo.c'], include_dirs=['/usr/include/clustalo', '/usr/local/include/clustalo'], + library_dirs=['/usr/local/lib'], libraries=libraries, extra_compile_args=flags.compiler, extra_link_args=flags.linker)