source: sasview/setup.py @ 143c801

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 143c801 was afd42432, checked in by pkienzle, 10 years ago

require bumps 0.7.5.3 to fix 'input must be 1-d or 2-d' for levenberg-marquardt fit

  • Property mode set to 100644
File size: 14.1 KB
Line 
1"""
2    Setup for SasView
3    #TODO: Add checks to see that all the dependencies are on the system
4"""
5import sys
6import os
7from setuptools import setup, Extension
8from distutils.command.build_ext import build_ext
9from distutils.core import Command
10
11sys.path.append("docs/sphinx-docs")
12import build_sphinx
13
14try:
15    from numpy.distutils.misc_util import get_numpy_include_dirs
16    NUMPY_INC = get_numpy_include_dirs()[0]
17except:
18    try:
19        import numpy
20        NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0], 
21                                 "core","include")
22    except:
23        msg = "\nNumpy is needed to build SasView. "
24        print msg, "Try easy_install numpy.\n  %s" % str(sys.exc_value)
25        sys.exit(0)
26
27# Manage version number ######################################
28import sansview
29VERSION = sansview.__version__
30##############################################################
31
32package_dir = {}
33package_data = {}
34packages = []
35ext_modules = []
36
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', 
43                     'testmodel_2.py', 'testmodel.py',
44                     'polynominal5.pyc', 'sph_bessel_jn.pyc', 
45                     'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', 
46                     'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log']
47sans_dir = os.path.join(os.path.expanduser("~"),'.sasview')
48if os.path.isdir(sans_dir):
49    f_path = os.path.join(sans_dir, "sasview.log")
50    if os.path.isfile(f_path):
51        os.remove(f_path)
52    f_path = os.path.join(sans_dir, "serialized_cat.json")
53    if os.path.isfile(f_path):
54        os.remove(f_path)
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):
60        for f in os.listdir(f_path): 
61            if f in plugin_model_list:
62                file_path =  os.path.join(f_path, f)
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   
71enable_openmp = True
72
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"
85
86# Options to enable OpenMP
87copt =  {'msvc': ['/openmp'],
88         'mingw32' : ['-fopenmp'],
89         'unix' : ['-fopenmp']}
90lopt =  {'msvc': ['/MANIFEST'],
91         'mingw32' : ['-fopenmp'],
92         'unix' : ['-lgomp']}
93
94# Platform-specific link options
95platform_lopt = {'msvc' : ['/MANIFEST']}
96platform_copt = {}
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
107
108
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       
115        # OpenMP build options
116        if enable_openmp:
117            if copt.has_key(c):
118                for e in self.extensions:
119                    e.extra_compile_args = copt[ c ]
120            if lopt.has_key(c):
121                for e in self.extensions:
122                    e.extra_link_args = lopt[ c ]
123                   
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
129        if platform_copt.has_key(c):
130            for e in self.extensions:
131                e.extra_compile_args = platform_copt[ c ]
132
133
134        build_ext.build_extensions(self)
135
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
152# sans module
153package_dir["sans"] = os.path.join("src", "sans")
154packages.append("sans")
155
156# sans.invariant
157package_dir["sans.invariant"] = os.path.join("src", "sans", "invariant")
158packages.extend(["sans.invariant"])
159
160# sans.guiframe
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"])
166# build local plugin
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
170        packages.append(package_name)
171        package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d)
172
173# sans.dataloader
174package_dir["sans.dataloader"] = os.path.join("src", "sans", "dataloader")
175package_data["sans.dataloader.readers"] = ['defaults.xml','schema/*.xsd']
176packages.extend(["sans.dataloader","sans.dataloader.readers","sans.dataloader.readers.schema"])
177
178# sans.calculator
179package_dir["sans.calculator"] =os.path.join("src", "sans", "calculator")
180packages.extend(["sans.calculator"])
181   
182# sans.pr
183numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
184srcdir  = os.path.join("src", "sans", "pr", "c_extensions")
185package_dir["sans.pr.core"] = srcdir
186package_dir["sans.pr"] = os.path.join("src","sans", "pr")
187packages.extend(["sans.pr","sans.pr.core"])
188ext_modules.append( Extension("sans.pr.core.pr_inversion",
189                              sources = [os.path.join(srcdir, "Cinvertor.c"),
190                                         os.path.join(srcdir, "invertor.c"),
191                                         ],
192                              include_dirs=[numpy_incl_path],
193                              ) )
194       
195# sans.fit (park integration)
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"])
213package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*']
214
215packages.extend(["sans.perspectives", "sans.perspectives.calculator"])   
216package_data['sans.perspectives.calculator'] = ['images/*', 'media/*']
217   
218# Data util
219package_dir["data_util"] = os.path.join("src", "sans", "data_util")
220packages.append("sans.data_util")
221
222# Plottools
223package_dir["sans.plottools"] = os.path.join("src", "sans", "plottools")
224packages.append("sans.plottools")
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",
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"),
235                                         ],
236                              ) )
237
238# Sans models
239includedir  = os.path.join("src", "sans", "models", "include")
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")
246model_dir = os.path.join("src", "sans","models")
247
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:
253    os.makedirs(wrapper_dir)
254sys.path.append(os.path.join("src", "sans", "models", "c_extension", "python_wrapper"))
255from wrapping import generate_wrappers
256generate_wrappers(header_dir = includedir, 
257                  output_dir = model_dir,
258                  c_wrapper_dir = wrapper_dir)
259
260IGNORED_FILES = [".svn"]
261if not os.name=='nt':
262    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
263
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)
288append_file(file_list=model_sources, dir_path=wrapper_dir)
289
290smear_sources = []
291append_file(file_list=smear_sources, dir_path=smear_dir)
292       
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"))
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    ),
319                   
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    ),
327                   
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
342# SasView
343
344package_dir["sans.sansview"] = "sansview"
345package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*', 
346                                 'default_categories.json']
347packages.append("sans.sansview")
348
349required = [
350    'bumps>=0.7.5.3', 'periodictable>=1.3.1', 'pyparsing<2.0.0',
351
352    # 'lxml>=2.2.2',
353    'lxml', 
354
355    ## The following dependecies won't install automatically, so assume them
356    ## The numbers should be bumped up for matplotlib and wxPython as well.
357    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
358    # 'wxPython>=2.8.11', 'pil',
359    ]
360
361if os.name=='nt':
362    required.extend(['html5lib', 'reportlab'])
363else:
364    required.extend(['pil'])
365   
366# Set up SasView   
367setup(
368    name="sasview",
369    version = VERSION,
370    description = "SasView application",
371    author = "University of Tennessee",
372    author_email = "sansdanse@gmail.com",
373    url = "http://sasview.org",
374    license = "PSF",
375    keywords = "small-angle x-ray and neutron scattering analysis",
376    download_url = "https://sourceforge.net/projects/sansviewproject/files/",
377    package_dir = package_dir,
378    packages = packages,
379    package_data = package_data,
380    ext_modules = ext_modules,
381    install_requires = required,
382    zip_safe = False,
383    entry_points = {
384                    'console_scripts':[
385                                       "sasview = sans.sansview.sansview:run",
386                                       ]
387                    },
388    cmdclass = {'build_ext': build_ext_subclass,
389                'docs': BuildSphinxCommand}
390    )   
Note: See TracBrowser for help on using the repository browser.