source: sasview/setup.py @ df7a7e3

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 df7a7e3 was df7a7e3, checked in by Mathieu Doucet <doucetm@…>, 12 years ago

merging category branch

  • Property mode set to 100644
File size: 14.9 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
12
13
14
15try:
16    from numpy.distutils.misc_util import get_numpy_include_dirs
17    NUMPY_INC = get_numpy_include_dirs()[0]
18except:
19    try:
20        import numpy
21        NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0], 
22                                 "core","include")
23    except:
24        msg = "\nNumpy is needed to build SasView. "
25        print msg, "Try easy_install numpy.\n  %s" % str(sys.exc_value)
26        sys.exit(0)
27
28# Manage version number ######################################
29import sansview
30VERSION = sansview.__version__
31##############################################################
32
33package_dir = {}
34package_data = {}
35packages = []
36ext_modules = []
37
38# Remove all files that should be updated by this setup
39# We do this here because application updates these files from .sansview
40# except when there is no such file
41# Todo : make this list generic
42plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', 
43                     'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', 
44                     'testmodel_2.py', 'testmodel.py',
45                     'polynominal5.pyc', 'sph_bessel_jn.pyc', 
46                     'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', 
47                     'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log']
48sans_dir = os.path.join(os.path.expanduser("~"),'.sasview')
49if os.path.isdir(sans_dir):
50    f_path = os.path.join(sans_dir, "sasview.log")
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/*', 
119                                 'media/*', 
120                                 'default_categories.p']
121
122packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"])
123# build local plugin
124for dir in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
125    if dir not in ['.svn','__init__.py', '__init__.pyc']:
126        package_name = "sans.guiframe.local_perspectives." + dir
127        packages.append(package_name)
128        package_dir[package_name] = os.path.join(guiframe_path, 
129                                                 "local_perspectives", dir)
130
131# sans.dataloader
132package_dir["sans.dataloader"] = os.path.join("sansdataloader", 
133                                              "src", "sans", "dataloader")
134package_data["sans.dataloader.readers"] = ['defaults.xml']
135packages.extend(["sans.dataloader","sans.dataloader.readers"])
136
137# sans.calculator
138package_dir["sans.calculator"] = "sanscalculator/src/sans/calculator"
139packages.extend(["sans.calculator"])
140   
141# sans.pr
142numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
143srcdir  = os.path.join("pr_inversion", "src", "sans", "pr", "c_extensions")
144
145
146   
147package_dir["sans.pr.core"] = srcdir
148package_dir["sans.pr"] = os.path.join("pr_inversion", "src","sans", "pr")
149packages.extend(["sans.pr","sans.pr.core"])
150ext_modules.append( Extension("sans.pr.core.pr_inversion",
151                              sources = [ os.path.join(srcdir, "Cinvertor.c"),
152                                         os.path.join(srcdir, "invertor.c"),
153                                         ],
154                              include_dirs=[numpy_incl_path],
155                              ) )
156       
157# sans.fit (park integration)
158package_dir["sans.fit"] = "park_integration/src/sans/fit"
159packages.append("sans.fit")
160
161# inversion view
162package_dir["sans.perspectives"] = "inversionview/src/sans/perspectives"
163package_dir["sans.perspectives.pr"] = "inversionview/src/sans/perspectives/pr"
164packages.extend(["sans.perspectives","sans.perspectives.pr"])
165package_data["sans.perspectives.pr"] = ['images/*']
166
167# Invariant view
168package_dir["sans.perspectives"] = os.path.join("invariantview", "src", 
169                                                "sans", "perspectives")
170package_dir["sans.perspectives.invariant"] = os.path.join("invariantview", 
171                                    "src", "sans", "perspectives", "invariant")
172               
173package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')]
174packages.extend(["sans.perspectives","sans.perspectives.invariant"]) 
175
176# Fitting view
177fitting_path = os.path.join("fittingview", "src", "sans", 
178                            "perspectives", "fitting")
179package_dir["sans.perspectives"] = os.path.join("fittingview", 
180                                            "src", "sans", "perspectives"),
181package_dir["sans.perspectives.fitting"] = fitting_path
182package_dir["sans.perspectives.fitting.plugin_models"] = \
183                                os.path.join(fitting_path, "plugin_models")
184package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*']
185packages.extend(["sans.perspectives", "sans.perspectives.fitting", 
186                 "sans.perspectives.fitting.plugin_models"])
187
188# Calculator view
189package_dir["sans.perspectives"] = "calculatorview/src/sans/perspectives"
190package_dir["sans.perspectives.calculator"] = os.path.join("calculatorview", 
191                                "src", "sans", "perspectives", "calculator")
192package_data['sans.perspectives.calculator'] = ['images/*', 'media/*']
193packages.extend(["sans.perspectives", "sans.perspectives.calculator"])
194     
195# Data util
196package_dir["data_util"] = "sansutil"
197packages.extend(["data_util"])
198
199# Plottools
200package_dir["danse"] = os.path.join("plottools", "src", "danse")
201package_dir["danse.common"] = os.path.join("plottools", "src", 
202                                           "danse", "common")
203package_dir["danse.common.plottools"] = os.path.join("plottools", 
204                                    "src", "danse", "common", "plottools")
205packages.extend(["danse", "danse.common", "danse.common.plottools"])
206
207# Park 1.2.1
208package_dir["park"]="park-1.2.1/park"
209packages.extend(["park"])
210package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc']
211ext_modules.append( Extension("park._modeling",
212                              sources = [ os.path.join("park-1.2.1", 
213                                                "park", "lib", "modeling.cc"),
214                                         os.path.join("park-1.2.1", 
215                                                "park", "lib", "resolution.c"),
216                                         ],
217                              ) )
218
219# Sans models
220includedir  = os.path.join("sansmodels", "include")
221igordir = os.path.join("sansmodels", "src", "libigor")
222c_model_dir = os.path.join("sansmodels", "src", "c_models")
223smear_dir  = os.path.join("sansmodels", "src", "c_smearer")
224wrapper_dir  = os.path.join("sansmodels", "src", "python_wrapper", "generated")
225model_dir = os.path.join("sansmodels", "src", "sans","models")
226
227if os.path.isdir(wrapper_dir):
228    for file in os.listdir(wrapper_dir): 
229        file_path =  os.path.join(wrapper_dir, file)
230        os.remove(file_path)
231else:
232    os.makedirs(wrapper_dir)
233sys.path.append(os.path.join("sansmodels", "src", "python_wrapper"))
234from wrapping import generate_wrappers
235generate_wrappers(header_dir = includedir, 
236                  output_dir = model_dir,
237                  c_wrapper_dir = wrapper_dir)
238
239IGNORED_FILES = [".svn"]
240if not os.name=='nt':
241    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
242
243
244EXTENSIONS = [".c", ".cpp"]
245
246def append_file(file_list, dir_path):
247    """
248    Add sources file to sources
249    """
250    for f in os.listdir(dir_path):
251        if os.path.isfile(os.path.join(dir_path, f)):
252            _, ext = os.path.splitext(f)
253            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
254                file_list.append(os.path.join(dir_path, f)) 
255        elif os.path.isdir(os.path.join(dir_path, f)) and \
256                not f.startswith("."):
257            sub_dir = os.path.join(dir_path, f)
258            for new_f in os.listdir(sub_dir):
259                if os.path.isfile(os.path.join(sub_dir, new_f)):
260                    _, ext = os.path.splitext(new_f)
261                    if ext.lower() in EXTENSIONS and\
262                         new_f not in IGNORED_FILES:
263                        file_list.append(os.path.join(sub_dir, new_f)) 
264       
265model_sources = []
266append_file(file_list=model_sources, dir_path=igordir)
267append_file(file_list=model_sources, dir_path=c_model_dir)
268append_file(file_list=model_sources, dir_path=wrapper_dir)
269
270smear_sources = []
271append_file(file_list=smear_sources, dir_path=smear_dir)
272
273
274package_dir["sans"] = os.path.join("sansmodels", "src", "sans")
275package_dir["sans.models"] = model_dir
276
277package_dir["sans.models.sans_extension"] = os.path.join("sansmodels", "src", "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")]
286
287
288
289
290
291
292if os.name=='nt':
293    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
294
295ext_modules.extend( [ Extension("sans.models.sans_extension.c_models",
296                                sources=model_sources,                 
297                                include_dirs=[igordir, includedir, 
298                                              c_model_dir, numpy_incl_path],
299                                ),       
300                    # Smearer extension
301                    Extension("sans.models.sans_extension.smearer",
302                              sources = smearer_sources,
303                              include_dirs=[igordir, 
304                                            smear_dir, numpy_incl_path],
305                              ),
306                   
307                    Extension("sans.models.sans_extension.smearer2d_helper",
308                              sources = [os.path.join(smear_dir, 
309                                                "smearer2d_helper_module.cpp"),
310                                         os.path.join(smear_dir, 
311                                                "smearer2d_helper.cpp"),],
312                              include_dirs=[smear_dir,numpy_incl_path],
313                              )
314                    ] )
315       
316# SasView
317
318package_dir["sans.sansview"] = "sansview"
319package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*']
320packages.append("sans.sansview")
321
322#required = ['lxml>=2.2.2', 'numpy>=1.4.1', 'matplotlib>=0.99.1.1',
323#            'wxPython>=2.8.11', 'pil',
324#            'periodictable>=1.3.0', 'scipy>=0.7.2']
325required = ['lxml','periodictable>=1.3.0']
326
327if os.name=='nt':
328    required.extend(['html5lib', 'reportlab'])
329else:
330    required.extend(['pil'])
331
332# sys.path.append(os.path.join('sansguiframe',
333#                              'src',
334#                              'sans',
335#                              'guiframe'))
336
337#install category stuff
338cat_install_path = os.path.join('sansguiframe', 'src',
339                                'sans','guiframe','CategoryInstaller.py')
340shutil.copy(cat_install_path, os.getcwd())
341
342from CategoryInstaller import CategoryInstaller
343CategoryInstaller.check_install(defaultfile = \
344                                    os.path.join('sansguiframe',
345                                                 'src',
346                                                 'sans',
347                                                 'guiframe',
348                                                 'default_categories.p'),
349                                modelsdir = \
350                                    os.path.join('fittingview',
351                                                 'src',
352                                                 'sans',
353                                                 'perspectives',
354                                                 'fitting'), 
355                                installed_models_dir = \
356                                    os.path.join('sansdataloader',
357                                                 'src',
358                                                 'sans',
359                                                 'dataloader',
360                                                 'readers') )
361
362   
363 # Set up SasView   
364setup(
365    name="sasview",
366    version = VERSION,
367    description = "SasView application",
368    author = "University of Tennessee",
369    author_email = "sansdanse@gmail.com",
370    url = "http://danse.chem.utk.edu",
371    license = "PSF",
372    keywords = "small-angle x-ray and neutron scattering analysis",
373    download_url = "https://sourceforge.net/projects/sansviewproject/files/",
374    package_dir = package_dir,
375    packages = packages,
376    package_data = package_data,
377    ext_modules = ext_modules,
378    install_requires = required,
379    zip_safe = False,
380    entry_points = {
381                    'console_scripts':[
382                                       "sansview = sans.sansview.sansview:run",
383                                       ]
384                    },
385    cmdclass = {'build_ext': build_ext_subclass }
386    )   
Note: See TracBrowser for help on using the repository browser.