source: sasview/setup.py @ cfe472e

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 cfe472e was f9393dc, checked in by pkienzle, 10 years ago

remove park refs from build/run

  • Property mode set to 100644
File size: 14.1 KB
RevLine 
[d6bc28cf]1"""
[c329f4d]2    Setup for SasView
[d6bc28cf]3    #TODO: Add checks to see that all the dependencies are on the system
4"""
[8ab3302]5import sys
[d6bc28cf]6import os
[5980b1a]7from setuptools import setup, Extension
[2cef9d3]8from distutils.command.build_ext import build_ext
[968aa6e]9from distutils.core import Command
10
[e13ef7f]11try:
12    from numpy.distutils.misc_util import get_numpy_include_dirs
13    NUMPY_INC = get_numpy_include_dirs()[0]
14except:
[cb5fb4a]15    try:
[e13ef7f]16        import numpy
[8ab3302]17        NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0], 
18                                 "core","include")
[cb5fb4a]19    except:
[c329f4d]20        msg = "\nNumpy is needed to build SasView. "
[8ab3302]21        print msg, "Try easy_install numpy.\n  %s" % str(sys.exc_value)
[e13ef7f]22        sys.exit(0)
[d6bc28cf]23
[5548954]24# Manage version number ######################################
[3a39c2e]25import sasview
26VERSION = sasview.__version__
[5548954]27##############################################################
28
[d6bc28cf]29package_dir = {}
30package_data = {}
31packages = []
32ext_modules = []
33
[8ab3302]34# Remove all files that should be updated by this setup
[3a39c2e]35# We do this here because application updates these files from .sasview
[8ab3302]36# except when there is no such file
37# Todo : make this list generic
38plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py', 
39                     'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py', 
[b30ed8f]40                     'testmodel_2.py', 'testmodel.py',
41                     'polynominal5.pyc', 'sph_bessel_jn.pyc', 
42                     'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc', 
[eb32080e]43                     'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log']
[3a39c2e]44sas_dir = os.path.join(os.path.expanduser("~"),'.sasview')
45if os.path.isdir(sas_dir):
46    f_path = os.path.join(sas_dir, "sasview.log")
[e615a0d]47    if os.path.isfile(f_path):
48        os.remove(f_path)
[3a39c2e]49    f_path = os.path.join(sas_dir, "serialized_cat.json")
[ea5fa58]50    if os.path.isfile(f_path):
51        os.remove(f_path)
[3a39c2e]52    f_path = os.path.join(sas_dir, 'config', "custom_config.py")
[e615a0d]53    if os.path.isfile(f_path):
54        os.remove(f_path)
[3a39c2e]55    f_path = os.path.join(sas_dir, 'plugin_models')
[e615a0d]56    if os.path.isdir(f_path):
[5980b1a]57        for f in os.listdir(f_path): 
58            if f in plugin_model_list:
59                file_path =  os.path.join(f_path, f)
[e615a0d]60                os.remove(file_path)
61                   
62# 'sys.maxsize' and 64bit: Not supported for python2.5
63is_64bits = False
64if sys.version_info >= (2, 6):
65    is_64bits = sys.maxsize > 2**32
66   
[7a04dbb]67enable_openmp = False
[e79a467]68
[f468791]69if sys.platform =='darwin':
70    if not is_64bits:
71        # Disable OpenMP
72        enable_openmp = False
73    else:
74        # Newer versions of Darwin don't support openmp
75        try:
76            darwin_ver = int(os.uname()[2].split('.')[0])
77            if darwin_ver >= 12:
78                enable_openmp = False
79        except:
80            print "PROBLEM determining Darwin version"
[b30ed8f]81
82# Options to enable OpenMP
83copt =  {'msvc': ['/openmp'],
84         'mingw32' : ['-fopenmp'],
85         'unix' : ['-fopenmp']}
86lopt =  {'msvc': ['/MANIFEST'],
87         'mingw32' : ['-fopenmp'],
88         'unix' : ['-lgomp']}
[13f00a0]89
[ebdb833]90# Platform-specific link options
91platform_lopt = {'msvc' : ['/MANIFEST']}
[307fa4f]92platform_copt = {}
[b9c8fc5]93
94# Set copts to get compile working on OS X >= 10.9 using clang
95if sys.platform =='darwin':
96    try:
97        darwin_ver = int(os.uname()[2].split('.')[0])
98        if darwin_ver >= 13:
99            platform_copt = {'unix' : ['-Wno-error=unused-command-line-argument-hard-error-in-future']}
100    except:
101        print "PROBLEM determining Darwin version"
102
[5972029]103class DisableOpenMPCommand(Command):
104    description = "The version of MinGW that comes with Anaconda does not come with OpenMP :( "\
105                  "This commands means we can turn off compiling with OpenMP for this or any "\
106                  "other reason."
107    user_options = []
108
109    def initialize_options(self):
110        self.cwd = None
111
112    def finalize_options(self):
113        self.cwd = os.getcwd()
114        global enable_openmp
115        enable_openmp = False
[1829835]116
[5972029]117    def run(self):
118        pass
[ebdb833]119
[13f00a0]120class build_ext_subclass( build_ext ):
121    def build_extensions(self):
122        # Get 64-bitness
123        c = self.compiler.compiler_type
124        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
125       
[ebdb833]126        # OpenMP build options
[b30ed8f]127        if enable_openmp:
[13f00a0]128            if copt.has_key(c):
[5980b1a]129                for e in self.extensions:
130                    e.extra_compile_args = copt[ c ]
[13f00a0]131            if lopt.has_key(c):
132                for e in self.extensions:
133                    e.extra_link_args = lopt[ c ]
134                   
[ebdb833]135        # Platform-specific build options
136        if platform_lopt.has_key(c):
137            for e in self.extensions:
138                e.extra_link_args = platform_lopt[ c ]
139
[1829835]140        if platform_copt.has_key(c):
141            for e in self.extensions:
142                e.extra_compile_args = platform_copt[ c ]
143
144
[13f00a0]145        build_ext.build_extensions(self)
[d6bc28cf]146
[968aa6e]147class BuildSphinxCommand(Command):
148    description = "Build Sphinx documentation."
149    user_options = []
150
151    def initialize_options(self):
152        self.cwd = None
153
154    def finalize_options(self):
155        self.cwd = os.getcwd()
156
[d8c4019]157    def run(self):
158        sys.path.append("docs/sphinx-docs")
159        import build_sphinx
160
[968aa6e]161        build_sphinx.clean()
162        build_sphinx.retrieve_user_docs()
163        build_sphinx.apidoc()
164        build_sphinx.build()
165
[3a39c2e]166# sas module
167package_dir["sas"] = os.path.join("src", "sas")
168packages.append("sas")
[29e96f3]169
[3a39c2e]170# sas.invariant
171package_dir["sas.invariant"] = os.path.join("src", "sas", "invariant")
172packages.extend(["sas.invariant"])
[d6bc28cf]173
[3a39c2e]174# sas.guiframe
175guiframe_path = os.path.join("src", "sas", "guiframe")
176package_dir["sas.guiframe"] = guiframe_path
177package_dir["sas.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives"))
178package_data["sas.guiframe"] = ['images/*', 'media/*']
179packages.extend(["sas.guiframe", "sas.guiframe.local_perspectives"])
[d6bc28cf]180# build local plugin
[5980b1a]181for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
182    if d not in ['.svn','__init__.py', '__init__.pyc']:
[3a39c2e]183        package_name = "sas.guiframe.local_perspectives." + d
[3d24489]184        packages.append(package_name)
[5980b1a]185        package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d)
[d6bc28cf]186
[3a39c2e]187# sas.dataloader
188package_dir["sas.dataloader"] = os.path.join("src", "sas", "dataloader")
[25f223b]189package_data["sas.dataloader.readers"] = ['defaults.json','schema/*.xsd']
[3a39c2e]190packages.extend(["sas.dataloader","sas.dataloader.readers","sas.dataloader.readers.schema"])
[d6bc28cf]191
[3a39c2e]192# sas.calculator
193package_dir["sas.calculator"] =os.path.join("src", "sas", "calculator")
194packages.extend(["sas.calculator"])
[d6bc28cf]195   
[3a39c2e]196# sas.pr
[cb5fb4a]197numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
[3a39c2e]198srcdir  = os.path.join("src", "sas", "pr", "c_extensions")
199package_dir["sas.pr.core"] = srcdir
200package_dir["sas.pr"] = os.path.join("src","sas", "pr")
201packages.extend(["sas.pr","sas.pr.core"])
202ext_modules.append( Extension("sas.pr.core.pr_inversion",
[3d24489]203                              sources = [os.path.join(srcdir, "Cinvertor.c"),
[29e96f3]204                                         os.path.join(srcdir, "invertor.c"),
205                                         ],
206                              include_dirs=[numpy_incl_path],
207                              ) )
[d6bc28cf]208       
[f9393dc]209# sas.fit
[3a39c2e]210package_dir["sas.fit"] = os.path.join("src", "sas", "fit")
211packages.append("sas.fit")
[3d24489]212
213# Perspectives
[3a39c2e]214package_dir["sas.perspectives"] = os.path.join("src", "sas", "perspectives")
215package_dir["sas.perspectives.pr"] = os.path.join("src", "sas", "perspectives", "pr")
216packages.extend(["sas.perspectives","sas.perspectives.pr"])
217package_data["sas.perspectives.pr"] = ['images/*']
218
219package_dir["sas.perspectives.invariant"] = os.path.join("src", "sas", "perspectives", "invariant")
220packages.extend(["sas.perspectives.invariant"])
221package_data['sas.perspectives.invariant'] = [os.path.join("media",'*')]
222
223package_dir["sas.perspectives.fitting"] = os.path.join("src", "sas", "perspectives", "fitting")
224package_dir["sas.perspectives.fitting.plugin_models"] = os.path.join("src", "sas", "perspectives", "fitting", "plugin_models")
225packages.extend(["sas.perspectives.fitting", 
226                 "sas.perspectives.fitting.plugin_models"])
227package_data['sas.perspectives.fitting'] = ['media/*','plugin_models/*']
228
229packages.extend(["sas.perspectives", "sas.perspectives.calculator"])   
230package_data['sas.perspectives.calculator'] = ['images/*', 'media/*']
[3d24489]231   
[d6bc28cf]232# Data util
[3a39c2e]233package_dir["data_util"] = os.path.join("src", "sas", "data_util")
234packages.append("sas.data_util")
[d6bc28cf]235
236# Plottools
[3a39c2e]237package_dir["sas.plottools"] = os.path.join("src", "sas", "plottools")
238packages.append("sas.plottools")
[d6bc28cf]239
[3a39c2e]240# sas models
241includedir  = os.path.join("src", "sas", "models", "include")
242igordir = os.path.join("src", "sas", "models", "c_extension", "libigor")
243cephes_dir = os.path.join("src", "sas", "models", "c_extension", "cephes")
244c_model_dir = os.path.join("src", "sas", "models", "c_extension", "c_models")
245smear_dir  = os.path.join("src", "sas", "models", "c_extension", "c_smearer")
246gen_dir  = os.path.join("src", "sas", "models", "c_extension", "c_gen")
247wrapper_dir  = os.path.join("src", "sas", "models", "c_extension", "python_wrapper", "generated")
248model_dir = os.path.join("src", "sas","models")
[082c565]249
[78f74bd7]250if os.path.isdir(wrapper_dir):
251    for file in os.listdir(wrapper_dir): 
252        file_path =  os.path.join(wrapper_dir, file)
253        os.remove(file_path)
254else:
[0ba3b08]255    os.makedirs(wrapper_dir)
[3a39c2e]256sys.path.append(os.path.join("src", "sas", "models", "c_extension", "python_wrapper"))
[3d24489]257from wrapping import generate_wrappers
258generate_wrappers(header_dir = includedir, 
259                  output_dir = model_dir,
260                  c_wrapper_dir = wrapper_dir)
[2d1b700]261
[101065a]262IGNORED_FILES = [".svn"]
[9cde4cc]263if not os.name=='nt':
[2c63e80e]264    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
[9cde4cc]265
[d6bc28cf]266EXTENSIONS = [".c", ".cpp"]
267
268def append_file(file_list, dir_path):
269    """
270    Add sources file to sources
271    """
272    for f in os.listdir(dir_path):
273        if os.path.isfile(os.path.join(dir_path, f)):
274            _, ext = os.path.splitext(f)
275            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
276                file_list.append(os.path.join(dir_path, f)) 
277        elif os.path.isdir(os.path.join(dir_path, f)) and \
278                not f.startswith("."):
279            sub_dir = os.path.join(dir_path, f)
280            for new_f in os.listdir(sub_dir):
281                if os.path.isfile(os.path.join(sub_dir, new_f)):
282                    _, ext = os.path.splitext(new_f)
283                    if ext.lower() in EXTENSIONS and\
284                         new_f not in IGNORED_FILES:
285                        file_list.append(os.path.join(sub_dir, new_f)) 
286       
287model_sources = []
288append_file(file_list=model_sources, dir_path=igordir)
289append_file(file_list=model_sources, dir_path=c_model_dir)
[67424cd]290append_file(file_list=model_sources, dir_path=wrapper_dir)
291
[d6bc28cf]292smear_sources = []
293append_file(file_list=smear_sources, dir_path=smear_dir)
294       
[3a39c2e]295package_dir["sas.models"] = model_dir
296package_dir["sas.models.sas_extension"] = os.path.join("src", "sas", "models", "sas_extension")
297package_data['sas.models'] = [os.path.join('media', "*.*")]
298package_data['sas.models'] += [os.path.join('media','img', "*.*")]
299packages.extend(["sas.models","sas.models.sas_extension"])
[5980b1a]300   
301smearer_sources = [os.path.join(smear_dir, "smearer.cpp"),
302                  os.path.join(smear_dir, "smearer_module.cpp")]
303geni_sources = [os.path.join(gen_dir, "sld2i_module.cpp")]
304if os.name=='nt':
305    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
306    geni_sources.append(os.path.join(igordir, "winFuncs.c"))
[820df88]307
308c_models = [ 
[3a39c2e]309    Extension("sas.models.sas_extension.c_models",
[820df88]310        sources=model_sources,                 
311        include_dirs=[
312            igordir, includedir, c_model_dir, numpy_incl_path, cephes_dir
313        ],
314    ),
315
316    # Smearer extension
[3a39c2e]317    Extension("sas.models.sas_extension.smearer",
[820df88]318        sources = smearer_sources,
319        include_dirs=[igordir,  smear_dir, numpy_incl_path],
320    ),
[5980b1a]321                   
[3a39c2e]322    Extension("sas.models.sas_extension.smearer2d_helper",
[820df88]323        sources = [
324            os.path.join(smear_dir, "smearer2d_helper_module.cpp"),
325            os.path.join(smear_dir, "smearer2d_helper.cpp"),
[a6d2e3b]326            os.path.join(igordir, "winFuncs.c"),
[820df88]327        ],
328        include_dirs=[smear_dir, numpy_incl_path],
329    ),
[5980b1a]330                   
[3a39c2e]331    Extension("sas.models.sas_extension.sld2i",
[820df88]332        sources = [
333            os.path.join(gen_dir, "sld2i_module.cpp"),
334            os.path.join(gen_dir, "sld2i.cpp"),
335            os.path.join(c_model_dir, "libfunc.c"),
336            os.path.join(c_model_dir, "librefl.c"),
[a6d2e3b]337            os.path.join(igordir, "winFuncs.c"),
[820df88]338        ],
339        include_dirs=[gen_dir, includedir,  c_model_dir, numpy_incl_path],
340    ),
341]
342
343# Comment out the following to avoid rebuilding all the models
344ext_modules.extend(c_models)
345
[c329f4d]346# SasView
[df7a7e3]347
[3a39c2e]348package_dir["sas.sasview"] = "sasview"
349package_data['sas.sasview'] = ['images/*', 'media/*', 'test/*', 
[27b7acc]350                                 'default_categories.json']
[3a39c2e]351packages.append("sas.sasview")
[d6bc28cf]352
[9f32c57]353required = [
[b44da61]354    'bumps>=0.7.5.4', 'periodictable>=1.3.1', 'pyparsing<2.0.0',
[9f32c57]355
356    # 'lxml>=2.2.2',
357    'lxml', 
358
359    ## The following dependecies won't install automatically, so assume them
360    ## The numbers should be bumped up for matplotlib and wxPython as well.
361    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
362    # 'wxPython>=2.8.11', 'pil',
363    ]
[213b445]364
[95fe70d]365if os.name=='nt':
[7a211030]366    required.extend(['html5lib', 'reportlab'])
[7f59928e]367else:
[202c1ef]368    required.extend(['pil'])
[30ad350]369   
[5980b1a]370# Set up SasView   
[d6bc28cf]371setup(
[c329f4d]372    name="sasview",
[5548954]373    version = VERSION,
[c329f4d]374    description = "SasView application",
[d6bc28cf]375    author = "University of Tennessee",
376    author_email = "sansdanse@gmail.com",
[5980b1a]377    url = "http://sasview.org",
[d6bc28cf]378    license = "PSF",
[c329f4d]379    keywords = "small-angle x-ray and neutron scattering analysis",
[d6bc28cf]380    download_url = "https://sourceforge.net/projects/sansviewproject/files/",
381    package_dir = package_dir,
382    packages = packages,
383    package_data = package_data,
384    ext_modules = ext_modules,
385    install_requires = required,
[60f7d19]386    zip_safe = False,
[a7b774d]387    entry_points = {
388                    'console_scripts':[
[3a39c2e]389                                       "sasview = sas.sasview.sasview:run",
[a7b774d]390                                       ]
[13f00a0]391                    },
[968aa6e]392    cmdclass = {'build_ext': build_ext_subclass,
[5972029]393                'docs': BuildSphinxCommand,
394                'disable_openmp': DisableOpenMPCommand}
[d113531]395    )   
Note: See TracBrowser for help on using the repository browser.