1
1
from distutils .core import setup
2
2
from distutils .extension import Extension
3
3
import multiprocessing
4
- # from Cython.Distutils import build_ext
4
+ from tools import glob_files , BuildError , get_user_module_sources
5
5
from Cython .Build import cythonize
6
6
import numpy
7
- import os
8
7
import glob
9
- import re
10
- import sys
11
- #if sys.platform == 'darwin':
12
- # from distutils import sysconfig
13
- # vars = sysconfig.get_config_vars()
14
- # vars['LDSHARED'] = vars['LDSHARED'].replace('-bundle', '-dynamiclib')
15
-
16
- class BuildError (Exception ):
17
- pass
8
+ import os
18
9
10
+ version = '5.0alpha'
19
11
20
- if 'CC' in os .environ :
21
- print ("Using CC={}" .format (os .environ ['CC' ]))
22
- else :
23
- os .environ ["CC" ] = "gcc"
24
- print ("Using CC={} (set by setup.py)" .format (os .environ ['CC' ]))
12
+ # if 'CC' in os.environ:
13
+ # print("Using CC={}".format(os.environ['CC']))
14
+ # else:
15
+ # os.environ["CC"] = "gcc"
16
+ # print("Using CC={} (set by setup.py)".format(os.environ['CC']))
25
17
26
18
MODULE_DIR = os .path .dirname (os .path .abspath (__file__ ))
27
- print (MODULE_DIR )
28
19
SRC_DIR = os .path .join (MODULE_DIR , "fidimag" )
29
20
SUNDIALS_DIR = os .path .join (SRC_DIR , "common" , "sundials" )
30
21
NEB_DIR = os .path .join (SRC_DIR , "common" , "neb" )
@@ -35,43 +26,14 @@ class BuildError(Exception):
35
26
BARYAKHTAR_DIR = os .path .join (MICRO_DIR , "baryakhtar" )
36
27
DEMAG_DIR = os .path .join (SRC_DIR , "common" , "dipolar" )
37
28
USER_DIR = os .path .join (SRC_DIR , "user" )
38
- print (USER_DIR )
39
-
40
29
LOCAL_DIR = os .path .join (MODULE_DIR , "local" )
41
30
INCLUDE_DIR = os .path .join (LOCAL_DIR , "include" )
42
31
LIB_DIR = os .path .join (LOCAL_DIR , "lib" )
43
- print ("LIB_DIR={}" .format (LIB_DIR ))
44
-
45
-
46
- pkg_init_path = os .path .join (
47
- os .path .dirname (__file__ ), 'fidimag' , '__init__.py' )
48
-
49
-
50
- def get_version ():
51
- with open (pkg_init_path ) as f :
52
- for line in f :
53
- m = re .match (r'''__version__\s*=\s*(['"])(.+)\1''' , line .strip ())
54
- if m :
55
- return m .group (2 )
56
- raise Exception ("Couldn't find __version__ in %s" % pkg_init_path )
57
-
58
- version = get_version ()
59
-
60
-
61
- def glob_files (path , excludes , extension = "*.cpp" ):
62
- files = []
63
- for srcfile in glob .glob (os .path .join (path , extension )):
64
- filename = os .path .basename (srcfile )
65
- if not filename in tuple (excludes ):
66
- files .append (srcfile )
67
- return files
68
32
69
33
sources = []
70
34
sources .append (os .path .join (ATOM_DIR , 'clib.pyx' ))
71
35
sources += glob_files (ATOM_DIR , excludes = ["clib.cpp" ])
72
36
73
-
74
-
75
37
common_sources = []
76
38
common_sources .append (os .path .join (COMMON_DIR , 'common_clib.pyx' ))
77
39
common_sources += glob_files (COMMON_DIR , excludes = ["common_clib.cpp" ])
@@ -217,25 +179,9 @@ def glob_files(path, excludes, extension="*.cpp"):
217
179
),
218
180
]
219
181
220
-
221
182
for folder in glob .glob (os .path .join (USER_DIR , '*/' )):
222
183
module_name = folder .split ('/' )[- 2 ]
223
- print ('Found User Module: {}' .format (module_name ))
224
- user_sources = glob .glob (folder + '/*.pyx' )
225
- print ('\t Found Cython sources: {}' .format (user_sources ))
226
-
227
- if len (user_sources ) != 1 :
228
- raise BuildError ("User Modules are only allowed one Cython .pyx file" )
229
-
230
- filename_string = user_sources [0 ].split ('/' )[- 1 ][:- 4 ]
231
- if filename_string != module_name :
232
- print (filename_string , module_name )
233
- raise BuildError ("The Cython source file in {} must match the folder name - i.e. it must be {}.pyx" .format (module_name , module_name ))
234
- cfilename = filename_string + '.cpp'
235
- print (cfilename )
236
- user_sources += glob_files (folder , excludes = [cfilename ])
237
-
238
- print (user_sources )
184
+ user_sources = get_user_module_sources (folder )
239
185
240
186
ext_modules .append (
241
187
Extension ("fidimag.extensions.user.{}" .format (module_name ),
@@ -248,8 +194,11 @@ def glob_files(path, excludes, extension="*.cpp"):
248
194
),
249
195
)
250
196
197
+
198
+
199
+
251
200
nthreads = multiprocessing .cpu_count ()
252
- print ( 'Building with {} threads' . format ( nthreads ))
201
+
253
202
setup (
254
203
name = 'fidimag' ,
255
204
version = version ,
@@ -259,7 +208,7 @@ def glob_files(path, excludes, extension="*.cpp"):
259
208
'fidimag.micro' ,
260
209
'fidimag.extensions' ,
261
210
'fidimag.common' ,
262
- ],
211
+ ],
263
212
ext_modules = cythonize (ext_modules ,
264
213
nthreads = nthreads ,
265
214
compiler_directives = {
0 commit comments