-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup.py
92 lines (71 loc) · 2.65 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import sys
import subprocess
from setuptools.command.test import test as TestCommand
from setuptools import find_packages
from distutils.core import Extension
from distutils import log
from distutils.core import setup
from Cython.Build import cythonize
import numpy
CODELINES = """
import sys
from distutils.ccompiler import new_compiler
ccompiler = new_compiler()
ccompiler.add_library('gomp')
sys.exit(int(ccompiler.has_function('omp_get_num_threads')))
"""
def check_openmp():
s = subprocess.Popen([sys.executable], stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = s.communicate(CODELINES.encode('utf-8'))
s.wait()
return bool(s.returncode), (stdout, stderr)
def get_extensions():
sources = ["lacosmicx/_lacosmicx.pyx", "lacosmicx/laxutils.c"]
include_dirs = [numpy.get_include(), '.']
libraries = []
ext = Extension(name="_lacosmicx",
sources=sources,
include_dirs=include_dirs,
libraries=libraries,
language="c",
extra_compile_args=['-g', '-O3',
'-funroll-loops', '-ffast-math'])
has_openmp, outputs = check_openmp()
if has_openmp:
ext.extra_compile_args.append('-fopenmp')
ext.extra_link_args = ['-g', '-fopenmp']
else:
log.warn('OpenMP was not found. '
'lacosmicx will be compiled without OpenMP. '
'(Use the "-v" option of setup.py for more details.)')
log.debug(('(Start of OpenMP info)\n'
'compiler stdout:\n{0}\n'
'compiler stderr:\n{1}\n'
'(End of OpenMP info)').format(*outputs))
return [ext]
class PyTest(TestCommand):
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(self.pytest_args)
sys.exit(errno)
setup(name="lacosmicx",
packages=find_packages(),
ext_modules=cythonize(get_extensions()),
tests_require=['pytest'],
cmdclass={'test': PyTest},
version='1.0',
description='Fast Implementation of LA Cosmic',
author='Curtis McCully',
author_email='[email protected]',
url='https://github.com/cmccully/lacosmicx')