Skip to content

Commit 5527fdf

Browse files
authored
Merge pull request #1 from joachimwolff/develop
Replace setuptools with distutils.core to enable openmp
2 parents 64b6222 + 68c3f4e commit 5527fdf

File tree

1 file changed

+20
-76
lines changed

1 file changed

+20
-76
lines changed

setup.py

Lines changed: 20 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,38 @@
1-
#The template of this setup.py is taken from pybind github (https://github.com/pybind/python_example)
2-
from setuptools import setup, Extension
31
from setuptools.command.build_ext import build_ext
2+
from distutils.core import setup, Extension
43
import sys
5-
import setuptools
64
from sysconfig import get_config_var, get_paths
5+
import logging
76

7+
__version__ = '0.0.1dev'
88

9-
__version__ = '0.0.0'
109

11-
def get_include(): #TODO
12-
info = get_paths()
13-
Eigen_path = info['include']+'/../eigen3'
14-
return Eigen_path
10+
def get_include(): # TODO
11+
info = get_paths()
12+
Eigen_path = '/'.join(info['include'].split('/')[:-1])
13+
Eigen_path += '/eigen3'
14+
return Eigen_path
1515

16-
KR_module = [
17-
Extension(
18-
'KRBalancing',
19-
['src/KRBalancing.cpp'],
20-
include_dirs=[
21-
# Path to eigen3 headers
22-
get_include(),
23-
],
24-
language='c++',
25-
extra_compile_args=["-fopenmp"],
26-
extra_link_args=["-fopenmp"]
27-
)
28-
]
2916

17+
sources_list = ['src/KRBalancing.cpp']
3018

31-
# As of Python 3.6, CCompiler has a `has_flag` method.
32-
# cf http://bugs.python.org/issue26689
33-
def has_flag(compiler, flagname):
34-
"""Return a boolean indicating whether a flag name is supported on
35-
the specified compiler.
36-
"""
37-
import tempfile
38-
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
39-
f.write('int main (int argc, char **argv) { return 0; }')
40-
try:
41-
compiler.compile([f.name], extra_postargs=[flagname])
42-
except setuptools.distutils.errors.CompileError:
43-
return False
44-
return True
19+
kr_module = Extension('KRBalancing',
20+
sources=sources_list,
21+
include_dirs=[
22+
# Path to eigen3 headers
23+
get_include()
24+
],
25+
extra_link_args=["-lgomp", "-lm", "-lrt"],
26+
extra_compile_args=["-fopenmp", "-std=c++11"]
27+
)
4528

4629

47-
def cpp_flag(compiler):
48-
"""Return the -std=c++[11/14] compiler flag.
49-
The c++14 is prefered over c++11 (when it is available).
50-
"""
51-
if has_flag(compiler, '-std=c++14'):
52-
return '-std=c++14'
53-
elif has_flag(compiler, '-std=c++11'):
54-
return '-std=c++11'
55-
else:
56-
raise RuntimeError('Unsupported compiler -- at least C++11 support '
57-
'is needed!')
58-
59-
60-
class BuildExt(build_ext):
61-
"""A custom build extension for adding compiler-specific options."""
62-
c_opts = {
63-
'msvc': ['/EHsc'],
64-
'unix': [],
65-
}
66-
67-
if sys.platform == 'darwin':
68-
c_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7']
69-
70-
def build_extensions(self):
71-
ct = self.compiler.compiler_type
72-
opts = self.c_opts.get(ct, [])
73-
if ct == 'unix':
74-
opts.append('-DVERSION_INFO="%s" ' % self.distribution.get_version())
75-
opts.append(cpp_flag(self.compiler))
76-
if has_flag(self.compiler, '-fvisibility=hidden'):
77-
opts.append('-fvisibility=hidden')
78-
elif ct == 'msvc':
79-
opts.append('/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version())
80-
for ext in self.extensions:
81-
ext.extra_compile_args = opts
82-
build_ext.build_extensions(self)
83-
8430
setup(
8531
name='KRBalancing',
8632
version=__version__,
8733
author='Leily Rabbani',
8834
author_email='[email protected]',
8935
description='A c++ extension for python to balance a matrix using KR method',
90-
ext_modules=KR_module,
91-
install_requires=['pybind11>=2.2'],
92-
cmdclass={'build_ext': BuildExt},
93-
zip_safe=False,
36+
ext_modules=[kr_module],
37+
install_requires=['pybind11>=2.2']
9438
)

0 commit comments

Comments
 (0)