source: sasview/setup.py @ b30ed8f

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

move plugin log to plugin_models dir

  • Property mode set to 100644
File size: 13.2 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
10import os
11import platform
12from setuptools import setup, Extension, find_packages
13from distutils.command.build_ext import build_ext
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 SansView. "
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']
48sans_dir = os.path.join(os.path.expanduser("~"),'.sansview')
49if os.path.isdir(sans_dir):
50    f_path = os.path.join(sans_dir, "sansview.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
63enable_openmp = True                   
64if sys.argv[-1] == "-nomp":
65    # Disable OpenMP
66    enable_openmp = False
67if sys.platform =='darwin' and not is_64bits:
68    # Disable OpenMP
69    enable_openmp = False
70
71# Options to enable OpenMP
72copt =  {'msvc': ['/openmp'],
73         'mingw32' : ['-fopenmp'],
74         'unix' : ['-fopenmp']}
75lopt =  {'msvc': ['/MANIFEST'],
76         'mingw32' : ['-fopenmp'],
77         'unix' : ['-lgomp']}
78
79class build_ext_subclass( build_ext ):
80    def build_extensions(self):
81        # Get 64-bitness
82        if sys.version_info >= (2, 6):
83            is_64bits = sys.maxsize > 2**32
84        else:
85            # 'sys.maxsize' and 64bit: Not supported for python2.5
86            is_64bits = False
87       
88        c = self.compiler.compiler_type
89        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
90       
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               
97                for e in self.extensions:
98                    e.extra_link_args = lopt[ c ]
99                   
100        build_ext.build_extensions(self)
101
102
103# sans.invariant
104package_dir["sans.invariant"] = "sansinvariant/src/sans/invariant"
105packages.extend(["sans.invariant"])
106
107# sans.guiframe
108guiframe_path = os.path.join("sansguiframe", "src", "sans", "guiframe")
109package_dir["sans.guiframe"] = guiframe_path
110package_dir["sans.guiframe.local_perspectives"] = os.path.join(guiframe_path, 
111                                                        "local_perspectives")
112package_data["sans.guiframe"] = ['images/*', 'media/*']
113packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"])
114# build local plugin
115for dir in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
116    if dir not in ['.svn','__init__.py', '__init__.pyc']:
117        package_name = "sans.guiframe.local_perspectives." + dir
118        packages.append(package_name)
119        package_dir[package_name] = os.path.join(guiframe_path, 
120                                                 "local_perspectives", dir)
121
122# sans.dataloader
123package_dir["sans.dataloader"] = os.path.join("sansdataloader", 
124                                              "src", "sans", "dataloader")
125package_data["sans.dataloader.readers"] = ['defaults.xml']
126packages.extend(["sans.dataloader","sans.dataloader.readers"])
127
128# sans.calculator
129package_dir["sans.calculator"] = "sanscalculator/src/sans/calculator"
130packages.extend(["sans.calculator"])
131   
132# sans.pr
133numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
134srcdir  = os.path.join("pr_inversion", "src", "sans", "pr", "c_extensions")
135
136
137   
138package_dir["sans.pr.core"] = srcdir
139package_dir["sans.pr"] = os.path.join("pr_inversion", "src","sans", "pr")
140packages.extend(["sans.pr","sans.pr.core"])
141ext_modules.append( Extension("sans.pr.core.pr_inversion",
142                              sources = [ os.path.join(srcdir, "Cinvertor.c"),
143                                         os.path.join(srcdir, "invertor.c"),
144                                         ],
145                              include_dirs=[numpy_incl_path],
146                              ) )
147       
148# sans.fit (park integration)
149package_dir["sans.fit"] = "park_integration/src/sans/fit"
150packages.append("sans.fit")
151
152# inversion view
153package_dir["sans.perspectives"] = "inversionview/src/sans/perspectives"
154package_dir["sans.perspectives.pr"] = "inversionview/src/sans/perspectives/pr"
155packages.extend(["sans.perspectives","sans.perspectives.pr"])
156package_data["sans.perspectives.pr"] = ['images/*']
157
158# Invariant view
159package_dir["sans.perspectives"] = os.path.join("invariantview", "src", 
160                                                "sans", "perspectives")
161package_dir["sans.perspectives.invariant"] = os.path.join("invariantview", 
162                                    "src", "sans", "perspectives", "invariant")
163               
164package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')]
165packages.extend(["sans.perspectives","sans.perspectives.invariant"]) 
166
167# Fitting view
168fitting_path = os.path.join("fittingview", "src", "sans", 
169                            "perspectives", "fitting")
170package_dir["sans.perspectives"] = os.path.join("fittingview", 
171                                            "src", "sans", "perspectives"),
172package_dir["sans.perspectives.fitting"] = fitting_path
173package_dir["sans.perspectives.fitting.plugin_models"] = \
174                                os.path.join(fitting_path, "plugin_models")
175package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*']
176packages.extend(["sans.perspectives", "sans.perspectives.fitting", 
177                 "sans.perspectives.fitting.plugin_models"])
178
179# Calculator view
180package_dir["sans.perspectives"] = "calculatorview/src/sans/perspectives"
181package_dir["sans.perspectives.calculator"] = os.path.join("calculatorview", 
182                                "src", "sans", "perspectives", "calculator")
183package_data['sans.perspectives.calculator'] = ['images/*', 'media/*']
184packages.extend(["sans.perspectives", "sans.perspectives.calculator"])
185     
186# Data util
187package_dir["data_util"] = "sansutil"
188packages.extend(["data_util"])
189
190# Plottools
191package_dir["danse"] = os.path.join("plottools", "src", "danse")
192package_dir["danse.common"] = os.path.join("plottools", "src", 
193                                           "danse", "common")
194package_dir["danse.common.plottools"] = os.path.join("plottools", 
195                                    "src", "danse", "common", "plottools")
196packages.extend(["danse", "danse.common", "danse.common.plottools"])
197
198# Park 1.2.1
199package_dir["park"]="park-1.2.1/park"
200packages.extend(["park"])
201package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc']
202ext_modules.append( Extension("park._modeling",
203                              sources = [ os.path.join("park-1.2.1", 
204                                                "park", "lib", "modeling.cc"),
205                                         os.path.join("park-1.2.1", 
206                                                "park", "lib", "resolution.c"),
207                                         ],
208                              ) )
209
210# Sans models
211srcdir  = os.path.join("sansmodels", "src", "sans", "models", "c_extensions")
212igordir = os.path.join("sansmodels", "src","sans", "models", "libigor")
213c_model_dir = os.path.join("sansmodels", "src", "sans", "models", "c_models")
214smear_dir  = os.path.join("sansmodels", "src", "sans", "models", "c_smearer")
215
216IGNORED_FILES = ["a.exe",
217                 "__init__.py"
218                 ".svn",
219                   "lineparser.py",
220                   "run.py",
221                   "CGaussian.cpp",
222                   "CLogNormal.cpp",
223                   "CLorentzian.cpp",
224                   "CSchulz.cpp",
225                   "WrapperGenerator.py",
226                   "wrapping.py"
227                   ]
228
229if not os.name=='nt':
230    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
231
232
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=srcdir)
256append_file(file_list=model_sources, dir_path=igordir)
257append_file(file_list=model_sources, dir_path=c_model_dir)
258smear_sources = []
259append_file(file_list=smear_sources, dir_path=smear_dir)
260
261
262package_dir["sans"] = os.path.join("sansmodels", "src", "sans")
263package_dir["sans.models"] = os.path.join("sansmodels", "src", "sans", "models")
264package_dir["sans.models.sans_extension"] = srcdir
265           
266package_data['sans.models'] = [os.path.join('media', "*")]
267packages.extend(["sans","sans.models","sans.models.sans_extension"])
268   
269smearer_sources = [os.path.join(smear_dir, "smearer.cpp"),
270                  os.path.join(smear_dir, "smearer_module.cpp")]
271
272if os.name=='nt':
273    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
274
275ext_modules.extend( [ Extension("sans.models.sans_extension.c_models",
276                                sources=model_sources,                 
277                                include_dirs=[igordir, srcdir, 
278                                              c_model_dir, numpy_incl_path],
279                                ),       
280                    # Smearer extension
281                    Extension("sans.models.sans_extension.smearer",
282                              sources = smearer_sources,
283                              include_dirs=[igordir, 
284                                            smear_dir, numpy_incl_path],
285                              ),
286                   
287                    Extension("sans.models.sans_extension.smearer2d_helper",
288                              sources = [os.path.join(smear_dir, 
289                                                "smearer2d_helper_module.cpp"),
290                                         os.path.join(smear_dir, 
291                                                "smearer2d_helper.cpp"),],
292                              include_dirs=[smear_dir,numpy_incl_path],
293                              )
294                    ] )
295       
296# SansView
297package_dir["sans.sansview"] = "sansview"
298package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*']
299packages.append("sans.sansview")
300
301#required = ['lxml>=2.2.2', 'numpy>=1.4.1', 'matplotlib>=0.99.1.1',
302#            'wxPython>=2.8.11', 'pil',
303#            'periodictable>=1.3.0', 'scipy>=0.7.2']
304required = ['lxml','periodictable>=1.3.0']
305"""
306if os.name=='nt':
307    #required.extend(['comtypes', 'pisa', 'html5lib', 'reportlab'])
308    #required.extend(['pisa', 'html5lib'])
309    if sys.version_info < (2, 7):
310        required.append('comtypes')
311else:
312    required.extend(['pil'])
313"""   
314 # Set up SansView   
315setup(
316    name="sansview",
317    version = VERSION,
318    description = "SansView application",
319    author = "University of Tennessee",
320    author_email = "sansdanse@gmail.com",
321    url = "http://danse.chem.utk.edu",
322    license = "PSF",
323    keywords = "small-angle neutron scattering analysis",
324    download_url = "https://sourceforge.net/projects/sansviewproject/files/",
325    package_dir = package_dir,
326    packages = packages,
327    package_data = package_data,
328    ext_modules = ext_modules,
329    install_requires = required,
330    zip_safe = False,
331    entry_points = {
332                    'console_scripts':[
333                                       "sansview = sans.sansview.sansview:run",
334                                       ]
335                    },
336    cmdclass = {'build_ext': build_ext_subclass }
337    )   
Note: See TracBrowser for help on using the repository browser.