-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.py
More file actions
71 lines (64 loc) · 2.44 KB
/
setup.py
File metadata and controls
71 lines (64 loc) · 2.44 KB
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
from setuptools import Extension, setup, find_packages
import os
import sys
import os.path
from Cython.Build import cythonize
import shutil
import subprocess
def get_env_or_exit(name):
try:
value = os.environ[name]
except KeyError:
sys.exit('Environment variable %s not set. Aborting' % name)
return value
# Removed [-1] from the end
PDC_DIR = os.path.join(*os.path.split(get_env_or_exit("PDC_DIR")))
MERCURY_DIR = get_env_or_exit("MERCURY_DIR")
path = shutil.which('mpicc')
if not path:
print("mpicc not found on PATH. Attempting to compile without MPI support.")
mpi_build_args = []
mpi_link_args = []
else:
# Try OpenMPI style first
try:
compile_output = subprocess.check_output(['mpicc', '--showme:compile'], stderr=subprocess.PIPE, text=True)
link_output = subprocess.check_output(['mpicc', '--showme:link'], stderr=subprocess.PIPE, text=True)
print("Compiling with openmpi")
mpi_build_args = compile_output.strip().split()
mpi_link_args = link_output.strip().split()
except (subprocess.CalledProcessError, FileNotFoundError):
# Try MPICH style
try:
compile_output = subprocess.check_output(['mpicc', '-compile_info'], stderr=subprocess.PIPE, text=True)
link_output = subprocess.check_output(['mpicc', '-link_info'], stderr=subprocess.PIPE, text=True)
print("Compiling with mpich")
mpi_build_args = [arg for arg in compile_output.strip().split() if arg not in ('-compile_info', 'gcc')]
mpi_link_args = [arg for arg in link_output.strip().split() if arg not in ('-link_info', 'gcc')]
except (subprocess.CalledProcessError, FileNotFoundError):
print("mpicc is neither openmpi or mpich. Attempting to compile without MPI support.")
mpi_build_args = []
mpi_link_args = []
# Removed "install"
extension = Extension(
"*",
["pdc/*.pyx"],
libraries=["pdc"],
library_dirs=[os.path.join(PDC_DIR, "lib")],
include_dirs=[
os.path.join(PDC_DIR, "include"),
os.path.join(MERCURY_DIR, "include"),
],
extra_compile_args=mpi_build_args,
extra_link_args=mpi_link_args
)
#extension.cython_directives = {'language_level': "3"}
version_file = open('version.txt', 'r')
version = version_file.read().strip()
version_file.close()
setup(
name='PDCpy',
version=version,
ext_modules=cythonize(extension, language_level=3),
zip_safe=False,
)