-
Notifications
You must be signed in to change notification settings - Fork 17
/
setup.py
113 lines (98 loc) · 3.31 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import numpy, os, sys, os.path, tempfile, subprocess, shutil
import os, sys, re
from setuptools import setup, Extension
from Cython.Build import cythonize
import Cython.Compiler.Options
Cython.Compiler.Options.annotate=True
def checkOpenmpSupport():
'''
Function to check openMP support
Adapted from https://stackoverflow.com/questions/16549893/
'''
ompTest = \
r'''
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf('Thread %d, Total number of threads %d\n', omp_get_thread_num(), omp_get_num_threads());
}
'''
tmpdir = tempfile.mkdtemp()
curdir = os.getcwd()
os.chdir(tmpdir)
filename = r'test.c'
try:
with open(filename, 'w') as file:
file.write(ompTest)
with open(os.devnull, 'w') as fnull:
result = subprocess.call(['cc', '-fopenmp', filename],
stdout=fnull, stderr=fnull)
except:
print('Failed to test for OpenMP support. Assuming unavailability');
result = -1;
os.chdir(curdir)
shutil.rmtree(tmpdir)
if result == 0:
return True
else:
return False
### Checking for openMP support
if checkOpenmpSupport() == True:
ompArgs = ['-fopenmp']
else:
ompArgs = None
with open("README.md", "r") as fh:
long_description = fh.read()
### Setting version names
cwd = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(cwd, 'pystokes', '__init__.py')) as fp:
for line in fp:
m = re.search(r'^\s*__version__\s*=\s*([\'"])([^\'"]+)\1\s*$', line)
if m:
version = m.group(2)
break
else:
raise RuntimeError('Unable to find own __version__ string')
### Extensions to be compiled
extension1 = Extension('pystokes/*', ['pystokes/*.pyx'],
include_dirs=[numpy.get_include()],
extra_compile_args=ompArgs,
extra_link_args=ompArgs,
)
extension2 = Extension('pystokes/phoretic/*', ['pystokes/phoretic/*.pyx'],
include_dirs=[numpy.get_include()],
extra_compile_args=ompArgs,
extra_link_args=ompArgs,
)
setup(
name='pystokes',
version=version,
url='https://github.com/rajeshrinet/pystokes',
author = 'The PyStokes team',
author_email = '[email protected]',
license='MIT',
description='Phoresis and Stokesian hydrodynamics in Python',
long_description=long_description,
long_description_content_type='text/markdown',
platforms='tested on macOS, windows, and LINUX',
ext_modules=cythonize([extension1, extension2],
compiler_directives={'language_level': sys.version_info[0],
'linetrace': True},
),
libraries=[],
packages=['pystokes', 'pystokes/phoretic'],
package_data={'pystokes': ['*.pxd'], 'pystokes/phoretic': ['*.pxd']},
include_package_data=True,
setup_requires=['wheel'],
classifiers=[
'License :: OSI Approved :: MIT License',
"Operating System :: OS Independent",
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
],
install_requires=['cython','numpy','scipy','matplotlib']
)