source: sasview/setup.py @ 6bdf6ae

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

fix logging

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