1 | """ |
---|
2 | Installation script for SANS models |
---|
3 | """ |
---|
4 | |
---|
5 | import sys |
---|
6 | import os |
---|
7 | import platform |
---|
8 | from numpy.distutils.misc_util import get_numpy_include_dirs |
---|
9 | numpy_incl_path = os.path.join(get_numpy_include_dirs()[0], "numpy") |
---|
10 | |
---|
11 | # Then build and install the modules |
---|
12 | from distutils.core import Extension, setup |
---|
13 | from distutils.command.build_ext import build_ext |
---|
14 | |
---|
15 | # Options to enable OpenMP |
---|
16 | copt = {'msvc': ['/openmp'], |
---|
17 | 'mingw32' : ['-fopenmp'], |
---|
18 | 'unix' : ['-fopenmp']} |
---|
19 | lopt = {'msvc': ['/MANIFEST'], |
---|
20 | 'mingw32' : ['-fopenmp'], |
---|
21 | 'unix' : ['-lgomp']} |
---|
22 | |
---|
23 | class build_ext_subclass( build_ext ): |
---|
24 | def build_extensions(self): |
---|
25 | # Get 64-bitness |
---|
26 | is_64bits = sys.maxsize > 2**32 |
---|
27 | |
---|
28 | c = self.compiler.compiler_type |
---|
29 | print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) |
---|
30 | |
---|
31 | if not (sys.platform=='darwin' and not is_64bits): |
---|
32 | if copt.has_key(c): |
---|
33 | for e in self.extensions: |
---|
34 | e.extra_compile_args = copt[ c ] |
---|
35 | if lopt.has_key(c): |
---|
36 | for e in self.extensions: |
---|
37 | e.extra_link_args = lopt[ c ] |
---|
38 | |
---|
39 | build_ext.build_extensions(self) |
---|
40 | |
---|
41 | # Build the module name |
---|
42 | srcdir = os.path.join("src", "sans", "models", "c_extensions") |
---|
43 | igordir = os.path.join("src","sans", "models", "libigor") |
---|
44 | c_model_dir = os.path.join("src", "sans", "models", "c_models") |
---|
45 | smear_dir = os.path.join("src", "sans", "models", "c_smearer") |
---|
46 | print "Installing SANS models" |
---|
47 | |
---|
48 | |
---|
49 | IGNORED_FILES = ["a.exe", |
---|
50 | "__init__.py" |
---|
51 | ".svn", |
---|
52 | "lineparser.py", |
---|
53 | "run.py", |
---|
54 | "CGaussian.cpp", |
---|
55 | "CLogNormal.cpp", |
---|
56 | "CLorentzian.cpp", |
---|
57 | "CSchulz.cpp", |
---|
58 | "WrapperGenerator.py", |
---|
59 | "wrapping.py" |
---|
60 | ] |
---|
61 | if not os.name=='nt': |
---|
62 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
63 | |
---|
64 | EXTENSIONS = [".c", ".cpp"] |
---|
65 | |
---|
66 | def append_file(file_list, dir_path): |
---|
67 | """ |
---|
68 | Add sources file to sources |
---|
69 | """ |
---|
70 | for f in os.listdir(dir_path): |
---|
71 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
72 | _, ext = os.path.splitext(f) |
---|
73 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
74 | file_list.append(os.path.join(dir_path, f)) |
---|
75 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
76 | not f.startswith("."): |
---|
77 | sub_dir = os.path.join(dir_path, f) |
---|
78 | for new_f in os.listdir(sub_dir): |
---|
79 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
80 | _, ext = os.path.splitext(new_f) |
---|
81 | if ext.lower() in EXTENSIONS and\ |
---|
82 | new_f not in IGNORED_FILES: |
---|
83 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
84 | |
---|
85 | model_sources = [] |
---|
86 | append_file(file_list=model_sources, dir_path=srcdir) |
---|
87 | append_file(file_list=model_sources, dir_path=igordir) |
---|
88 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
89 | smear_sources = [] |
---|
90 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
91 | |
---|
92 | |
---|
93 | smearer_sources = [os.path.join(smear_dir, "smearer.cpp"), |
---|
94 | os.path.join(smear_dir, "smearer_module.cpp")] |
---|
95 | if os.name=='nt': |
---|
96 | smearer_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
97 | |
---|
98 | dist = setup( |
---|
99 | name="sansmodels", |
---|
100 | version = "1.0.0", |
---|
101 | description = "Python module for SANS scattering models", |
---|
102 | author = "SANS/DANSE", |
---|
103 | author_email = "sansdanse@gmail.gov", |
---|
104 | url = "http://danse.us/trac/sans", |
---|
105 | |
---|
106 | # Place this module under the sans package |
---|
107 | #ext_package = "sans", |
---|
108 | |
---|
109 | # Use the pure python modules |
---|
110 | package_dir = {"sans":os.path.join("src", "sans"), |
---|
111 | "sans.models":os.path.join("src", "sans", "models"), |
---|
112 | "sans.models.sans_extension":srcdir, |
---|
113 | }, |
---|
114 | package_data={'sans.models': [os.path.join('media', "*")]}, |
---|
115 | packages = ["sans","sans.models", |
---|
116 | "sans.models.sans_extension",], |
---|
117 | |
---|
118 | ext_modules = [ Extension("sans.models.sans_extension.c_models", |
---|
119 | sources=model_sources, |
---|
120 | include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path], |
---|
121 | ), |
---|
122 | |
---|
123 | # Smearer extension |
---|
124 | Extension("sans.models.sans_extension.smearer", |
---|
125 | sources = smearer_sources, |
---|
126 | include_dirs=[igordir, smear_dir, numpy_incl_path], |
---|
127 | ), |
---|
128 | |
---|
129 | Extension("sans.models.sans_extension.smearer2d_helper", |
---|
130 | sources = [os.path.join(smear_dir, |
---|
131 | "smearer2d_helper_module.cpp"), |
---|
132 | os.path.join(smear_dir, "smearer2d_helper.cpp"),], |
---|
133 | include_dirs=[smear_dir,numpy_incl_path], |
---|
134 | ) |
---|
135 | ], |
---|
136 | cmdclass = {'build_ext': build_ext_subclass } |
---|
137 | ) |
---|
138 | |
---|