This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
setup.py
151 lines (131 loc) · 5.41 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env python
#
# This file is part of PyOP2
#
# PyOP2 is Copyright (c) 2012, Imperial College London and
# others. Please see the AUTHORS file in the main source directory for
# a full list of copyright holders. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * The name of Imperial College London or that of other
# contributors may not be used to endorse or promote products
# derived from this software without specific prior written
# permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTERS
# ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.
from setuptools import setup, Extension
from glob import glob
from os import environ as env
import sys
import numpy as np
import petsc4py
import versioneer
import os
def get_petsc_dir():
try:
arch = '/' + env.get('PETSC_ARCH', '')
dir = env['PETSC_DIR']
return (dir, dir + arch)
except KeyError:
try:
import petsc
return (petsc.get_petsc_dir(), )
except ImportError:
sys.exit("""Error: Could not find PETSc library.
Set the environment variable PETSC_DIR to your local PETSc base
directory or install PETSc from PyPI: pip install petsc""")
cmdclass = versioneer.get_cmdclass()
_sdist = cmdclass['sdist']
if "clean" in sys.argv[1:]:
# Forcibly remove the results of Cython.
for dirname, dirs, files in os.walk("pyop2"):
for f in files:
base, ext = os.path.splitext(f)
if ext in (".c", ".cpp", ".so") and base + ".pyx" in files:
os.remove(os.path.join(dirname, f))
# If Cython is available, built the extension module from the Cython source
try:
from Cython.Distutils import build_ext
cmdclass['build_ext'] = build_ext
sparsity_sources = ['pyop2/sparsity.pyx']
# Else we require the Cython-compiled .c file to be present and use that
# Note: file is not in revision control but needs to be included in distributions
except ImportError:
sparsity_sources = ['pyop2/sparsity.c']
sources = sparsity_sources
from os.path import exists
if not all([exists(f) for f in sources]):
raise ImportError("Installing from source requires Cython")
install_requires = [
'decorator',
'mpi4py',
'numpy>=1.6',
'pytools',
]
version = sys.version_info[:2]
if version < (3, 6):
raise ValueError("Python version >= 3.6 required")
test_requires = [
'flake8>=2.1.0',
'pytest>=2.3',
]
petsc_dirs = get_petsc_dir()
numpy_includes = [np.get_include()]
includes = numpy_includes + [petsc4py.get_include()]
includes += ["%s/include" % d for d in petsc_dirs]
if 'CC' not in env:
env['CC'] = "mpicc"
class sdist(_sdist):
def run(self):
# Make sure the compiled Cython files in the distribution are up-to-date
from Cython.Build import cythonize
cythonize(sparsity_sources, language="c", include_path=includes)
_sdist.run(self)
cmdclass['sdist'] = sdist
setup(name='PyOP2',
version=versioneer.get_version(),
description='Framework for performance-portable parallel computations on unstructured meshes',
author='Imperial College London and others',
author_email='[email protected]',
url='https://github.com/OP2/PyOP2/',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: C',
'Programming Language :: Cython',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
],
install_requires=install_requires + test_requires,
packages=['pyop2', 'pyop2.codegen', 'pyop2.types'],
package_data={
'pyop2': ['assets/*', '*.h', '*.pxd', '*.pyx', 'codegen/c/*.c']},
scripts=glob('scripts/*'),
cmdclass=cmdclass,
ext_modules=[Extension('pyop2.sparsity', sparsity_sources,
include_dirs=['pyop2'] + includes, language="c",
libraries=["petsc"],
extra_link_args=(["-L%s/lib" % d for d in petsc_dirs]
+ ["-Wl,-rpath,%s/lib" % d for d in petsc_dirs]))])