-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsetup.py
More file actions
127 lines (105 loc) · 4.32 KB
/
setup.py
File metadata and controls
127 lines (105 loc) · 4.32 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
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
from setuptools import setup
from setuptools import Extension
import multiprocessing
from Cython.Build import cythonize
import numpy
import os
import glob
import re
from pathlib import Path
sYellow = "\x1b[33;49m"
sBlue = "\x1b[34;49m"
sRed = "\x1b[31;49m"
sReset = "\x1b[0m"
ABS_MODULE_DIR = Path(__file__).parent # This should be the abs path
MODULE_DIR = Path('.') # This should be the rel path (setup.py requires rel paths for pip -e)
print(MODULE_DIR)
INCLUDE_DIR = ABS_MODULE_DIR / 'local/include'
# Use absolute paths for the sundials/fftw libs:
LIB_DIR = ABS_MODULE_DIR / 'local/lib'
LIB_DIR64 = ABS_MODULE_DIR / 'local/lib64'
# rpath: run-time search path for the sundials (cvode) and fftw library objects
com_link = ['-Wl,-rpath,{},-rpath,{}'.format(str(LIB_DIR), str(LIB_DIR64)), '-fopenmp']
lib_paths = [str(LIB_DIR), str(LIB_DIR64)]
com_libs = ['m', 'fftw3_omp', 'fftw3', 'sundials_core', 'sundials_cvodes', 'sundials_nvecserial', 'sundials_nvecopenmp', 'blas', 'lapack']
com_args = ['-O3', '-Wno-cpp', '-Wno-unused-function', '-Wall', '-std=c99', '-fopenmp']
com_args_cpp = ['-O3', '-Wno-unused-function', '-Wall', '-std=c++14', '-fopenmp']
# Find all .pyx files with extensions (source files) -> relative paths
ROOT_DIR = MODULE_DIR / 'fidimag'
source_files = [s for s in ROOT_DIR.rglob('*.pyx')] # Paths
# User extensions are located in the "user" namespace within "extensions"
ext_names = []
for s in source_files:
if 'user' in str(s):
ext_names.append("fidimag.extensions.user." + s.stem)
else:
ext_names.append("fidimag.extensions." + s.stem)
com_inc = [numpy.get_include(), str(INCLUDE_DIR)]
if 'SUNDIALS_INC' in os.environ:
com_inc.append(os.environ['SUNDIALS_INC'])
if 'FFTW_INC' in os.environ:
com_inc.append(os.environ['FFTW_INC'])
ext_modules = []
for i, (module, src) in enumerate(zip(ext_names, source_files)):
print(sYellow + f"Compiling module {module}" + sReset)
if 'fmmlib' in module:
continue
# "python -m build ..." can use absolute paths
# srcFiles = [str(sF.resolve()) for sF in src.parent.glob('*') # resolve -> absolute paths
# if sF.is_file()
# and sF != src.with_suffix('.c')
# and str(sF).endswith(('.c', '.cpp'))
# ]
# src is a Path
srcFiles = [str(sF) for sF in src.parent.glob('*')
if sF.is_file()
and sF != src.with_suffix('.c')
and sF != src.with_suffix('.cpp')
and str(sF).endswith(('.c', '.cpp', '.pyx'))
]
if 'fmm' in module:
print(sBlue + f'Using cpp for this module: {module}' + sReset)
com_args_compiler = com_args_cpp
lan = 'c++'
else:
com_args_compiler = com_args
lan = 'c'
ext_modules.append(Extension(module,
sources=srcFiles,
include_dirs=com_inc,
libraries=com_libs,
library_dirs=lib_paths,
runtime_library_dirs=lib_paths,
extra_compile_args=com_args_compiler,
extra_link_args=com_link,
language=lan
)
)
if 'CC' in os.environ:
print("Using CC={}".format(os.environ['CC']))
else:
os.environ["CC"] = "gcc"
print("Using CC={} (set by setup.py)".format(os.environ['CC']))
def get_version():
with open('fidimag/__init__.py') as f:
for line in f:
m = re.match(r'''__version__\s*=\s*(['"])(.+)\1''', line.strip())
if m:
return m.group(2)
raise Exception("Couldn't find __version__ in %s" % pkg_init_path)
nthreads = 0 # Disabled parallel compilation due to Python 3.14 multiprocessing issues (0 = no multiprocessing)
print(sYellow + f'Building with {nthreads} threads' + sReset)
setup(
name='fidimag',
version=get_version(),
packages=['fidimag',
'fidimag.atomistic',
'fidimag.micro',
'fidimag.extensions',
'fidimag.common',
],
ext_modules=cythonize(ext_modules,
nthreads=nthreads,
compiler_directives={'linetrace': True, 'language_level' : "3"}
),
)