source: sasview/sansmodels/setup.py @ 0ba3b08

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 0ba3b08 was 0ba3b08, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

refactored bunch of models

  • Property mode set to 100644
File size: 5.5 KB
Line 
1"""
2 Installation script for SANS models
3"""
4
5import sys
6import os
7import platform
8from numpy.distutils.misc_util import get_numpy_include_dirs
9numpy_incl_path = os.path.join(get_numpy_include_dirs()[0], "numpy")
10   
11# Then build and install the modules
12from distutils.core import Extension, setup
13from distutils.command.build_ext import build_ext
14
15# Options to enable OpenMP
16copt =  {'msvc': ['/openmp'],
17         'mingw32' : ['-fopenmp'],
18         'unix' : ['-fopenmp']}
19lopt =  {'msvc': ['/MANIFEST'],
20         'mingw32' : ['-fopenmp'],
21         'unix' : ['-lgomp']}
22
23# Options for non-openmp builds. MSVC always needs MANIFEST
24if sys.argv[-1] == "-nomp":
25    copt = {}
26    lopt = {'msvc': ['/MANIFEST']}
27
28class 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
50srcdir  = os.path.join("src", "c_extensions")
51igordir = os.path.join("src", "libigor")
52c_model_dir = os.path.join("src", "c_models")
53smear_dir  = os.path.join("src", "c_smearer")
54wrapper_dir  = os.path.join("src", "python_wrapper")
55print "Installing SANS models"
56
57sys.path.append(wrapper_dir)
58from wrapping import generate_wrappers
59generate_wrappers(header_dir=srcdir, 
60                  output_dir=os.path.join("src", "sans", "models"), 
61                  c_wrapper_dir=wrapper_dir)
62
63IGNORED_FILES = ["a.exe",
64                 "__init__.py"
65                 ".svn",
66                   "lineparser.py",
67                   "run.py",
68                   "CGaussian.cpp",
69                   "CLogNormal.cpp",
70                   "CLorentzian.cpp",
71                   "CSchulz.cpp",
72                   "WrapperGenerator.py",
73                   "wrapping.py"
74                   ]
75if not os.name=='nt':
76    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
77
78EXTENSIONS = [".c", ".cpp"]
79
80def append_file(file_list, dir_path):
81    """
82    Add sources file to sources
83    """
84    for f in os.listdir(dir_path):
85        if os.path.isfile(os.path.join(dir_path, f)):
86            _, ext = os.path.splitext(f)
87            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
88                file_list.append(os.path.join(dir_path, f)) 
89        elif os.path.isdir(os.path.join(dir_path, f)) and \
90                not f.startswith("."):
91            sub_dir = os.path.join(dir_path, f)
92            for new_f in os.listdir(sub_dir):
93                if os.path.isfile(os.path.join(sub_dir, new_f)):
94                    _, ext = os.path.splitext(new_f)
95                    if ext.lower() in EXTENSIONS and\
96                         new_f not in IGNORED_FILES:
97                        file_list.append(os.path.join(sub_dir, new_f)) 
98       
99model_sources = []
100append_file(file_list=model_sources, dir_path=srcdir)
101append_file(file_list=model_sources, dir_path=igordir)
102append_file(file_list=model_sources, dir_path=c_model_dir)
103append_file(file_list=model_sources, dir_path=wrapper_dir)
104smear_sources = []
105append_file(file_list=smear_sources, dir_path=smear_dir)
106
107
108smearer_sources = [os.path.join(smear_dir, "smearer.cpp"),
109                  os.path.join(smear_dir, "smearer_module.cpp")]
110if os.name=='nt':
111    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
112
113dist = setup(
114    name="sansmodels",
115    version = "1.0.0",
116    description = "Python module for SANS scattering models",
117    author = "SANS/DANSE",
118    author_email = "sansdanse@gmail.gov",
119    url = "http://danse.us/trac/sans",
120   
121    # Place this module under the sans package
122    #ext_package = "sans",
123   
124    # Use the pure python modules
125    package_dir = {"sans":os.path.join("src", "sans"),
126                   "sans.models":os.path.join("src", "sans", "models"),
127                   "sans.models.sans_extension":srcdir,
128                  },
129    package_data={'sans.models': [os.path.join('media', "*")]},
130    packages = ["sans","sans.models",
131                "sans.models.sans_extension",],
132   
133    ext_modules = [ 
134                   
135        Extension("sans.models.sans_extension.c_models",
136                    sources=model_sources,                 
137                    include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path],   
138                    ),
139
140        # Smearer extension
141        Extension("sans.models.sans_extension.smearer",
142                   sources = smearer_sources,
143                   include_dirs=[igordir, smear_dir, numpy_incl_path],
144                   ),
145                   
146        Extension("sans.models.sans_extension.smearer2d_helper",
147                  sources = [os.path.join(smear_dir, 
148                                          "smearer2d_helper_module.cpp"),
149                             os.path.join(smear_dir, "smearer2d_helper.cpp"),],
150                  include_dirs=[smear_dir,numpy_incl_path],
151                  )
152        ],
153    cmdclass = {'build_ext': build_ext_subclass }
154    )
155       
Note: See TracBrowser for help on using the repository browser.