-
Notifications
You must be signed in to change notification settings - Fork 160
/
setup.py
122 lines (105 loc) · 3.74 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
from setuptools import setup, find_packages
from glob import glob
from os import environ as env, path
from pathlib import Path
from Cython.Distutils import build_ext
import os
import sys
import numpy as np
import petsc4py
import rtree
import versioneer
from firedrake_configuration import get_config
try:
from Cython.Distutils.extension import Extension
config = get_config()
complex_mode = config["options"].get("complex", False)
except ImportError:
# No Cython Extension means no complex mode!
from setuptools import Extension
complex_mode = False
try:
from pybind11.setup_helpers import Pybind11Extension
except ImportError:
Pybind11Extension = Extension
def get_petsc_dir():
try:
petsc_dir = os.environ["PETSC_DIR"]
petsc_arch = os.environ.get("PETSC_ARCH", "")
except KeyError:
try:
petsc_dir = os.path.join(os.environ["VIRTUAL_ENV"], "src", "petsc")
petsc_arch = "default"
except KeyError:
sys.exit("""Error: Firedrake venv not active.""")
return (petsc_dir, path.join(petsc_dir, petsc_arch))
cmdclass = versioneer.get_cmdclass()
cmdclass["build_ext"] = build_ext
if "clean" in sys.argv[1:]:
# Forcibly remove the results of Cython.
for dirname, dirs, files in os.walk("firedrake"):
for f in files:
base, ext = os.path.splitext(f)
if (ext in (".c", ".cpp") and base + ".pyx" in files
or ext == ".so"):
os.remove(os.path.join(dirname, f))
cython_compile_time_env = {"COMPLEX": complex_mode}
cythonfiles = [
("dmcommon", ["petsc"]),
("extrusion_numbering", ["petsc"]),
("hdf5interface", ["petsc"]),
("mgimpl", ["petsc"]),
("patchimpl", ["petsc"]),
("spatialindex", None),
("supermeshimpl", ["supermesh", "petsc"]),
]
petsc_dirs = get_petsc_dir()
if os.environ.get("HDF5_DIR"):
petsc_dirs = petsc_dirs + (os.environ.get("HDF5_DIR"), )
include_dirs = [np.get_include(), rtree.finder.get_include()]
petsc_include = [petsc4py.get_include()] + [os.path.join(d, "include") for d in petsc_dirs]
include_dirs += petsc_include
petsc_library = [os.path.join(petsc_dirs[1], "lib")]
dirs = (sys.prefix, *petsc_dirs)
link_args = ["-L%s/lib" % d for d in dirs] + ["-Wl,-rpath,%s/lib" % d for d in dirs]
libspatialindex_so = Path(rtree.core.rt._name).absolute()
link_args += [str(libspatialindex_so)]
link_args += ["-Wl,-rpath,%s" % libspatialindex_so.parent]
extensions = [
Extension(
"firedrake.cython.{}".format(ext),
sources=[os.path.join("firedrake", "cython", "{}.pyx".format(ext))],
include_dirs=include_dirs,
libraries=libs,
extra_link_args=link_args,
cython_compile_time_env=cython_compile_time_env
) for (ext, libs) in cythonfiles
] + [
Pybind11Extension(
name="tinyasm._tinyasm",
sources=sorted(glob("tinyasm/*.cpp")), # Sort source files for reproducibility
include_dirs=petsc_include,
library_dirs=petsc_library,
extra_compile_args=["-std=c++11",],
extra_link_args=["-lpetsc",],
runtime_library_dirs=petsc_library,
)
]
if "CC" not in env:
env["CC"] = "mpicc"
setup(
name="firedrake",
version=versioneer.get_version(),
cmdclass=cmdclass,
description="An automated finite element system.",
long_description="""Firedrake is an automated system for the portable
solution of partial differential equations using the finite element
method (FEM)""",
author="Imperial College London and others",
author_email="[email protected]",
url="http://firedrakeproject.org",
packages=find_packages(),
package_data={"firedrake": ["evaluate.h", "locate.c", "icons/*.png"]},
scripts=glob("scripts/*"),
ext_modules=extensions
)