source: sasview/setup.py @ ebdb833

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

Re #5 Make sure platform-specific build options are separated from openmp option

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