Skip to content

Commit 20abe2c

Browse files
Cleaned setup.py: added rel path to sundials and fftw; using pathlib
1 parent 3e4aaa4 commit 20abe2c

File tree

1 file changed

+18
-50
lines changed

1 file changed

+18
-50
lines changed

setup.py

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,17 @@
1414
sReset = "\x1b[0m"
1515

1616

17-
class BuildError(Exception):
18-
pass
19-
20-
21-
# setup.py requires relative paths:
22-
# MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
23-
MODULE_DIR = os.path.dirname(os.path.relpath(__file__))
24-
INCLUDE_DIR = os.path.join(MODULE_DIR, 'local', 'include')
25-
LIB_DIR = os.path.join(MODULE_DIR, 'local', 'lib')
26-
LIB_DIR64 = os.path.join(MODULE_DIR, 'local', 'lib64')
27-
# INCLUDE_DIR = 'local/include'
28-
# LIB_DIR = 'local/lib'
29-
# LIB_DIR64 = 'local/lib64'
30-
31-
# rpath is the path relative to the compiled shared object files (e.g. clib.so, etc)
32-
# which the dynamic linker looks for the linked libraries (e.g. libsundials_*.so) in.
33-
# We need to set it relatively in order for it to be preserved if the parent directory is moved
34-
# hence why it is a 'relative'(r) path. Here the relative path is with respect to
35-
# the fidimag/fidimag/extensions directory.
36-
RPATH = '../../local/lib'
37-
com_link = ['-Wl,-rpath,{},-rpath,{}'.format(str(LIB_DIR), str(LIB_DIR64)), '-fopenmp']
38-
39-
lib_paths = [LIB_DIR, LIB_DIR64]
40-
# lib_paths = [LIB_DIR, os.path.join(MODULE_DIR, 'native')]
41-
# com_inc = [numpy.get_include(), INCLUDE_DIR, os.path.join(MODULE_DIR, 'native', 'include')]
42-
# com_libs = ['fidimag']
17+
MODULE_DIR = Path(__file__).parent # This should be the abs path
18+
print(MODULE_DIR)
19+
INCLUDE_DIR = MODULE_DIR / 'local/include'
20+
LIB_DIR = MODULE_DIR / 'local/lib'
21+
LIB_DIR64 = MODULE_DIR / 'local/lib64'
22+
23+
# Paths are relative to the extensions directory in: fidimag/extensions/
24+
# So we use "../..". Otherwise, we have to add the LIB folder to LD_LIBRARY_PATH env variable
25+
com_link = ['-Wl,-rpath,../../{},-rpath,../../{}'.format(str(LIB_DIR), str(LIB_DIR64)), '-fopenmp']
26+
lib_paths = [str(LIB_DIR), str(LIB_DIR64)]
4327
com_libs = ['m', 'fftw3_omp', 'fftw3', 'sundials_cvodes', 'sundials_nvecserial', 'sundials_nvecopenmp', 'blas', 'lapack']
44-
# com_args = []
4528
com_args = ['-O3', '-Wno-cpp', '-Wno-unused-function', '-Wall', '-std=c99', '-fopenmp']
4629
com_args_cpp = ['-O3', '-Wno-unused-function', '-Wall', '-std=c++14', '-fopenmp']
4730

@@ -54,14 +37,16 @@ class BuildError(Exception):
5437
# Find .pyx files with extensions (source files)
5538
ROOT_DIR = Path('fidimag')
5639
source_files = [s for s in ROOT_DIR.rglob('*.pyx')] # Paths
57-
print(source_files)
40+
41+
# User extensions are located in the "user" namespace within "extensions"
5842
ext_names = []
5943
for s in source_files:
6044
if 'user' in str(s):
6145
ext_names.append("fidimag.extensions.user." + s.stem)
6246
else:
6347
ext_names.append("fidimag.extensions." + s.stem)
64-
print(ext_names)
48+
49+
com_inc = [numpy.get_include(), str(INCLUDE_DIR)]
6550

6651
ext_modules = []
6752
for i, (module, src) in enumerate(zip(ext_names, source_files)):
@@ -70,35 +55,24 @@ class BuildError(Exception):
7055
if 'fmmlib' in module:
7156
continue
7257

73-
# src is a Path
58+
# "python -m build ..." can use absolute paths
7459
# srcFiles = [str(sF.resolve()) for sF in src.parent.glob('*') # resolve -> absolute paths
7560
# if sF.is_file()
7661
# and sF != src.with_suffix('.c')
7762
# and str(sF).endswith(('.c', '.cpp'))
7863
# ]
7964

65+
# src is a Path
8066
srcFiles = [str(sF) for sF in src.parent.glob('*')
8167
if sF.is_file()
8268
and sF != src.with_suffix('.c')
8369
and sF != src.with_suffix('.cpp')
8470
and str(sF).endswith(('.c', '.cpp', '.pyx'))
8571
]
8672

87-
com_inc = [numpy.get_include(), INCLUDE_DIR]
88-
89-
print(module)
90-
print(com_inc)
91-
print(com_libs)
92-
print(srcFiles)
93-
print(lib_paths)
94-
print(com_link)
95-
# print(com_args_compiler)
96-
for s in srcFiles:
97-
print(s)
98-
print(com_inc)
9973

10074
if 'fmm' in module:
101-
print(sBlue + f'Using cpp for this module' + sReset)
75+
print(sBlue + f'Using cpp for this module: {module}' + sReset)
10276
com_args_compiler = com_args_cpp
10377
lan = 'c++'
10478
else:
@@ -124,15 +98,9 @@ class BuildError(Exception):
12498
os.environ["CC"] = "gcc"
12599
print("Using CC={} (set by setup.py)".format(os.environ['CC']))
126100

127-
USER_DIR = os.path.join("fidimag/user")
128-
129-
130-
pkg_init_path = os.path.join(
131-
os.path.dirname(__file__), 'fidimag', '__init__.py')
132-
133101

134102
def get_version():
135-
with open(pkg_init_path) as f:
103+
with open('fidimag/__init__.py') as f:
136104
for line in f:
137105
m = re.match(r'''__version__\s*=\s*(['"])(.+)\1''', line.strip())
138106
if m:

0 commit comments

Comments
 (0)