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 setuptools import setup#, find_packages |
---|
14 | |
---|
15 | # Build the module name |
---|
16 | srcdir = os.path.join("src", "sans", "models", "c_extensions") |
---|
17 | igordir = os.path.join("src","sans", "models", "libigor") |
---|
18 | c_model_dir = os.path.join("src", "sans", "models", "c_models") |
---|
19 | smear_dir = os.path.join("src", "sans", "models", "c_smearer") |
---|
20 | print "Installing SANS models" |
---|
21 | |
---|
22 | |
---|
23 | IGNORED_FILES = ["a.exe", |
---|
24 | "__init__.py" |
---|
25 | ".svn", |
---|
26 | "lineparser.py", |
---|
27 | "run.py", |
---|
28 | "CGaussian.cpp", |
---|
29 | "CLogNormal.cpp", |
---|
30 | "CLorentzian.cpp", |
---|
31 | "CSchulz.cpp", |
---|
32 | "WrapperGenerator.py", |
---|
33 | "wrapping.py" |
---|
34 | ] |
---|
35 | if not os.name=='nt': |
---|
36 | IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"]) |
---|
37 | |
---|
38 | EXTENSIONS = [".c", ".cpp"] |
---|
39 | |
---|
40 | def append_file(file_list, dir_path): |
---|
41 | """ |
---|
42 | Add sources file to sources |
---|
43 | """ |
---|
44 | for f in os.listdir(dir_path): |
---|
45 | if os.path.isfile(os.path.join(dir_path, f)): |
---|
46 | _, ext = os.path.splitext(f) |
---|
47 | if ext.lower() in EXTENSIONS and f not in IGNORED_FILES: |
---|
48 | file_list.append(os.path.join(dir_path, f)) |
---|
49 | elif os.path.isdir(os.path.join(dir_path, f)) and \ |
---|
50 | not f.startswith("."): |
---|
51 | sub_dir = os.path.join(dir_path, f) |
---|
52 | for new_f in os.listdir(sub_dir): |
---|
53 | if os.path.isfile(os.path.join(sub_dir, new_f)): |
---|
54 | _, ext = os.path.splitext(new_f) |
---|
55 | if ext.lower() in EXTENSIONS and\ |
---|
56 | new_f not in IGNORED_FILES: |
---|
57 | file_list.append(os.path.join(sub_dir, new_f)) |
---|
58 | |
---|
59 | model_sources = [] |
---|
60 | append_file(file_list=model_sources, dir_path=srcdir) |
---|
61 | append_file(file_list=model_sources, dir_path=igordir) |
---|
62 | append_file(file_list=model_sources, dir_path=c_model_dir) |
---|
63 | smear_sources = [] |
---|
64 | append_file(file_list=smear_sources, dir_path=smear_dir) |
---|
65 | |
---|
66 | |
---|
67 | smearer_sources = [os.path.join(smear_dir, "smearer.cpp"), |
---|
68 | os.path.join(smear_dir, "smearer_module.cpp")] |
---|
69 | if os.name=='nt': |
---|
70 | smearer_sources.append(os.path.join(igordir, "winFuncs.c")) |
---|
71 | |
---|
72 | # Enable OpenMP |
---|
73 | extra_compile_args = [] |
---|
74 | extra_link_args = [] |
---|
75 | if sys.platform=='linux2' or (sys.platform=='darwin' and platform.architecture()[0]=='64bit'): |
---|
76 | extra_compile_args = ['-fopenmp'] |
---|
77 | extra_link_args = ['-lgomp'] |
---|
78 | elif os.name=='nt': |
---|
79 | extra_compile_args = ['/openmp'] |
---|
80 | |
---|
81 | dist = setup( |
---|
82 | name="sansmodels", |
---|
83 | version = "1.0.0", |
---|
84 | description = "Python module for SANS scattering models", |
---|
85 | author = "SANS/DANSE", |
---|
86 | author_email = "sansdanse@gmail.gov", |
---|
87 | url = "http://danse.us/trac/sans", |
---|
88 | |
---|
89 | # Place this module under the sans package |
---|
90 | #ext_package = "sans", |
---|
91 | |
---|
92 | # Use the pure python modules |
---|
93 | package_dir = {"sans":os.path.join("src", "sans"), |
---|
94 | "sans.models":os.path.join("src", "sans", "models"), |
---|
95 | "sans.models.sans_extension":srcdir, |
---|
96 | }, |
---|
97 | package_data={'sans.models': [os.path.join('media', "*")]}, |
---|
98 | packages = ["sans","sans.models", |
---|
99 | "sans.models.sans_extension",], |
---|
100 | |
---|
101 | ext_modules = [ Extension("sans.models.sans_extension.c_models", |
---|
102 | sources=model_sources, |
---|
103 | |
---|
104 | include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path], |
---|
105 | extra_compile_args=extra_compile_args, |
---|
106 | extra_link_args=extra_link_args |
---|
107 | ), |
---|
108 | |
---|
109 | # Smearer extension |
---|
110 | Extension("sans.models.sans_extension.smearer", |
---|
111 | sources = smearer_sources, |
---|
112 | include_dirs=[smear_dir, numpy_incl_path]), |
---|
113 | Extension("sans.models.sans_extension.smearer2d_helper", |
---|
114 | sources = [os.path.join(smear_dir, |
---|
115 | "smearer2d_helper_module.cpp"), |
---|
116 | os.path.join(smear_dir, "smearer2d_helper.cpp"),], |
---|
117 | include_dirs=[smear_dir,numpy_incl_path], |
---|
118 | extra_compile_args=extra_compile_args, |
---|
119 | extra_link_args=extra_link_args |
---|
120 | ) |
---|
121 | ] |
---|
122 | ) |
---|
123 | |
---|