source: sasview/setup.py @ 30ad350

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 30ad350 was 30ad350, checked in by Jae Cho <jhjcho@…>, 12 years ago

put back pil for linux

  • 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]5# [command] can be any of the following:
6#   -nomp: no openmp: Use this flag; C-lib without openmp as well as numpy < 1.6
[5c77050]7
[8ab3302]8import sys
[d6bc28cf]9import os
[01de557]10import platform
[d6bc28cf]11from setuptools import setup, Extension, find_packages
[2cef9d3]12from distutils.command.build_ext import build_ext
13
[e13ef7f]14try:
15    from numpy.distutils.misc_util import get_numpy_include_dirs
16    NUMPY_INC = get_numpy_include_dirs()[0]
17except:
[cb5fb4a]18    try:
[e13ef7f]19        import numpy
[8ab3302]20        NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0], 
21                                 "core","include")
[cb5fb4a]22    except:
[8ab3302]23        msg = "\nNumpy is needed to build SansView. "
24        print msg, "Try easy_install numpy.\n  %s" % str(sys.exc_value)
[e13ef7f]25        sys.exit(0)
[d6bc28cf]26
[5548954]27# Manage version number ######################################
[a134fc6]28import sansview
29VERSION = sansview.__version__
[5548954]30##############################################################
31
[d6bc28cf]32package_dir = {}
33package_data = {}
34packages = []
35ext_modules = []
36
[8ab3302]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', 
[b30ed8f]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']
[8ab3302]47sans_dir = os.path.join(os.path.expanduser("~"),'.sansview')
48if os.path.isdir(sans_dir):
49    f_path = os.path.join(sans_dir, "sansview.log")
[5e56f89]50    if sys.platform =='darwin' or sys.platform == 'win32':
[494f151]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)
[5e56f89]62
[b30ed8f]63
64enable_openmp = True                   
[5c77050]65if sys.argv[-1] == "-nomp":
[8b8a03f]66    # Disable OpenMP
[b30ed8f]67    enable_openmp = False
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
80class build_ext_subclass( build_ext ):
81    def build_extensions(self):
82        # Get 64-bitness
[5d75d65a]83        if sys.version_info >= (2, 6):
84            is_64bits = sys.maxsize > 2**32
85        else:
86            # 'sys.maxsize' and 64bit: Not supported for python2.5
87            is_64bits = False
[13f00a0]88       
89        c = self.compiler.compiler_type
90        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
91       
[b30ed8f]92        if enable_openmp:
[13f00a0]93            if copt.has_key(c):
94               for e in self.extensions:
95                   e.extra_compile_args = copt[ c ]
96            if lopt.has_key(c):
[b30ed8f]97               
[13f00a0]98                for e in self.extensions:
99                    e.extra_link_args = lopt[ c ]
100                   
101        build_ext.build_extensions(self)
[d6bc28cf]102
[29e96f3]103
[d6bc28cf]104# sans.invariant
105package_dir["sans.invariant"] = "sansinvariant/src/sans/invariant"
106packages.extend(["sans.invariant"])
107
108# sans.guiframe
[0711849]109guiframe_path = os.path.join("sansguiframe", "src", "sans", "guiframe")
[d6bc28cf]110package_dir["sans.guiframe"] = guiframe_path
[8ab3302]111package_dir["sans.guiframe.local_perspectives"] = os.path.join(guiframe_path, 
112                                                        "local_perspectives")
[d6bc28cf]113package_data["sans.guiframe"] = ['images/*', 'media/*']
114packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"])
115# build local plugin
116for dir in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
117    if dir not in ['.svn','__init__.py', '__init__.pyc']:
118        package_name = "sans.guiframe.local_perspectives." + dir
119        packages.append(package_name)
[8ab3302]120        package_dir[package_name] = os.path.join(guiframe_path, 
121                                                 "local_perspectives", dir)
[d6bc28cf]122
123# sans.dataloader
[8ab3302]124package_dir["sans.dataloader"] = os.path.join("sansdataloader", 
125                                              "src", "sans", "dataloader")
[d6bc28cf]126package_data["sans.dataloader.readers"] = ['defaults.xml']
127packages.extend(["sans.dataloader","sans.dataloader.readers"])
128
129# sans.calculator
130package_dir["sans.calculator"] = "sanscalculator/src/sans/calculator"
131packages.extend(["sans.calculator"])
132   
133# sans.pr
[cb5fb4a]134numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
[d6bc28cf]135srcdir  = os.path.join("pr_inversion", "src", "sans", "pr", "c_extensions")
136
137
138   
139package_dir["sans.pr.core"] = srcdir
140package_dir["sans.pr"] = os.path.join("pr_inversion", "src","sans", "pr")
141packages.extend(["sans.pr","sans.pr.core"])
142ext_modules.append( Extension("sans.pr.core.pr_inversion",
[29e96f3]143                              sources = [ os.path.join(srcdir, "Cinvertor.c"),
144                                         os.path.join(srcdir, "invertor.c"),
145                                         ],
146                              include_dirs=[numpy_incl_path],
147                              ) )
[d6bc28cf]148       
149# sans.fit (park integration)
150package_dir["sans.fit"] = "park_integration/src/sans/fit"
151packages.append("sans.fit")
152
153# inversion view
154package_dir["sans.perspectives"] = "inversionview/src/sans/perspectives"
155package_dir["sans.perspectives.pr"] = "inversionview/src/sans/perspectives/pr"
156packages.extend(["sans.perspectives","sans.perspectives.pr"])
157package_data["sans.perspectives.pr"] = ['images/*']
158
159# Invariant view
[8ab3302]160package_dir["sans.perspectives"] = os.path.join("invariantview", "src", 
161                                                "sans", "perspectives")
162package_dir["sans.perspectives.invariant"] = os.path.join("invariantview", 
163                                    "src", "sans", "perspectives", "invariant")
[d6bc28cf]164               
165package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')]
166packages.extend(["sans.perspectives","sans.perspectives.invariant"]) 
167
168# Fitting view
[8ab3302]169fitting_path = os.path.join("fittingview", "src", "sans", 
170                            "perspectives", "fitting")
171package_dir["sans.perspectives"] = os.path.join("fittingview", 
172                                            "src", "sans", "perspectives"),
173package_dir["sans.perspectives.fitting"] = fitting_path
174package_dir["sans.perspectives.fitting.plugin_models"] = \
175                                os.path.join(fitting_path, "plugin_models")
[8ca5890]176package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*']
[8ab3302]177packages.extend(["sans.perspectives", "sans.perspectives.fitting", 
178                 "sans.perspectives.fitting.plugin_models"])
[d6bc28cf]179
180# Calculator view
181package_dir["sans.perspectives"] = "calculatorview/src/sans/perspectives"
[8ab3302]182package_dir["sans.perspectives.calculator"] = os.path.join("calculatorview", 
183                                "src", "sans", "perspectives", "calculator")
[d6bc28cf]184package_data['sans.perspectives.calculator'] = ['images/*', 'media/*']
185packages.extend(["sans.perspectives", "sans.perspectives.calculator"])
186     
187# Data util
188package_dir["data_util"] = "sansutil"
189packages.extend(["data_util"])
190
191# Plottools
192package_dir["danse"] = os.path.join("plottools", "src", "danse")
[8ab3302]193package_dir["danse.common"] = os.path.join("plottools", "src", 
194                                           "danse", "common")
195package_dir["danse.common.plottools"] = os.path.join("plottools", 
196                                    "src", "danse", "common", "plottools")
[d6bc28cf]197packages.extend(["danse", "danse.common", "danse.common.plottools"])
198
199# Park 1.2.1
200package_dir["park"]="park-1.2.1/park"
201packages.extend(["park"])
202package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc']
203ext_modules.append( Extension("park._modeling",
[8ab3302]204                              sources = [ os.path.join("park-1.2.1", 
205                                                "park", "lib", "modeling.cc"),
206                                         os.path.join("park-1.2.1", 
207                                                "park", "lib", "resolution.c"),
[29e96f3]208                                         ],
209                              ) )
[d6bc28cf]210
211# Sans models
212srcdir  = os.path.join("sansmodels", "src", "sans", "models", "c_extensions")
213igordir = os.path.join("sansmodels", "src","sans", "models", "libigor")
214c_model_dir = os.path.join("sansmodels", "src", "sans", "models", "c_models")
215smear_dir  = os.path.join("sansmodels", "src", "sans", "models", "c_smearer")
216
217IGNORED_FILES = ["a.exe",
218                 "__init__.py"
219                 ".svn",
220                   "lineparser.py",
221                   "run.py",
222                   "CGaussian.cpp",
223                   "CLogNormal.cpp",
224                   "CLorentzian.cpp",
225                   "CSchulz.cpp",
226                   "WrapperGenerator.py",
[8b9a2be]227                   "wrapping.py"
228                   ]
[9cde4cc]229
230if not os.name=='nt':
[2c63e80e]231    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
[9cde4cc]232
233
[d6bc28cf]234EXTENSIONS = [".c", ".cpp"]
235
236def append_file(file_list, dir_path):
237    """
238    Add sources file to sources
239    """
240    for f in os.listdir(dir_path):
241        if os.path.isfile(os.path.join(dir_path, f)):
242            _, ext = os.path.splitext(f)
243            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
244                file_list.append(os.path.join(dir_path, f)) 
245        elif os.path.isdir(os.path.join(dir_path, f)) and \
246                not f.startswith("."):
247            sub_dir = os.path.join(dir_path, f)
248            for new_f in os.listdir(sub_dir):
249                if os.path.isfile(os.path.join(sub_dir, new_f)):
250                    _, ext = os.path.splitext(new_f)
251                    if ext.lower() in EXTENSIONS and\
252                         new_f not in IGNORED_FILES:
253                        file_list.append(os.path.join(sub_dir, new_f)) 
254       
255model_sources = []
256append_file(file_list=model_sources, dir_path=srcdir)
257append_file(file_list=model_sources, dir_path=igordir)
258append_file(file_list=model_sources, dir_path=c_model_dir)
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")
265package_dir["sans.models.sans_extension"] = srcdir
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,                 
[8ab3302]278                                include_dirs=[igordir, srcdir, 
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.