@@ -19,7 +19,8 @@ class BuildError(Exception):
1919
2020
2121# setup.py requires relative paths:
22- MODULE_DIR = os .path .dirname (os .path .abspath (__file__ ))
22+ # MODULE_DIR = os.path.dirname(os.path.abspath(__file__))
23+ MODULE_DIR = os .path .dirname (os .path .relpath (__file__ ))
2324INCLUDE_DIR = os .path .join (MODULE_DIR , 'local' , 'include' )
2425LIB_DIR = os .path .join (MODULE_DIR , 'local' , 'lib' )
2526LIB_DIR64 = os .path .join (MODULE_DIR , 'local' , 'lib64' )
@@ -66,23 +67,35 @@ class BuildError(Exception):
6667for i , (module , src ) in enumerate (zip (ext_names , source_files )):
6768 print (sYellow + f"Compiling module { module } " + sReset )
6869
70+ if 'fmmlib' in module :
71+ continue
72+
6973 # src is a Path
70- srcFiles = [str (sF ) for sF in src .parent .glob ('*' ) if sF .is_file ()
71- and sF != src .with_suffix ('.c' )
72- and str (sF ).endswith (('.c' , '.cpp' ))
74+ # srcFiles = [str(sF.resolve()) for sF in src.parent.glob('*') # resolve -> absolute paths
75+ # if sF.is_file()
76+ # and sF != src.with_suffix('.c')
77+ # and str(sF).endswith(('.c', '.cpp'))
78+ # ]
79+
80+ srcFiles = [str (sF ) for sF in src .parent .glob ('*' )
81+ if sF .is_file ()
82+ and sF != src .with_suffix ('.c' )
83+ and sF != src .with_suffix ('.cpp' )
84+ and str (sF ).endswith (('.c' , '.cpp' , '.pyx' ))
7385 ]
7486
75- com_inc = [numpy .get_include (), INCLUDE_DIR ] + [ str ( src . parent )]
87+ com_inc = [numpy .get_include (), INCLUDE_DIR ]
7688
77- # print(module)
78- # print(com_inc)
79- # print(com_libs)
80- # print(srcFiles)
81- # print(lib_paths)
82- # print(com_link)
89+ print (module )
90+ print (com_inc )
91+ print (com_libs )
92+ print (srcFiles )
93+ print (lib_paths )
94+ print (com_link )
8395 # print(com_args_compiler)
8496 for s in srcFiles :
8597 print (s )
98+ print (com_inc )
8699
87100 if 'fmm' in module :
88101 print (sBlue + f'Using cpp for this module' + sReset )
@@ -98,8 +111,8 @@ class BuildError(Exception):
98111 libraries = com_libs ,
99112 library_dirs = lib_paths ,
100113 runtime_library_dirs = lib_paths ,
101- extra_link_args = com_link ,
102114 extra_compile_args = com_args_compiler ,
115+ extra_link_args = com_link ,
103116 language = lan
104117 )
105118 )
@@ -111,26 +124,7 @@ class BuildError(Exception):
111124 os .environ ["CC" ] = "gcc"
112125 print ("Using CC={} (set by setup.py)" .format (os .environ ['CC' ]))
113126
114- # # setup.py requires relative paths:
115- # MODULE_DIR = os.path.dirname(os.path.relpath(__file__))
116- # SRC_DIR = os.path.join(MODULE_DIR, "fidimag")
117- # #
118- # SUNDIALS_DIR = os.path.join(SRC_DIR, "common", "sundials")
119- # NEB_DIR = os.path.join(SRC_DIR, "common", "neb")
120- # NEBM_DIR = os.path.join(SRC_DIR, "common", "neb_method")
121- # ATOM_DIR = os.path.join(SRC_DIR, "atomistic", "lib")
122- # COMMON_DIR = os.path.join(SRC_DIR, "common", "lib")
123- # MICRO_DIR = os.path.join(SRC_DIR, "micro", "lib")
124- # BARYAKHTAR_DIR = os.path.join(MICRO_DIR, "baryakhtar")
125- # DEMAG_DIR = os.path.join(SRC_DIR, "common", "dipolar")
126- #
127- # FMMLIB_DIR = os.path.join(SRC_DIR, "atomistic", "fmmlib")
128127USER_DIR = os .path .join ("fidimag/user" )
129- #
130- # LOCAL_DIR = os.path.join(MODULE_DIR, "local")
131- # INCLUDE_DIR = os.path.join(LOCAL_DIR, "include")
132- # LIB_DIR = os.path.join(LOCAL_DIR, "lib")
133- # LIB_DIR64 = os.path.join(LOCAL_DIR, "lib64")
134128
135129
136130pkg_init_path = os .path .join (
@@ -146,211 +140,6 @@ def get_version():
146140 raise Exception ("Couldn't find __version__ in %s" % pkg_init_path )
147141
148142
149- def glob_cfiles (path , excludes , extension = "*.c" ):
150- cfiles = []
151- for cfile in glob .glob (os .path .join (path , extension )):
152- filename = os .path .basename (cfile )
153- if filename not in tuple (excludes ):
154- cfiles .append (cfile )
155- return cfiles
156- #
157- #
158- # sources = []
159- # sources.append(os.path.join(ATOM_DIR, 'clib.pyx'))
160- # sources += glob_cfiles(ATOM_DIR, excludes=["clib.c"])
161- #
162- # common_sources = []
163- # common_sources.append(os.path.join(COMMON_DIR, 'common_clib.pyx'))
164- # common_sources += glob_cfiles(COMMON_DIR, excludes=["common_clib.c"])
165- #
166- # cvode_sources = []
167- # cvode_sources.append(os.path.join(SUNDIALS_DIR, 'cvode.pyx'))
168- # cvode_sources += glob_cfiles(SUNDIALS_DIR, excludes=["cvode.c"])
169- #
170- # baryakhtar_sources = []
171- # baryakhtar_sources.append(os.path.join(BARYAKHTAR_DIR, 'baryakhtar_clib.pyx'))
172- # baryakhtar_sources += glob_cfiles(BARYAKHTAR_DIR,
173- # excludes=["baryakhtar_clib.c"])
174- #
175- # micro_sources = []
176- # micro_sources.append(os.path.join(MICRO_DIR, 'micro_clib.pyx'))
177- # micro_sources += glob_cfiles(MICRO_DIR, excludes=["micro_clib.c"])
178- #
179- # nebm_sources = []
180- # nebm_sources.append(os.path.join(NEBM_DIR, "nebm_clib.pyx"))
181- # nebm_sources += glob_cfiles(NEBM_DIR, excludes=["nebm_clib.c"])
182- #
183- # dipolar_sources = []
184- # dipolar_sources.append(os.path.join(DEMAG_DIR, 'dipolar.pyx'))
185- # dipolar_sources += glob_cfiles(DEMAG_DIR, excludes=["dipolar.c"])
186- #
187- # fmm_sources = []
188- # fmm_sources.append(os.path.join(FMMLIB_DIR, 'fmm.pyx'))
189- # fmm_sources += glob_cfiles(FMMLIB_DIR, excludes=["fmm.cpp"], extension="*.cpp")
190- # fmm_sources += glob_cfiles(FMMLIB_DIR, excludes=[], extension="*.c")
191- #
192- #
193- #
194- # com_libs = ['m', 'fftw3_omp', 'fftw3', 'sundials_cvodes',
195- # 'sundials_nvecserial', 'sundials_nvecopenmp', 'blas', 'lapack']
196- #
197- #
198- # com_args = ['-O3', '-Wno-cpp', '-Wno-unused-function', '-Wall']
199- #
200- #
201- #
202- # # rpath is the path relative to the compiled shared object files (e.g. clib.so, etc)
203- # # which the dynamic linker looks for the linked libraries (e.g. libsundials_*.so) in.
204- # # We need to set it relatively in order for it to be preserved if the parent directory is moved
205- # # hence why it is a 'relative'(r) path. Here the relative path is with respect to
206- # # the fidimag/fidimag/extensions directory.
207- # RPATH = '../../local/lib'
208- # com_link = ['-Wl,-rpath,{},-rpath,{}'.format(LIB_DIR, LIB_DIR64)]
209- # lib_paths = [LIB_DIR, LIB_DIR64]
210- #
211- #
212- # com_args.append('-fopenmp')
213- # com_link.append('-fopenmp')
214- #
215- #
216- # com_inc = [numpy.get_include(), INCLUDE_DIR]
217- #
218- # if 'SUNDIALS_DIR' in os.environ:
219- # lib_paths.append(os.environ['SUNDIALS_DIR'])
220- # com_inc.append(os.environ['SUNDIALS_INC'])
221- #
222- # if 'FFTW_DIR' in os.environ:
223- # lib_paths.append(os.environ['FFTW_DIR'])
224- # com_inc.append(os.environ['FFTW_INC'])
225- #
226- # com_args_cpp = com_args.copy()
227- # com_args_cpp.append('-std=c++14')
228- #
229- # com_args.append('-std=c99')
230- # com_inc_cpp = com_inc.copy()
231- # com_link_cpp = com_link.copy()
232- # com_libs_cpp = com_libs.copy()
233- # lib_paths_cpp = lib_paths.copy()
234- #
235- # ext_modules = [
236- # Extension("fidimag.extensions.clib",
237- # sources=sources,
238- # include_dirs=com_inc,
239- # libraries=com_libs,
240- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
241- # extra_compile_args=com_args,
242- # extra_link_args=com_link,
243- # ),
244- # Extension("fidimag.extensions.common_clib",
245- # sources=common_sources,
246- # include_dirs=com_inc,
247- # libraries=com_libs,
248- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
249- # extra_compile_args=com_args,
250- # extra_link_args=com_link,
251- # ),
252- # Extension("fidimag.extensions.cvode",
253- # sources=cvode_sources,
254- # include_dirs=com_inc,
255- # libraries=com_libs,
256- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
257- # extra_compile_args=com_args,
258- # extra_link_args=com_link,
259- # ),
260- # Extension("fidimag.extensions.baryakhtar_clib",
261- # sources=baryakhtar_sources,
262- # include_dirs=com_inc,
263- # libraries=com_libs,
264- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
265- # extra_compile_args=com_args,
266- # extra_link_args=com_link,
267- # ),
268- # Extension("fidimag.extensions.micro_clib",
269- # sources=micro_sources,
270- # include_dirs=com_inc,
271- # libraries=com_libs,
272- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
273- # extra_compile_args=com_args,
274- # extra_link_args=com_link,
275- # ),
276- # Extension("fidimag.extensions.nebm_clib",
277- # sources=nebm_sources,
278- # include_dirs=com_inc,
279- # libraries=com_libs,
280- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
281- # extra_compile_args=com_args,
282- # extra_link_args=com_link,
283- # ),
284- # Extension("fidimag.extensions.cvode",
285- # sources=cvode_sources,
286- # include_dirs=com_inc,
287- # libraries=com_libs,
288- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
289- # extra_compile_args=com_args,
290- # extra_link_args=com_link,
291- # ),
292- # Extension("fidimag.extensions.baryakhtar_clib",
293- # sources=baryakhtar_sources,
294- # include_dirs=com_inc,
295- # libraries=com_libs,
296- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
297- # extra_compile_args=com_args,
298- # extra_link_args=com_link,
299- # ),
300- # Extension("fidimag.extensions.micro_clib",
301- # sources=micro_sources,
302- # include_dirs=com_inc,
303- # libraries=com_libs,
304- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
305- # extra_compile_args=com_args,
306- # extra_link_args=com_link,
307- # ),
308- # Extension("fidimag.extensions.dipolar",
309- # sources=dipolar_sources,
310- # include_dirs=com_inc,
311- # libraries=com_libs,
312- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
313- # extra_compile_args=com_args,
314- # extra_link_args=com_link,
315- # ),
316- # Extension("fidimag.extensions.fmm",
317- # sources=fmm_sources,
318- # include_dirs=com_inc_cpp,
319- # libraries=com_libs_cpp,
320- # library_dirs=lib_paths_cpp, runtime_library_dirs=lib_paths_cpp,
321- # extra_compile_args=com_args_cpp,
322- # extra_link_args=com_link_cpp,
323- # language="c++",
324- # )
325- # ]
326-
327-
328- # for folder in glob.glob(os.path.join(USER_DIR, '*/')):
329- # module_name = folder.split('/')[-2]
330- # print(sYellow + f'Found User Module: {module_name}' + sReset)
331- # user_sources = glob.glob(folder + '/*.pyx')
332- # if len(user_sources) != 1:
333- # raise BuildError("User Modules are only allowed one Cython .pyx file")
334- #
335- # filename_string = user_sources[0].split('/')[-1][:-4]
336- # if filename_string != module_name:
337- # print(filename_string, module_name)
338- # raise BuildError("The Cython source file in {} must match the folder name - i.e. it must be {}.pyx".format(module_name, module_name))
339- # cfilename = filename_string + '.c'
340- # user_sources += glob_cfiles(folder, excludes=[cfilename])
341- #
342- #
343- # ext_modules.append(
344- # Extension("fidimag.extensions.user.{}".format(module_name),
345- # sources=user_sources,
346- # include_dirs=com_inc,
347- # libraries=com_libs,
348- # library_dirs=lib_paths, runtime_library_dirs=lib_paths,
349- # extra_compile_args=com_args,
350- # extra_link_args=com_link,
351- # ),
352- # )
353-
354143nthreads = multiprocessing .cpu_count ()
355144print (sYellow + f'Building with { nthreads } threads' + sReset )
356145setup (
0 commit comments