source: sasview/setup.py @ 530cc84

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 530cc84 was 0a8f658, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

fix logging

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