-
Notifications
You must be signed in to change notification settings - Fork 29
/
setup.py
124 lines (102 loc) · 4.59 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
113
114
115
116
117
118
119
120
121
122
123
124
# from distutils.core import setup, Extension
try:
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
except ImportError:
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext
from distutils.errors import CompileError
import numpy as np
# First we find out what link/etc. flags we want based on the compiler.
def has_flags(compiler, flags):
"""
This checks whether our C compiler allows for a flag to be passed,
by compiling a small test program.
"""
import tempfile
from distutils.errors import CompileError
with tempfile.NamedTemporaryFile("w", suffix=".c") as f:
f.write("int main (int argc, char **argv) { return 0; }")
try:
compiler.compile([f.name], extra_postargs=flags)
except CompileError:
return False
return True
# Build a build extension class that allows for finer selection of flags.
class BuildExt(build_ext):
# Never check these; they're always added.
# Note that we don't support MSVC here.
compile_flags = {"unix": ["-std=c99", "-w",
"-ffast-math", "-I{:s}".format(np.get_include())]}
def build_extensions(self):
ct = self.compiler.compiler_type
opts = self.compile_flags.get(ct, [])
links = []
# Check for the presence of -fopenmp; if it's there we're good to go!
if has_flags(self.compiler, ["-fopenmp"]):
# Generic case, this is what GCC accepts
opts += ["-fopenmp"]
links += ["-lgomp"]
elif has_flags(self.compiler, ["-Xpreprocessor", "-fopenmp", "-lomp"]):
# Hope that clang accepts this
opts += ["-Xpreprocessor", "-fopenmp", "-lomp"]
links += ["-lomp"]
elif has_flags(self.compiler, ["-Xpreprocessor",
"-fopenmp",
"-lomp",
'-I"$(brew --prefix libomp)/include"',
'-L"$(brew --prefix libomp)/lib"']):
# Case on MacOS where somebody has installed libomp using homebrew
opts += ["-Xpreprocessor",
"-fopenmp",
"-lomp",
'-I"$(brew --prefix libomp)/include"',
'-L"$(brew --prefix libomp)/lib"']
links += ["-lomp"]
else:
raise CompileError("Unable to compile C extensions on your machine, as we can't find OpenMP. "
"If you are on MacOS, try `brew install libomp` and try again. "
"If you are on Windows, please reach out on the GitHub and we can try "
"to find a solution.")
for ext in self.extensions:
ext.extra_compile_args = opts
ext.extra_link_args = links
build_ext.build_extensions(self)
extensions = [
Extension(path, sources=[source])
for path, source in {
"sphviewer/extensions/scene": "sphviewer/extensions/scenemodule.c",
"sphviewer/extensions/render": "sphviewer/extensions/rendermodule.c",
"sphviewer/tools/makehsv": "sphviewer/tools/makehsvmodule.c",
}.items()
]
# __version__ is set in the below file, but use this here to avoid warnings.
__version__ = None
exec(open("sphviewer/version.py").read())
setup(
name="py-sphviewer",
version=__version__,
description="Py-SPHViewer is a framework for rendering particles using the smoothed particle hydrodynamics scheme.",
author="Alejandro Benitez Llambay",
author_email="[email protected]",
url="https://github.com/alejandrobll/py-sphviewer",
packages=["sphviewer", "sphviewer.extensions", "sphviewer.tools"],
include_dirs=[np.get_include()],
requires=["pykdtree", "numpy", "matplotlib","scipy"],
install_requires=["pykdtree", "numpy", "matplotlib","scipy"],
package_data={"sphviewer": ["*.c", "*.txt"]},
cmdclass=dict(build_ext=BuildExt),
ext_modules=extensions,
license="GNU GPL v3",
classifiers=[
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Multimedia :: Graphics",
"Topic :: Multimedia :: Graphics :: 3D Rendering",
"Topic :: Multimedia :: Graphics :: Viewers",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Utilities",
],
keywords="smoothed particle hydrodynamics render particles nbody galaxy formation dark matter sph cosmology movies",
)