source: sasview/setup.py @ e2271c5

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 e2271c5 was e2271c5, checked in by Anders Markvardsen <anders.markvardsen@…>, 11 years ago

Prepare to move corfunc perspective code out of trunk into branch

  • Property mode set to 100644
File size: 14.6 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
7import platform
8import shutil
9from setuptools import setup, Extension, find_packages
10from distutils.command.build_ext import build_ext
11
12try:
13    from numpy.distutils.misc_util import get_numpy_include_dirs
14    NUMPY_INC = get_numpy_include_dirs()[0]
15except:
16    try:
17        import numpy
18        NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0], 
19                                 "core","include")
20    except:
21        msg = "\nNumpy is needed to build SasView. "
22        print msg, "Try easy_install numpy.\n  %s" % str(sys.exc_value)
23        sys.exit(0)
24
25# Manage version number ######################################
26import sansview
27VERSION = sansview.__version__
28##############################################################
29
30package_dir = {}
31package_data = {}
32packages = []
33ext_modules = []
34
35# Remove all files that should be updated by this setup
36# We do this here because application updates these files from .sansview
37# except when there is no such file
38# Todo : make this list generic
39plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', 
40                     'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', 
41                     'testmodel_2.py', 'testmodel.py',
42                     'polynominal5.pyc', 'sph_bessel_jn.pyc', 
43                     'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', 
44                     'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log']
45sans_dir = os.path.join(os.path.expanduser("~"),'.sasview')
46if os.path.isdir(sans_dir):
47    f_path = os.path.join(sans_dir, "sasview.log")
48    if os.path.isfile(f_path):
49        os.remove(f_path)
50    f_path = os.path.join(sans_dir, "serialized_cat.p")
51    if os.path.isfile(f_path):
52        os.remove(f_path)
53    f_path = os.path.join(sans_dir, 'config', "custom_config.py")
54    if os.path.isfile(f_path):
55        os.remove(f_path)
56    f_path = os.path.join(sans_dir, 'plugin_models')
57    if os.path.isdir(f_path):
58        for file in os.listdir(f_path): 
59            if file in plugin_model_list:
60                file_path =  os.path.join(f_path, file)
61                os.remove(file_path)
62                   
63# 'sys.maxsize' and 64bit: Not supported for python2.5
64is_64bits = False
65if sys.version_info >= (2, 6):
66    is_64bits = sys.maxsize > 2**32
67   
68   
69enable_openmp = True                   
70
71if sys.platform =='darwin' and not is_64bits:
72    # Disable OpenMP
73    enable_openmp = False
74
75# Options to enable OpenMP
76copt =  {'msvc': ['/openmp'],
77         'mingw32' : ['-fopenmp'],
78         'unix' : ['-fopenmp']}
79lopt =  {'msvc': ['/MANIFEST'],
80         'mingw32' : ['-fopenmp'],
81         'unix' : ['-lgomp']}
82
83# Platform-specific link options
84platform_lopt = {'msvc' : ['/MANIFEST']}
85
86class build_ext_subclass( build_ext ):
87    def build_extensions(self):
88        # Get 64-bitness
89        c = self.compiler.compiler_type
90        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
91       
92        # OpenMP build options
93        if enable_openmp:
94            if copt.has_key(c):
95               for e in self.extensions:
96                   e.extra_compile_args = copt[ c ]
97            if lopt.has_key(c):
98                for e in self.extensions:
99                    e.extra_link_args = lopt[ c ]
100                   
101        # Platform-specific build options
102        if platform_lopt.has_key(c):
103            for e in self.extensions:
104                e.extra_link_args = platform_lopt[ c ]
105
106        build_ext.build_extensions(self)
107
108
109# sans.invariant
110package_dir["sans.invariant"] = "sansinvariant/src/sans/invariant"
111packages.extend(["sans.invariant"])
112
113# sans.guiframe
114guiframe_path = os.path.join("sansguiframe", "src", "sans", "guiframe")
115package_dir["sans.guiframe"] = guiframe_path
116package_dir["sans.guiframe.local_perspectives"] = os.path.join(guiframe_path, 
117                                                        "local_perspectives")
118package_data["sans.guiframe"] = ['images/*', 'media/*']
119packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"])
120# build local plugin
121for dir in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
122    if dir not in ['.svn','__init__.py', '__init__.pyc']:
123        package_name = "sans.guiframe.local_perspectives." + dir
124        packages.append(package_name)
125        package_dir[package_name] = os.path.join(guiframe_path, 
126                                                 "local_perspectives", dir)
127
128# sans.dataloader
129package_dir["sans.dataloader"] = os.path.join("sansdataloader", 
130                                              "src", "sans", "dataloader")
131package_data["sans.dataloader.readers"] = ['defaults.xml']
132packages.extend(["sans.dataloader","sans.dataloader.readers"])
133
134# sans.calculator
135package_dir["sans.calculator"] = "sanscalculator/src/sans/calculator"
136packages.extend(["sans.calculator"])
137   
138# sans.pr
139numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
140srcdir  = os.path.join("pr_inversion", "src", "sans", "pr", "c_extensions")
141
142
143   
144package_dir["sans.pr.core"] = srcdir
145package_dir["sans.pr"] = os.path.join("pr_inversion", "src","sans", "pr")
146packages.extend(["sans.pr","sans.pr.core"])
147ext_modules.append( Extension("sans.pr.core.pr_inversion",
148                              sources = [ os.path.join(srcdir, "Cinvertor.c"),
149                                         os.path.join(srcdir, "invertor.c"),
150                                         ],
151                              include_dirs=[numpy_incl_path],
152                              ) )
153       
154# sans.fit (park integration)
155package_dir["sans.fit"] = "park_integration/src/sans/fit"
156packages.append("sans.fit")
157
158# inversion view
159package_dir["sans.perspectives"] = "inversionview/src/sans/perspectives"
160package_dir["sans.perspectives.pr"] = "inversionview/src/sans/perspectives/pr"
161packages.extend(["sans.perspectives","sans.perspectives.pr"])
162package_data["sans.perspectives.pr"] = ['images/*']
163
164# Invariant view
165package_dir["sans.perspectives"] = os.path.join("invariantview", "src", 
166                                                "sans", "perspectives")
167package_dir["sans.perspectives.invariant"] = os.path.join("invariantview", 
168                                    "src", "sans", "perspectives", "invariant")
169               
170package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')]
171packages.extend(["sans.perspectives","sans.perspectives.invariant"]) 
172
173# Fitting view
174fitting_path = os.path.join("fittingview", "src", "sans", 
175                            "perspectives", "fitting")
176package_dir["sans.perspectives"] = os.path.join("fittingview", 
177                                            "src", "sans", "perspectives"),
178package_dir["sans.perspectives.fitting"] = fitting_path
179package_dir["sans.perspectives.fitting.plugin_models"] = \
180                                os.path.join(fitting_path, "plugin_models")
181package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*']
182packages.extend(["sans.perspectives", "sans.perspectives.fitting", 
183                 "sans.perspectives.fitting.plugin_models"])
184
185# Calculator view
186package_dir["sans.perspectives"] = "calculatorview/src/sans/perspectives"
187package_dir["sans.perspectives.calculator"] = os.path.join("calculatorview", 
188                                "src", "sans", "perspectives", "calculator")
189package_data['sans.perspectives.calculator'] = ['images/*', 'media/*']
190packages.extend(["sans.perspectives", "sans.perspectives.calculator"])   
191     
192# Data util
193package_dir["data_util"] = "sansutil"
194packages.extend(["data_util"])
195
196# Plottools
197package_dir["danse"] = os.path.join("plottools", "src", "danse")
198package_dir["danse.common"] = os.path.join("plottools", "src", 
199                                           "danse", "common")
200package_dir["danse.common.plottools"] = os.path.join("plottools", 
201                                    "src", "danse", "common", "plottools")
202packages.extend(["danse", "danse.common", "danse.common.plottools"])
203
204# Park 1.2.1
205package_dir["park"]="park-1.2.1/park"
206packages.extend(["park"])
207package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc']
208ext_modules.append( Extension("park._modeling",
209                              sources = [ os.path.join("park-1.2.1", 
210                                                "park", "lib", "modeling.cc"),
211                                         os.path.join("park-1.2.1", 
212                                                "park", "lib", "resolution.c"),
213                                         ],
214                              ) )
215
216# Sans models
217includedir  = os.path.join("sansmodels", "include")
218igordir = os.path.join("sansmodels", "src", "libigor")
219cephes_dir = os.path.join("sansmodels", "src", "cephes")
220c_model_dir = os.path.join("sansmodels", "src", "c_models")
221smear_dir  = os.path.join("sansmodels", "src", "c_smearer")
222gen_dir  = os.path.join("sansmodels", "src", "c_gen")
223wrapper_dir  = os.path.join("sansmodels", "src", "python_wrapper", "generated")
224model_dir = os.path.join("sansmodels", "src", "sans","models")
225
226if os.path.isdir(wrapper_dir):
227    for file in os.listdir(wrapper_dir): 
228        file_path =  os.path.join(wrapper_dir, file)
229        os.remove(file_path)
230else:
231    os.makedirs(wrapper_dir)
232sys.path.append(os.path.join("sansmodels", "src", "python_wrapper"))
233from wrapping import generate_wrappers
234generate_wrappers(header_dir = includedir, 
235                  output_dir = model_dir,
236                  c_wrapper_dir = wrapper_dir)
237
238IGNORED_FILES = [".svn"]
239if not os.name=='nt':
240    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
241
242
243EXTENSIONS = [".c", ".cpp"]
244
245def append_file(file_list, dir_path):
246    """
247    Add sources file to sources
248    """
249    for f in os.listdir(dir_path):
250        if os.path.isfile(os.path.join(dir_path, f)):
251            _, ext = os.path.splitext(f)
252            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
253                file_list.append(os.path.join(dir_path, f)) 
254        elif os.path.isdir(os.path.join(dir_path, f)) and \
255                not f.startswith("."):
256            sub_dir = os.path.join(dir_path, f)
257            for new_f in os.listdir(sub_dir):
258                if os.path.isfile(os.path.join(sub_dir, new_f)):
259                    _, ext = os.path.splitext(new_f)
260                    if ext.lower() in EXTENSIONS and\
261                         new_f not in IGNORED_FILES:
262                        file_list.append(os.path.join(sub_dir, new_f)) 
263       
264model_sources = []
265append_file(file_list=model_sources, dir_path=igordir)
266append_file(file_list=model_sources, dir_path=c_model_dir)
267append_file(file_list=model_sources, dir_path=wrapper_dir)
268
269smear_sources = []
270append_file(file_list=smear_sources, dir_path=smear_dir)
271
272
273package_dir["sans"] = os.path.join("sansmodels", "src", "sans")
274package_dir["sans.models"] = model_dir
275
276package_dir["sans.models.sans_extension"] = os.path.join("sansmodels", "src", 
277                                            "sans", "models", "sans_extension")
278           
279package_data['sans.models'] = [os.path.join('media', "*.*")]
280package_data['sans.models'] += [os.path.join('media','img', "*.*")]
281
282packages.extend(["sans","sans.models","sans.models.sans_extension"])
283   
284smearer_sources = [os.path.join(smear_dir, "smearer.cpp"),
285                  os.path.join(smear_dir, "smearer_module.cpp")]
286geni_sources = [os.path.join(gen_dir, "sld2i_module.cpp")]
287if os.name=='nt':
288    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
289    geni_sources.append(os.path.join(igordir, "winFuncs.c"))
290ext_modules.extend( [ Extension("sans.models.sans_extension.c_models",
291                                sources=model_sources,                 
292                                include_dirs=[igordir, includedir, 
293                                              c_model_dir, numpy_incl_path, cephes_dir],
294                                ),       
295                    # Smearer extension
296                    Extension("sans.models.sans_extension.smearer",
297                              sources = smearer_sources,
298                              include_dirs=[igordir, 
299                                            smear_dir, numpy_incl_path],
300                              ),
301                   
302                    Extension("sans.models.sans_extension.smearer2d_helper",
303                              sources = [os.path.join(smear_dir, 
304                                                "smearer2d_helper_module.cpp"),
305                                         os.path.join(smear_dir, 
306                                                "smearer2d_helper.cpp"),],
307                              include_dirs=[smear_dir, numpy_incl_path],
308                              ),
309                   
310                    Extension("sans.models.sans_extension.sld2i",
311                              sources = [os.path.join(gen_dir, 
312                                                "sld2i_module.cpp"),
313                                         os.path.join(gen_dir, 
314                                                "sld2i.cpp"),
315                                         os.path.join(c_model_dir, 
316                                                "libfunc.c"),
317                                         os.path.join(c_model_dir, 
318                                                "librefl.c"),],
319                              include_dirs=[gen_dir, includedir, 
320                                            c_model_dir, numpy_incl_path],
321                              )
322                    ] )
323       
324# SasView
325
326package_dir["sans.sansview"] = "sansview"
327package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*', 
328                                 'default_categories.p']
329packages.append("sans.sansview")
330
331#required = ['lxml>=2.2.2', 'numpy>=1.4.1', 'matplotlib>=0.99.1.1',
332#            'wxPython>=2.8.11', 'pil',
333#            'periodictable>=1.3.0', 'scipy>=0.7.2']
334required = ['lxml','periodictable>=1.3.1','pyparsing<2.0.0']
335
336if os.name=='nt':
337    required.extend(['html5lib', 'reportlab'])
338else:
339    required.extend(['pil'])
340   
341 # Set up SasView   
342setup(
343    name="sasview",
344    version = VERSION,
345    description = "SasView application",
346    author = "University of Tennessee",
347    author_email = "sansdanse@gmail.com",
348    url = "http://danse.chem.utk.edu",
349    license = "PSF",
350    keywords = "small-angle x-ray and neutron scattering analysis",
351    download_url = "https://sourceforge.net/projects/sansviewproject/files/",
352    package_dir = package_dir,
353    packages = packages,
354    package_data = package_data,
355    ext_modules = ext_modules,
356    install_requires = required,
357    zip_safe = False,
358    entry_points = {
359                    'console_scripts':[
360                                       "sasview = sans.sansview.sansview:run",
361                                       ]
362                    },
363    cmdclass = {'build_ext': build_ext_subclass }
364    )   
Note: See TracBrowser for help on using the repository browser.