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