source: sasview/sansmodels/setup.py @ 8b8a03f

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 8b8a03f was 8b8a03f, checked in by Jae Cho <jhjcho@…>, 12 years ago

small correction

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