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 | # Options for non-openmp builds. MSVC always needs MANIFEST |
---|
24 | if sys.argv[-1] == "-nomp": |
---|
25 | copt = {} |
---|
26 | lopt = {'msvc': ['/MANIFEST']} |
---|
27 | |
---|
28 | class build_ext_subclass( build_ext ): |
---|
29 | def build_extensions(self): |
---|
30 | # Get 64-bitness |
---|
31 | if sys.version_info >= (2, 6): |
---|
32 | is_64bits = sys.maxsize > 2**32 |
---|
33 | else: |
---|
34 | # 'sys.maxsize' and 64bit: Not supported for python2.5 |
---|
35 | is_64bits = False |
---|
36 | c = self.compiler.compiler_type |
---|
37 | print "Compiling with %s (64bit=%s)" % (c, str(is_64bits)) |
---|
38 | |
---|
39 | if not (sys.platform=='darwin' and not is_64bits): |
---|
40 | if copt.has_key(c): |
---|
41 | for e in self.extensions: |
---|
42 | e.extra_compile_args = copt[ c ] |
---|
43 | if lopt.has_key(c): |
---|
44 | for e in self.extensions: |
---|
45 | e.extra_link_args = lopt[ c ] |
---|
46 | |
---|
47 | build_ext.build_extensions(self) |
---|
48 | |
---|
49 | # Build the module name |
---|
50 | srcdir = os.path.join("src", "include") |
---|
51 | igordir = os.path.join("src", "libigor") |
---|
52 | c_model_dir = os.path.join("src", "c_models") |
---|
53 | smear_dir = os.path.join("src", "c_smearer") |
---|
54 | wrapper_dir = os.path.join("src", "python_wrapper") |
---|
55 | print "Installing SANS models" |
---|
56 | |
---|
57 | sys.path.append(wrapper_dir) |
---|
58 | from wrapping import generate_wrappers |
---|
59 | generate_wrappers(header_dir=srcdir, |
---|
60 | output_dir=os.path.join("src", "sans", "models"), |
---|
61 | c_wrapper_dir=wrapper_dir) |
---|
62 | |
---|
63 | IGNORED_FILES = [".svn"] |
---|
64 | if not os.name=='nt': |
---|
65 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
66 | |
---|
67 | EXTENSIONS = [".c", ".cpp"] |
---|
68 | |
---|
69 | def append_file(file_list, dir_path): |
---|
70 | """ |
---|
71 | Add sources file to sources |
---|
72 | """ |
---|
73 | for f in os.listdir(dir_path): |
---|
74 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
75 | _, ext = os.path.splitext(f) |
---|
76 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
77 | file_list.append(os.path.join(dir_path, f)) |
---|
78 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
79 | not f.startswith("."): |
---|
80 | sub_dir = os.path.join(dir_path, f) |
---|
81 | for new_f in os.listdir(sub_dir): |
---|
82 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
83 | _, ext = os.path.splitext(new_f) |
---|
84 | if ext.lower() in EXTENSIONS and\ |
---|
85 | new_f not in IGNORED_FILES: |
---|
86 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
87 | |
---|
88 | model_sources = [] |
---|
89 | append_file(file_list=model_sources, dir_path=srcdir) |
---|
90 | append_file(file_list=model_sources, dir_path=igordir) |
---|
91 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
92 | append_file(file_list=model_sources, dir_path=wrapper_dir) |
---|
93 | smear_sources = [] |
---|
94 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
95 | |
---|
96 | |
---|
97 | smearer_sources = [os.path.join(smear_dir, "smearer.cpp"), |
---|
98 | os.path.join(smear_dir, "smearer_module.cpp")] |
---|
99 | if os.name=='nt': |
---|
100 | smearer_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
101 | |
---|
102 | dist = setup( |
---|
103 | name="sansmodels", |
---|
104 | version = "1.0.0", |
---|
105 | description = "Python module for SANS scattering models", |
---|
106 | author = "SANS/DANSE", |
---|
107 | author_email = "sansdanse@gmail.gov", |
---|
108 | url = "http://danse.us/trac/sans", |
---|
109 | |
---|
110 | # Place this module under the sans package |
---|
111 | #ext_package = "sans", |
---|
112 | |
---|
113 | # Use the pure python modules |
---|
114 | package_dir = {"sans":os.path.join("src", "sans"), |
---|
115 | "sans.models":os.path.join("src", "sans", "models"), |
---|
116 | "sans.models.sans_extension":srcdir, |
---|
117 | }, |
---|
118 | package_data={'sans.models': [os.path.join('media', "*")]}, |
---|
119 | packages = ["sans","sans.models", |
---|
120 | "sans.models.sans_extension",], |
---|
121 | |
---|
122 | ext_modules = [ |
---|
123 | |
---|
124 | Extension("sans.models.sans_extension.c_models", |
---|
125 | sources=model_sources, |
---|
126 | include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path], |
---|
127 | ), |
---|
128 | |
---|
129 | # Smearer extension |
---|
130 | Extension("sans.models.sans_extension.smearer", |
---|
131 | sources = smearer_sources, |
---|
132 | include_dirs=[igordir, smear_dir, numpy_incl_path], |
---|
133 | ), |
---|
134 | |
---|
135 | Extension("sans.models.sans_extension.smearer2d_helper", |
---|
136 | sources = [os.path.join(smear_dir, |
---|
137 | "smearer2d_helper_module.cpp"), |
---|
138 | os.path.join(smear_dir, "smearer2d_helper.cpp"),], |
---|
139 | include_dirs=[smear_dir,numpy_incl_path], |
---|
140 | ) |
---|
141 | ], |
---|
142 | cmdclass = {'build_ext': build_ext_subclass } |
---|
143 | ) |
---|
144 | |
---|