source: sasview/setup.py @ f8063bf

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

bump bumps required version to 0.7.5.4 so that fits to sld parameters will work

  • 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   
70enable_openmp = False if "--disable-open-mp" in sys.argv else True
71
72if sys.platform =='darwin':
73    if not is_64bits:
74        # Disable OpenMP
75        enable_openmp = False
76    else:
77        # Newer versions of Darwin don't support openmp
78        try:
79            darwin_ver = int(os.uname()[2].split('.')[0])
80            if darwin_ver >= 12:
81                enable_openmp = False
82        except:
83            print "PROBLEM determining Darwin version"
84
85# Options to enable OpenMP
86copt =  {'msvc': ['/openmp'],
87         'mingw32' : ['-fopenmp'],
88         'unix' : ['-fopenmp']}
89lopt =  {'msvc': ['/MANIFEST'],
90         'mingw32' : ['-fopenmp'],
91         'unix' : ['-lgomp']}
92
93# Platform-specific link options
94platform_lopt = {'msvc' : ['/MANIFEST']}
95platform_copt = {}
96
97# Set copts to get compile working on OS X >= 10.9 using clang
98if sys.platform =='darwin':
99    try:
100        darwin_ver = int(os.uname()[2].split('.')[0])
101        if darwin_ver >= 13:
102            platform_copt = {'unix' : ['-Wno-error=unused-command-line-argument-hard-error-in-future']}
103    except:
104        print "PROBLEM determining Darwin version"
105
106
107
108class build_ext_subclass( build_ext ):
109    def build_extensions(self):
110        # Get 64-bitness
111        c = self.compiler.compiler_type
112        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
113       
114        # OpenMP build options
115        if enable_openmp:
116            if copt.has_key(c):
117                for e in self.extensions:
118                    e.extra_compile_args = copt[ c ]
119            if lopt.has_key(c):
120                for e in self.extensions:
121                    e.extra_link_args = lopt[ c ]
122                   
123        # Platform-specific build options
124        if platform_lopt.has_key(c):
125            for e in self.extensions:
126                e.extra_link_args = platform_lopt[ c ]
127
128        if platform_copt.has_key(c):
129            for e in self.extensions:
130                e.extra_compile_args = platform_copt[ c ]
131
132
133        build_ext.build_extensions(self)
134
135class BuildSphinxCommand(Command):
136    description = "Build Sphinx documentation."
137    user_options = []
138
139    def initialize_options(self):
140        self.cwd = None
141
142    def finalize_options(self):
143        self.cwd = os.getcwd()
144
145    def run(self):       
146        build_sphinx.clean()
147        build_sphinx.retrieve_user_docs()
148        build_sphinx.apidoc()
149        build_sphinx.build()
150
151# sans module
152package_dir["sans"] = os.path.join("src", "sans")
153packages.append("sans")
154
155# sans.invariant
156package_dir["sans.invariant"] = os.path.join("src", "sans", "invariant")
157packages.extend(["sans.invariant"])
158
159# sans.guiframe
160guiframe_path = os.path.join("src", "sans", "guiframe")
161package_dir["sans.guiframe"] = guiframe_path
162package_dir["sans.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives"))
163package_data["sans.guiframe"] = ['images/*', 'media/*']
164packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"])
165# build local plugin
166for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
167    if d not in ['.svn','__init__.py', '__init__.pyc']:
168        package_name = "sans.guiframe.local_perspectives." + d
169        packages.append(package_name)
170        package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d)
171
172# sans.dataloader
173package_dir["sans.dataloader"] = os.path.join("src", "sans", "dataloader")
174package_data["sans.dataloader.readers"] = ['defaults.xml','schema/*.xsd']
175packages.extend(["sans.dataloader","sans.dataloader.readers","sans.dataloader.readers.schema"])
176
177# sans.calculator
178package_dir["sans.calculator"] =os.path.join("src", "sans", "calculator")
179packages.extend(["sans.calculator"])
180   
181# sans.pr
182numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
183srcdir  = os.path.join("src", "sans", "pr", "c_extensions")
184package_dir["sans.pr.core"] = srcdir
185package_dir["sans.pr"] = os.path.join("src","sans", "pr")
186packages.extend(["sans.pr","sans.pr.core"])
187ext_modules.append( Extension("sans.pr.core.pr_inversion",
188                              sources = [os.path.join(srcdir, "Cinvertor.c"),
189                                         os.path.join(srcdir, "invertor.c"),
190                                         ],
191                              include_dirs=[numpy_incl_path],
192                              ) )
193       
194# sans.fit (park integration)
195package_dir["sans.fit"] = os.path.join("src", "sans", "fit")
196packages.append("sans.fit")
197
198# Perspectives
199package_dir["sans.perspectives"] = os.path.join("src", "sans", "perspectives")
200package_dir["sans.perspectives.pr"] = os.path.join("src", "sans", "perspectives", "pr")
201packages.extend(["sans.perspectives","sans.perspectives.pr"])
202package_data["sans.perspectives.pr"] = ['images/*']
203
204package_dir["sans.perspectives.invariant"] = os.path.join("src", "sans", "perspectives", "invariant")
205packages.extend(["sans.perspectives.invariant"])
206package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')]
207
208package_dir["sans.perspectives.fitting"] = os.path.join("src", "sans", "perspectives", "fitting")
209package_dir["sans.perspectives.fitting.plugin_models"] = os.path.join("src", "sans", "perspectives", "fitting", "plugin_models")
210packages.extend(["sans.perspectives.fitting", 
211                 "sans.perspectives.fitting.plugin_models"])
212package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*']
213
214packages.extend(["sans.perspectives", "sans.perspectives.calculator"])   
215package_data['sans.perspectives.calculator'] = ['images/*', 'media/*']
216   
217# Data util
218package_dir["data_util"] = os.path.join("src", "sans", "data_util")
219packages.append("sans.data_util")
220
221# Plottools
222package_dir["sans.plottools"] = os.path.join("src", "sans", "plottools")
223packages.append("sans.plottools")
224
225# Park 1.2.1
226package_dir["park"]="park-1.2.1/park"
227packages.extend(["park"])
228package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc']
229ext_modules.append( Extension("park._modeling",
230                              sources = [ os.path.join("park-1.2.1", 
231                                                "park", "lib", "modeling.cc"),
232                                         os.path.join("park-1.2.1", 
233                                                "park", "lib", "resolution.c"),
234                                         ],
235                              ) )
236
237# Sans models
238includedir  = os.path.join("src", "sans", "models", "include")
239igordir = os.path.join("src", "sans", "models", "c_extension", "libigor")
240cephes_dir = os.path.join("src", "sans", "models", "c_extension", "cephes")
241c_model_dir = os.path.join("src", "sans", "models", "c_extension", "c_models")
242smear_dir  = os.path.join("src", "sans", "models", "c_extension", "c_smearer")
243gen_dir  = os.path.join("src", "sans", "models", "c_extension", "c_gen")
244wrapper_dir  = os.path.join("src", "sans", "models", "c_extension", "python_wrapper", "generated")
245model_dir = os.path.join("src", "sans","models")
246
247if os.path.isdir(wrapper_dir):
248    for file in os.listdir(wrapper_dir): 
249        file_path =  os.path.join(wrapper_dir, file)
250        os.remove(file_path)
251else:
252    os.makedirs(wrapper_dir)
253sys.path.append(os.path.join("src", "sans", "models", "c_extension", "python_wrapper"))
254from wrapping import generate_wrappers
255generate_wrappers(header_dir = includedir, 
256                  output_dir = model_dir,
257                  c_wrapper_dir = wrapper_dir)
258
259IGNORED_FILES = [".svn"]
260if not os.name=='nt':
261    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
262
263EXTENSIONS = [".c", ".cpp"]
264
265def append_file(file_list, dir_path):
266    """
267    Add sources file to sources
268    """
269    for f in os.listdir(dir_path):
270        if os.path.isfile(os.path.join(dir_path, f)):
271            _, ext = os.path.splitext(f)
272            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
273                file_list.append(os.path.join(dir_path, f)) 
274        elif os.path.isdir(os.path.join(dir_path, f)) and \
275                not f.startswith("."):
276            sub_dir = os.path.join(dir_path, f)
277            for new_f in os.listdir(sub_dir):
278                if os.path.isfile(os.path.join(sub_dir, new_f)):
279                    _, ext = os.path.splitext(new_f)
280                    if ext.lower() in EXTENSIONS and\
281                         new_f not in IGNORED_FILES:
282                        file_list.append(os.path.join(sub_dir, new_f)) 
283       
284model_sources = []
285append_file(file_list=model_sources, dir_path=igordir)
286append_file(file_list=model_sources, dir_path=c_model_dir)
287append_file(file_list=model_sources, dir_path=wrapper_dir)
288
289smear_sources = []
290append_file(file_list=smear_sources, dir_path=smear_dir)
291       
292package_dir["sans.models"] = model_dir
293package_dir["sans.models.sans_extension"] = os.path.join("src", "sans", "models", "sans_extension")
294package_data['sans.models'] = [os.path.join('media', "*.*")]
295package_data['sans.models'] += [os.path.join('media','img', "*.*")]
296packages.extend(["sans.models","sans.models.sans_extension"])
297   
298smearer_sources = [os.path.join(smear_dir, "smearer.cpp"),
299                  os.path.join(smear_dir, "smearer_module.cpp")]
300geni_sources = [os.path.join(gen_dir, "sld2i_module.cpp")]
301if os.name=='nt':
302    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
303    geni_sources.append(os.path.join(igordir, "winFuncs.c"))
304
305c_models = [ 
306    Extension("sans.models.sans_extension.c_models",
307        sources=model_sources,                 
308        include_dirs=[
309            igordir, includedir, c_model_dir, numpy_incl_path, cephes_dir
310        ],
311    ),
312
313    # Smearer extension
314    Extension("sans.models.sans_extension.smearer",
315        sources = smearer_sources,
316        include_dirs=[igordir,  smear_dir, numpy_incl_path],
317    ),
318                   
319    Extension("sans.models.sans_extension.smearer2d_helper",
320        sources = [
321            os.path.join(smear_dir, "smearer2d_helper_module.cpp"),
322            os.path.join(smear_dir, "smearer2d_helper.cpp"),
323        ],
324        include_dirs=[smear_dir, numpy_incl_path],
325    ),
326                   
327    Extension("sans.models.sans_extension.sld2i",
328        sources = [
329            os.path.join(gen_dir, "sld2i_module.cpp"),
330            os.path.join(gen_dir, "sld2i.cpp"),
331            os.path.join(c_model_dir, "libfunc.c"),
332            os.path.join(c_model_dir, "librefl.c"),
333        ],
334        include_dirs=[gen_dir, includedir,  c_model_dir, numpy_incl_path],
335    ),
336]
337
338# Comment out the following to avoid rebuilding all the models
339ext_modules.extend(c_models)
340
341# SasView
342
343package_dir["sans.sansview"] = "sansview"
344package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*', 
345                                 'default_categories.json']
346packages.append("sans.sansview")
347
348required = [
349    'bumps>=0.7.5.4', 'periodictable>=1.3.1', 'pyparsing<2.0.0',
350
351    # 'lxml>=2.2.2',
352    'lxml', 
353
354    ## The following dependecies won't install automatically, so assume them
355    ## The numbers should be bumped up for matplotlib and wxPython as well.
356    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
357    # 'wxPython>=2.8.11', 'pil',
358    ]
359
360if os.name=='nt':
361    required.extend(['html5lib', 'reportlab'])
362else:
363    required.extend(['pil'])
364   
365# Set up SasView   
366setup(
367    name="sasview",
368    version = VERSION,
369    description = "SasView application",
370    author = "University of Tennessee",
371    author_email = "sansdanse@gmail.com",
372    url = "http://sasview.org",
373    license = "PSF",
374    keywords = "small-angle x-ray and neutron scattering analysis",
375    download_url = "https://sourceforge.net/projects/sansviewproject/files/",
376    package_dir = package_dir,
377    packages = packages,
378    package_data = package_data,
379    ext_modules = ext_modules,
380    install_requires = required,
381    zip_safe = False,
382    entry_points = {
383                    'console_scripts':[
384                                       "sasview = sans.sansview.sansview:run",
385                                       ]
386                    },
387    cmdclass = {'build_ext': build_ext_subclass,
388                'docs': BuildSphinxCommand}
389    )   
Note: See TracBrowser for help on using the repository browser.