source: sasview/sansmodels/setup.py @ d555416

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 d555416 was 592cb156, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Fix sansmodels as standalone package

  • Property mode set to 100644
File size: 5.5 KB
RevLine 
[ae3ce4e]1"""
2 Installation script for SANS models
3"""
[d7a2531]4
[f88624d]5import sys
6import os
[0b082f3]7import platform
[b72b595]8from numpy.distutils.misc_util import get_numpy_include_dirs
[6c13861]9numpy_incl_path = os.path.join(get_numpy_include_dirs()[0], "numpy")
[0abf7bf]10   
[ae3ce4e]11# Then build and install the modules
[87615a48]12from distutils.core import Extension, setup
[13f00a0]13from distutils.command.build_ext import build_ext
14
[592cb156]15# Manage version number ######################################
16sys.path.append(os.path.join("src", "sans"))
17import models
18VERSION = models.__version__
19print "Building models v%s" % VERSION
20##############################################################
21
[13f00a0]22# Options to enable OpenMP
[ebdb833]23copt =  {'msvc': ['/openmp'],
24         'mingw32' : ['-fopenmp'],
25         'unix' : ['-fopenmp']}
26lopt =  {'msvc': ['/MANIFEST'],
27         'mingw32' : ['-fopenmp'],
28         'unix' : ['-lgomp']}
29
30# Options for non-openmp builds. MSVC always needs MANIFEST
[5c77050]31if sys.argv[-1] == "-nomp":
[8b8a03f]32    copt = {}
[ebdb833]33    lopt = {'msvc': ['/MANIFEST']}
[13f00a0]34
35class build_ext_subclass( build_ext ):
36    def build_extensions(self):
37        # Get 64-bitness
[d9673d7a]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
[13f00a0]43        c = self.compiler.compiler_type
44        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
[ebdb833]45       
[13f00a0]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)
[ae3ce4e]55
56# Build the module name
[503a972]57includedir  = "include"
[67424cd]58igordir = os.path.join("src", "libigor")
59c_model_dir = os.path.join("src", "c_models")
60smear_dir  = os.path.join("src", "c_smearer")
[26e0249]61wrapper_dir  = os.path.join("src", "python_wrapper", "generated")
[592cb156]62if not os.path.isdir(wrapper_dir):
63    os.makedirs(wrapper_dir)
[ae3ce4e]64
[26e0249]65sys.path.append(os.path.join("src", "python_wrapper"))
[0ba3b08]66from wrapping import generate_wrappers
[886dde6b]67generate_wrappers(header_dir=includedir, 
[0ba3b08]68                  output_dir=os.path.join("src", "sans", "models"), 
69                  c_wrapper_dir=wrapper_dir)
[ae3ce4e]70
[101065a]71IGNORED_FILES = [".svn"]
[f9303b6]72if not os.name=='nt':
73    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
74
[0f282a5]75EXTENSIONS = [".c", ".cpp"]
[0a51f0d8]76
77def 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)
[0f282a5]84            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
[0a51f0d8]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)
[0f282a5]92                    if ext.lower() in EXTENSIONS and\
[0a51f0d8]93                         new_f not in IGNORED_FILES:
94                        file_list.append(os.path.join(sub_dir, new_f)) 
95       
96model_sources = []
97append_file(file_list=model_sources, dir_path=igordir)
98append_file(file_list=model_sources, dir_path=c_model_dir)
[67424cd]99append_file(file_list=model_sources, dir_path=wrapper_dir)
[0a51f0d8]100smear_sources = []
101append_file(file_list=smear_sources, dir_path=smear_dir)
102
103
[f9303b6]104smearer_sources = [os.path.join(smear_dir, "smearer.cpp"),
105                  os.path.join(smear_dir, "smearer_module.cpp")]
106if os.name=='nt':
107    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
108
[87615a48]109dist = setup(
[5953b77]110    name="sansmodels",
[592cb156]111    version = VERSION,
[ae3ce4e]112    description = "Python module for SANS scattering models",
[87615a48]113    author = "SANS/DANSE",
114    author_email = "sansdanse@gmail.gov",
[592cb156]115    url = "http://sansviewproject.svn.sourceforge.net",
[ae3ce4e]116   
117    # Place this module under the sans package
118    #ext_package = "sans",
119   
120    # Use the pure python modules
[0a51f0d8]121    package_dir = {"sans":os.path.join("src", "sans"),
122                   "sans.models":os.path.join("src", "sans", "models"),
[592cb156]123                   "sans.models.sans_extension":os.path.join("src", "sans", "models", "sans_extension"),
[42c974f]124                  },
125    package_data={'sans.models': [os.path.join('media', "*")]},
126    packages = ["sans","sans.models",
[0abf7bf]127                "sans.models.sans_extension",],
[ae3ce4e]128   
[67424cd]129    ext_modules = [ 
130                   
131        Extension("sans.models.sans_extension.c_models",
132                    sources=model_sources,                 
[886dde6b]133                    include_dirs=[igordir, includedir, c_model_dir, numpy_incl_path],   
[67424cd]134                    ),
135
[87615a48]136        # Smearer extension
[c089120]137        Extension("sans.models.sans_extension.smearer",
[f9303b6]138                   sources = smearer_sources,
[13f00a0]139                   include_dirs=[igordir, smear_dir, numpy_incl_path],
140                   ),
141                   
[c089120]142        Extension("sans.models.sans_extension.smearer2d_helper",
[0a51f0d8]143                  sources = [os.path.join(smear_dir, 
144                                          "smearer2d_helper_module.cpp"),
145                             os.path.join(smear_dir, "smearer2d_helper.cpp"),],
[0b082f3]146                  include_dirs=[smear_dir,numpy_incl_path],
[13f00a0]147                  )
148        ],
149    cmdclass = {'build_ext': build_ext_subclass }
[87615a48]150    )
[b72b595]151       
Note: See TracBrowser for help on using the repository browser.