source: sasview/setup.py @ 820df88

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 820df88 was 820df88, checked in by pkienzle, 10 years ago

reenable c model build

  • Property mode set to 100644
File size: 14.3 KB
RevLine 
[d6bc28cf]1"""
[c329f4d]2    Setup for SasView
[d6bc28cf]3    #TODO: Add checks to see that all the dependencies are on the system
4"""
[8ab3302]5import sys
[d6bc28cf]6import os
[5980b1a]7from setuptools import setup, Extension
[2cef9d3]8from distutils.command.build_ext import build_ext
[968aa6e]9from distutils.core import Command
10
11sys.path.append("docs/sphinx-docs")
12import build_sphinx
[2cef9d3]13
[e13ef7f]14try:
15    from numpy.distutils.misc_util import get_numpy_include_dirs
16    NUMPY_INC = get_numpy_include_dirs()[0]
17except:
[cb5fb4a]18    try:
[e13ef7f]19        import numpy
[8ab3302]20        NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0], 
21                                 "core","include")
[cb5fb4a]22    except:
[c329f4d]23        msg = "\nNumpy is needed to build SasView. "
[8ab3302]24        print msg, "Try easy_install numpy.\n  %s" % str(sys.exc_value)
[e13ef7f]25        sys.exit(0)
[d6bc28cf]26
[5548954]27# Manage version number ######################################
[a134fc6]28import sansview
29VERSION = sansview.__version__
[5548954]30##############################################################
31
[d6bc28cf]32package_dir = {}
33package_data = {}
34packages = []
35ext_modules = []
36
[8ab3302]37# Remove all files that should be updated by this setup
38# We do this here because application updates these files from .sansview
39# except when there is no such file
40# Todo : make this list generic
41plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', 
42                     'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', 
[b30ed8f]43                     'testmodel_2.py', 'testmodel.py',
44                     'polynominal5.pyc', 'sph_bessel_jn.pyc', 
45                     'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', 
[eb32080e]46                     'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log']
[c329f4d]47sans_dir = os.path.join(os.path.expanduser("~"),'.sasview')
[8ab3302]48if os.path.isdir(sans_dir):
[c329f4d]49    f_path = os.path.join(sans_dir, "sasview.log")
[e615a0d]50    if os.path.isfile(f_path):
51        os.remove(f_path)
[27b7acc]52    f_path = os.path.join(sans_dir, "serialized_cat.json")
[ea5fa58]53    if os.path.isfile(f_path):
54        os.remove(f_path)
[e615a0d]55    f_path = os.path.join(sans_dir, 'config', "custom_config.py")
56    if os.path.isfile(f_path):
57        os.remove(f_path)
58    f_path = os.path.join(sans_dir, 'plugin_models')
59    if os.path.isdir(f_path):
[5980b1a]60        for f in os.listdir(f_path): 
61            if f in plugin_model_list:
62                file_path =  os.path.join(f_path, f)
[e615a0d]63                os.remove(file_path)
64                   
65# 'sys.maxsize' and 64bit: Not supported for python2.5
66is_64bits = False
67if sys.version_info >= (2, 6):
68    is_64bits = sys.maxsize > 2**32
69   
70   
[880f170]71enable_openmp = True
[e79a467]72
[f468791]73if sys.platform =='darwin':
74    if not is_64bits:
75        # Disable OpenMP
76        enable_openmp = False
77    else:
78        # Newer versions of Darwin don't support openmp
79        try:
80            darwin_ver = int(os.uname()[2].split('.')[0])
81            if darwin_ver >= 12:
82                enable_openmp = False
83        except:
84            print "PROBLEM determining Darwin version"
[b30ed8f]85
86# Options to enable OpenMP
87copt =  {'msvc': ['/openmp'],
88         'mingw32' : ['-fopenmp'],
89         'unix' : ['-fopenmp']}
90lopt =  {'msvc': ['/MANIFEST'],
91         'mingw32' : ['-fopenmp'],
92         'unix' : ['-lgomp']}
[13f00a0]93
[ebdb833]94# Platform-specific link options
95platform_lopt = {'msvc' : ['/MANIFEST']}
[307fa4f]96platform_copt = {}
[b9c8fc5]97
98# Set copts to get compile working on OS X >= 10.9 using clang
99if sys.platform =='darwin':
100    try:
101        darwin_ver = int(os.uname()[2].split('.')[0])
102        if darwin_ver >= 13:
103            platform_copt = {'unix' : ['-Wno-error=unused-command-line-argument-hard-error-in-future']}
104    except:
105        print "PROBLEM determining Darwin version"
106
[1829835]107
[ebdb833]108
[13f00a0]109class build_ext_subclass( build_ext ):
110    def build_extensions(self):
111        # Get 64-bitness
112        c = self.compiler.compiler_type
113        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
114       
[ebdb833]115        # OpenMP build options
[b30ed8f]116        if enable_openmp:
[13f00a0]117            if copt.has_key(c):
[5980b1a]118                for e in self.extensions:
119                    e.extra_compile_args = copt[ c ]
[13f00a0]120            if lopt.has_key(c):
121                for e in self.extensions:
122                    e.extra_link_args = lopt[ c ]
123                   
[ebdb833]124        # Platform-specific build options
125        if platform_lopt.has_key(c):
126            for e in self.extensions:
127                e.extra_link_args = platform_lopt[ c ]
128
[1829835]129        if platform_copt.has_key(c):
130            for e in self.extensions:
131                e.extra_compile_args = platform_copt[ c ]
132
133
[13f00a0]134        build_ext.build_extensions(self)
[d6bc28cf]135
[968aa6e]136class BuildSphinxCommand(Command):
137    description = "Build Sphinx documentation."
138    user_options = []
139
140    def initialize_options(self):
141        self.cwd = None
142
143    def finalize_options(self):
144        self.cwd = os.getcwd()
145
146    def run(self):       
147        build_sphinx.clean()
148        build_sphinx.retrieve_user_docs()
149        build_sphinx.apidoc()
150        build_sphinx.build()
151
[5980b1a]152# sans module
153package_dir["sans"] = os.path.join("src", "sans")
154packages.append("sans")
[29e96f3]155
[d6bc28cf]156# sans.invariant
[3d24489]157package_dir["sans.invariant"] = os.path.join("src", "sans", "invariant")
158packages.extend(["sans.invariant"])
[d6bc28cf]159
160# sans.guiframe
[3d24489]161guiframe_path = os.path.join("src", "sans", "guiframe")
162package_dir["sans.guiframe"] = guiframe_path
163package_dir["sans.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives"))
164package_data["sans.guiframe"] = ['images/*', 'media/*']
165packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"])
[d6bc28cf]166# build local plugin
[5980b1a]167for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
168    if d not in ['.svn','__init__.py', '__init__.pyc']:
169        package_name = "sans.guiframe.local_perspectives." + d
[3d24489]170        packages.append(package_name)
[5980b1a]171        package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d)
[d6bc28cf]172
173# sans.dataloader
[3d24489]174package_dir["sans.dataloader"] = os.path.join("src", "sans", "dataloader")
[eda8972]175package_data["sans.dataloader.readers"] = ['defaults.xml','schema/*.xsd']
176packages.extend(["sans.dataloader","sans.dataloader.readers","sans.dataloader.readers.schema"])
[d6bc28cf]177
178# sans.calculator
[3d24489]179package_dir["sans.calculator"] =os.path.join("src", "sans", "calculator")
180packages.extend(["sans.calculator"])
[d6bc28cf]181   
182# sans.pr
[cb5fb4a]183numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
[b8a8e4e]184srcdir  = os.path.join("src", "sans", "pr", "c_extensions")
[3d24489]185package_dir["sans.pr.core"] = srcdir
186package_dir["sans.pr"] = os.path.join("src","sans", "pr")
187packages.extend(["sans.pr","sans.pr.core"])
[d6bc28cf]188ext_modules.append( Extension("sans.pr.core.pr_inversion",
[3d24489]189                              sources = [os.path.join(srcdir, "Cinvertor.c"),
[29e96f3]190                                         os.path.join(srcdir, "invertor.c"),
191                                         ],
192                              include_dirs=[numpy_incl_path],
193                              ) )
[d6bc28cf]194       
195# sans.fit (park integration)
[3d24489]196package_dir["sans.fit"] = os.path.join("src", "sans", "fit")
197packages.append("sans.fit")
198
199# Perspectives
200package_dir["sans.perspectives"] = os.path.join("src", "sans", "perspectives")
201package_dir["sans.perspectives.pr"] = os.path.join("src", "sans", "perspectives", "pr")
202packages.extend(["sans.perspectives","sans.perspectives.pr"])
203package_data["sans.perspectives.pr"] = ['images/*']
204
205package_dir["sans.perspectives.invariant"] = os.path.join("src", "sans", "perspectives", "invariant")
206packages.extend(["sans.perspectives.invariant"])
207package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')]
208
209package_dir["sans.perspectives.fitting"] = os.path.join("src", "sans", "perspectives", "fitting")
210package_dir["sans.perspectives.fitting.plugin_models"] = os.path.join("src", "sans", "perspectives", "fitting", "plugin_models")
211packages.extend(["sans.perspectives.fitting", 
212                 "sans.perspectives.fitting.plugin_models"])
[8ca5890]213package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*']
[3d24489]214
215packages.extend(["sans.perspectives", "sans.perspectives.calculator"])   
216package_data['sans.perspectives.calculator'] = ['images/*', 'media/*']
217   
[d6bc28cf]218# Data util
[76263a5]219package_dir["data_util"] = os.path.join("src", "sans", "data_util")
220packages.append("sans.data_util")
[d6bc28cf]221
222# Plottools
[f468791]223package_dir["sans.plottools"] = os.path.join("src", "sans", "plottools")
224packages.append("sans.plottools")
[d6bc28cf]225
226# Park 1.2.1
227package_dir["park"]="park-1.2.1/park"
228packages.extend(["park"])
229package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc']
230ext_modules.append( Extension("park._modeling",
[8ab3302]231                              sources = [ os.path.join("park-1.2.1", 
232                                                "park", "lib", "modeling.cc"),
233                                         os.path.join("park-1.2.1", 
234                                                "park", "lib", "resolution.c"),
[29e96f3]235                                         ],
236                              ) )
[d6bc28cf]237
238# Sans models
[b8a8e4e]239includedir  = os.path.join("src", "sans", "models", "include")
[79d5b6c]240igordir = os.path.join("src", "sans", "models", "c_extension", "libigor")
241cephes_dir = os.path.join("src", "sans", "models", "c_extension", "cephes")
242c_model_dir = os.path.join("src", "sans", "models", "c_extension", "c_models")
243smear_dir  = os.path.join("src", "sans", "models", "c_extension", "c_smearer")
244gen_dir  = os.path.join("src", "sans", "models", "c_extension", "c_gen")
245wrapper_dir  = os.path.join("src", "sans", "models", "c_extension", "python_wrapper", "generated")
[b8a8e4e]246model_dir = os.path.join("src", "sans","models")
[082c565]247
[78f74bd7]248if os.path.isdir(wrapper_dir):
249    for file in os.listdir(wrapper_dir): 
250        file_path =  os.path.join(wrapper_dir, file)
251        os.remove(file_path)
252else:
[0ba3b08]253    os.makedirs(wrapper_dir)
[79d5b6c]254sys.path.append(os.path.join("src", "sans", "models", "c_extension", "python_wrapper"))
[3d24489]255from wrapping import generate_wrappers
256generate_wrappers(header_dir = includedir, 
257                  output_dir = model_dir,
258                  c_wrapper_dir = wrapper_dir)
[2d1b700]259
[101065a]260IGNORED_FILES = [".svn"]
[9cde4cc]261if not os.name=='nt':
[2c63e80e]262    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
[9cde4cc]263
[d6bc28cf]264EXTENSIONS = [".c", ".cpp"]
265
266def append_file(file_list, dir_path):
267    """
268    Add sources file to sources
269    """
270    for f in os.listdir(dir_path):
271        if os.path.isfile(os.path.join(dir_path, f)):
272            _, ext = os.path.splitext(f)
273            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
274                file_list.append(os.path.join(dir_path, f)) 
275        elif os.path.isdir(os.path.join(dir_path, f)) and \
276                not f.startswith("."):
277            sub_dir = os.path.join(dir_path, f)
278            for new_f in os.listdir(sub_dir):
279                if os.path.isfile(os.path.join(sub_dir, new_f)):
280                    _, ext = os.path.splitext(new_f)
281                    if ext.lower() in EXTENSIONS and\
282                         new_f not in IGNORED_FILES:
283                        file_list.append(os.path.join(sub_dir, new_f)) 
284       
285model_sources = []
286append_file(file_list=model_sources, dir_path=igordir)
287append_file(file_list=model_sources, dir_path=c_model_dir)
[67424cd]288append_file(file_list=model_sources, dir_path=wrapper_dir)
289
[d6bc28cf]290smear_sources = []
291append_file(file_list=smear_sources, dir_path=smear_dir)
292       
[5980b1a]293package_dir["sans.models"] = model_dir
294package_dir["sans.models.sans_extension"] = os.path.join("src", "sans", "models", "sans_extension")
295package_data['sans.models'] = [os.path.join('media', "*.*")]
296package_data['sans.models'] += [os.path.join('media','img', "*.*")]
297packages.extend(["sans.models","sans.models.sans_extension"])
298   
299smearer_sources = [os.path.join(smear_dir, "smearer.cpp"),
300                  os.path.join(smear_dir, "smearer_module.cpp")]
301geni_sources = [os.path.join(gen_dir, "sld2i_module.cpp")]
302if os.name=='nt':
303    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
304    geni_sources.append(os.path.join(igordir, "winFuncs.c"))
[820df88]305
306c_models = [ 
307    Extension("sans.models.sans_extension.c_models",
308        sources=model_sources,                 
309        include_dirs=[
310            igordir, includedir, c_model_dir, numpy_incl_path, cephes_dir
311        ],
312    ),
313
314    # Smearer extension
315    Extension("sans.models.sans_extension.smearer",
316        sources = smearer_sources,
317        include_dirs=[igordir,  smear_dir, numpy_incl_path],
318    ),
[5980b1a]319                   
[820df88]320    Extension("sans.models.sans_extension.smearer2d_helper",
321        sources = [
322            os.path.join(smear_dir, "smearer2d_helper_module.cpp"),
323            os.path.join(smear_dir, "smearer2d_helper.cpp"),
324        ],
325        include_dirs=[smear_dir, numpy_incl_path],
326    ),
[5980b1a]327                   
[820df88]328    Extension("sans.models.sans_extension.sld2i",
329        sources = [
330            os.path.join(gen_dir, "sld2i_module.cpp"),
331            os.path.join(gen_dir, "sld2i.cpp"),
332            os.path.join(c_model_dir, "libfunc.c"),
333            os.path.join(c_model_dir, "librefl.c"),
334        ],
335        include_dirs=[gen_dir, includedir,  c_model_dir, numpy_incl_path],
336    ),
337]
338
339# Comment out the following to avoid rebuilding all the models
340ext_modules.extend(c_models)
341
[c329f4d]342# SasView
[df7a7e3]343
[d6bc28cf]344package_dir["sans.sansview"] = "sansview"
[ea5fa58]345package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*', 
[27b7acc]346                                 'default_categories.json']
[d6bc28cf]347packages.append("sans.sansview")
348
[9f32c57]349required = [
350    'bumps>=0.7.5', 'periodictable>=1.3.1', 'pyparsing<2.0.0', 
351
352    # 'lxml>=2.2.2',
353    'lxml', 
354
355    ## numdifftools is an optional dependency for bumps, giving better
356    ## errorbars for amoeba and differential evolution.  It is suppressed
357    ## because it forces scipy>=0.8, which the SNS does not yet support.
358    # 'numdifftools',
359
360    ## The following dependecies won't install automatically, so assume them
361    ## The numbers should be bumped up for matplotlib and wxPython as well.
362    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
363    # 'wxPython>=2.8.11', 'pil',
364    ]
[213b445]365
[95fe70d]366if os.name=='nt':
[7a211030]367    required.extend(['html5lib', 'reportlab'])
[7f59928e]368else:
[202c1ef]369    required.extend(['pil'])
[30ad350]370   
[5980b1a]371# Set up SasView   
[d6bc28cf]372setup(
[c329f4d]373    name="sasview",
[5548954]374    version = VERSION,
[c329f4d]375    description = "SasView application",
[d6bc28cf]376    author = "University of Tennessee",
377    author_email = "sansdanse@gmail.com",
[5980b1a]378    url = "http://sasview.org",
[d6bc28cf]379    license = "PSF",
[c329f4d]380    keywords = "small-angle x-ray and neutron scattering analysis",
[d6bc28cf]381    download_url = "https://sourceforge.net/projects/sansviewproject/files/",
382    package_dir = package_dir,
383    packages = packages,
384    package_data = package_data,
385    ext_modules = ext_modules,
386    install_requires = required,
[60f7d19]387    zip_safe = False,
[a7b774d]388    entry_points = {
389                    'console_scripts':[
[9a3b713]390                                       "sasview = sans.sansview.sansview:run",
[a7b774d]391                                       ]
[13f00a0]392                    },
[968aa6e]393    cmdclass = {'build_ext': build_ext_subclass,
394                'docs': BuildSphinxCommand}
[d113531]395    )   
Note: See TracBrowser for help on using the repository browser.