source: sasview/setup.py @ f182f93

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since f182f93 was db74ee8, checked in by krzywon, 8 years ago

Changed h5py requirement to latest version instead of specifying v2.5

  • Property mode set to 100755
File size: 12.4 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
[c8843be]7import shutil
[5980b1a]8from setuptools import setup, Extension
[2cef9d3]9from distutils.command.build_ext import build_ext
[968aa6e]10from distutils.core import Command
[d6bc28cf]11
[5548954]12# Manage version number ######################################
[3a39c2e]13import sasview
14VERSION = sasview.__version__
[5548954]15##############################################################
16
[d6bc28cf]17package_dir = {}
18package_data = {}
19packages = []
20ext_modules = []
21
[8ab3302]22# Remove all files that should be updated by this setup
[3a39c2e]23# We do this here because application updates these files from .sasview
[8ab3302]24# except when there is no such file
25# Todo : make this list generic
[5881b17]26#plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py',
[a62945e]27#                      'sum_Ap1_1_Ap2.py', 'sum_p1_p2.py',
28#                      'testmodel_2.py', 'testmodel.py',
29#                      'polynominal5.pyc', 'sph_bessel_jn.pyc',
30#                      'sum_Ap1_1_Ap2.pyc', 'sum_p1_p2.pyc',
31#                      'testmodel_2.pyc', 'testmodel.pyc', 'plugins.log']
[c8843be]32
33CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
34SASVIEW_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build")
35
[3a39c2e]36sas_dir = os.path.join(os.path.expanduser("~"),'.sasview')
37if os.path.isdir(sas_dir):
38    f_path = os.path.join(sas_dir, "sasview.log")
[e615a0d]39    if os.path.isfile(f_path):
40        os.remove(f_path)
[50008e3]41    f_path = os.path.join(sas_dir, "categories.json")
[ea5fa58]42    if os.path.isfile(f_path):
43        os.remove(f_path)
[3a39c2e]44    f_path = os.path.join(sas_dir, 'config', "custom_config.py")
[e615a0d]45    if os.path.isfile(f_path):
46        os.remove(f_path)
[5881b17]47    #f_path = os.path.join(sas_dir, 'plugin_models')
48    #if os.path.isdir(f_path):
[a62945e]49    #     for f in os.listdir(f_path):
50    #         if f in plugin_model_list:
51    #             file_path =  os.path.join(f_path, f)
52    #             os.remove(file_path)
[c8843be]53    if os.path.exists(SASVIEW_BUILD):
54        print "Removing existing build directory", SASVIEW_BUILD, "for a clean build"
55        shutil.rmtree(SASVIEW_BUILD)
[e615a0d]56                   
57# 'sys.maxsize' and 64bit: Not supported for python2.5
58is_64bits = False
59if sys.version_info >= (2, 6):
60    is_64bits = sys.maxsize > 2**32
61   
[7a04dbb]62enable_openmp = False
[e79a467]63
[f468791]64if sys.platform =='darwin':
65    if not is_64bits:
66        # Disable OpenMP
67        enable_openmp = False
68    else:
69        # Newer versions of Darwin don't support openmp
70        try:
71            darwin_ver = int(os.uname()[2].split('.')[0])
72            if darwin_ver >= 12:
73                enable_openmp = False
74        except:
75            print "PROBLEM determining Darwin version"
[b30ed8f]76
77# Options to enable OpenMP
78copt =  {'msvc': ['/openmp'],
79         'mingw32' : ['-fopenmp'],
80         'unix' : ['-fopenmp']}
81lopt =  {'msvc': ['/MANIFEST'],
82         'mingw32' : ['-fopenmp'],
83         'unix' : ['-lgomp']}
[13f00a0]84
[ebdb833]85# Platform-specific link options
86platform_lopt = {'msvc' : ['/MANIFEST']}
[307fa4f]87platform_copt = {}
[b9c8fc5]88
89# Set copts to get compile working on OS X >= 10.9 using clang
90if sys.platform =='darwin':
91    try:
92        darwin_ver = int(os.uname()[2].split('.')[0])
[4adf48e]93        if darwin_ver >= 13 and darwin_ver < 14:
[b9c8fc5]94            platform_copt = {'unix' : ['-Wno-error=unused-command-line-argument-hard-error-in-future']}
95    except:
96        print "PROBLEM determining Darwin version"
97
[5972029]98class DisableOpenMPCommand(Command):
99    description = "The version of MinGW that comes with Anaconda does not come with OpenMP :( "\
100                  "This commands means we can turn off compiling with OpenMP for this or any "\
101                  "other reason."
102    user_options = []
103
104    def initialize_options(self):
105        self.cwd = None
106
107    def finalize_options(self):
108        self.cwd = os.getcwd()
109        global enable_openmp
110        enable_openmp = False
[1829835]111
[5972029]112    def run(self):
113        pass
[ebdb833]114
[13f00a0]115class build_ext_subclass( build_ext ):
116    def build_extensions(self):
117        # Get 64-bitness
118        c = self.compiler.compiler_type
119        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
120       
[ebdb833]121        # OpenMP build options
[b30ed8f]122        if enable_openmp:
[13f00a0]123            if copt.has_key(c):
[5980b1a]124                for e in self.extensions:
125                    e.extra_compile_args = copt[ c ]
[13f00a0]126            if lopt.has_key(c):
127                for e in self.extensions:
128                    e.extra_link_args = lopt[ c ]
129                   
[ebdb833]130        # Platform-specific build options
131        if platform_lopt.has_key(c):
132            for e in self.extensions:
133                e.extra_link_args = platform_lopt[ c ]
134
[1829835]135        if platform_copt.has_key(c):
136            for e in self.extensions:
137                e.extra_compile_args = platform_copt[ c ]
138
139
[13f00a0]140        build_ext.build_extensions(self)
[d6bc28cf]141
[968aa6e]142class BuildSphinxCommand(Command):
143    description = "Build Sphinx documentation."
144    user_options = []
145
146    def initialize_options(self):
147        self.cwd = None
148
149    def finalize_options(self):
150        self.cwd = os.getcwd()
151
[d8c4019]152    def run(self):
153        sys.path.append("docs/sphinx-docs")
154        import build_sphinx
[c2ee2b1]155        build_sphinx.rebuild()
[968aa6e]156
[3a39c2e]157# sas module
158package_dir["sas"] = os.path.join("src", "sas")
159packages.append("sas")
[29e96f3]160
[e0bbb7c]161# sas module
162package_dir["sas.sasgui"] = os.path.join("src", "sas", "sasgui")
163packages.append("sas.sasgui")
164
165# sas module
166package_dir["sas.sascalc"] = os.path.join("src", "sas", "sascalc")
167packages.append("sas.sascalc")
168
169# sas.sascalc.invariant
170package_dir["sas.sascalc.invariant"] = os.path.join("src", "sas", "sascalc", "invariant")
171packages.extend(["sas.sascalc.invariant"])
[d6bc28cf]172
[d85c194]173# sas.sasgui.guiframe
174guiframe_path = os.path.join("src", "sas", "sasgui", "guiframe")
175package_dir["sas.sasgui.guiframe"] = guiframe_path
176package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join(os.path.join(guiframe_path, "local_perspectives"))
177package_data["sas.sasgui.guiframe"] = ['images/*', 'media/*']
178packages.extend(["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"])
[d6bc28cf]179# build local plugin
[5980b1a]180for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
181    if d not in ['.svn','__init__.py', '__init__.pyc']:
[d85c194]182        package_name = "sas.sasgui.guiframe.local_perspectives." + d
[3d24489]183        packages.append(package_name)
[5980b1a]184        package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", d)
[d6bc28cf]185
[e0bbb7c]186# sas.sascalc.dataloader
187package_dir["sas.sascalc.dataloader"] = os.path.join("src", "sas", "sascalc", "dataloader")
188package_data["sas.sascalc.dataloader.readers"] = ['defaults.json','schema/*.xsd']
189packages.extend(["sas.sascalc.dataloader","sas.sascalc.dataloader.readers","sas.sascalc.dataloader.readers.schema"])
[d6bc28cf]190
[e0bbb7c]191# sas.sascalc.calculator
[9e531f2]192gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions")
193package_dir["sas.sascalc.calculator.core"] = gen_dir
194package_dir["sas.sascalc.calculator"] = os.path.join("src", "sas", "sascalc", "calculator")
195packages.extend(["sas.sascalc.calculator","sas.sascalc.calculator.core"])
196ext_modules.append( Extension("sas.sascalc.calculator.core.sld2i",
197        sources = [
198            os.path.join(gen_dir, "sld2i_module.cpp"),
199            os.path.join(gen_dir, "sld2i.cpp"),
200            os.path.join(gen_dir, "libfunc.c"),
201            os.path.join(gen_dir, "librefl.c"),
202        ],
[f567f92f]203        include_dirs=[gen_dir],
[9e531f2]204    )
205)
206
[d6bc28cf]207   
[b699768]208# sas.sascalc.pr
209srcdir  = os.path.join("src", "sas", "sascalc", "pr", "c_extensions")
210package_dir["sas.sascalc.pr.core"] = srcdir
211package_dir["sas.sascalc.pr"] = os.path.join("src","sas", "sascalc", "pr")
212packages.extend(["sas.sascalc.pr","sas.sascalc.pr.core"])
213ext_modules.append( Extension("sas.sascalc.pr.core.pr_inversion",
[3d24489]214                              sources = [os.path.join(srcdir, "Cinvertor.c"),
[29e96f3]215                                         os.path.join(srcdir, "invertor.c"),
216                                         ],
[f567f92f]217                              include_dirs=[],
[29e96f3]218                              ) )
[d6bc28cf]219       
[b699768]220# sas.sascalc.fit
221package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit")
222packages.append("sas.sascalc.fit")
[3d24489]223
224# Perspectives
[d85c194]225package_dir["sas.sasgui.perspectives"] = os.path.join("src", "sas", "sasgui", "perspectives")
226package_dir["sas.sasgui.perspectives.pr"] = os.path.join("src", "sas", "sasgui", "perspectives", "pr")
227packages.extend(["sas.sasgui.perspectives","sas.sasgui.perspectives.pr"])
228package_data["sas.sasgui.perspectives.pr"] = ['images/*']
229
230package_dir["sas.sasgui.perspectives.invariant"] = os.path.join("src", "sas", "sasgui", "perspectives", "invariant")
231packages.extend(["sas.sasgui.perspectives.invariant"])
232package_data['sas.sasgui.perspectives.invariant'] = [os.path.join("media",'*')]
233
234package_dir["sas.sasgui.perspectives.fitting"] = os.path.join("src", "sas", "sasgui", "perspectives", "fitting")
[a7c4ad2]235package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join("src", "sas", "sasgui", "perspectives", "fitting", "plugin_models")
236packages.extend(["sas.sasgui.perspectives.fitting", "sas.sasgui.perspectives.fitting.plugin_models"])
237package_data['sas.sasgui.perspectives.fitting'] = ['media/*', 'plugin_models/*']
[d85c194]238
[9e531f2]239packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.calculator"])
[d85c194]240package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*']
[3d24489]241   
[d6bc28cf]242# Data util
[e0bbb7c]243package_dir["sas.sascalc.data_util"] = os.path.join("src", "sas", "sascalc", "data_util")
[b699768]244packages.append("sas.sascalc.data_util")
[d6bc28cf]245
246# Plottools
[d7bb526]247package_dir["sas.sasgui.plottools"] = os.path.join("src", "sas", "sasgui", "plottools")
248packages.append("sas.sasgui.plottools")
[d6bc28cf]249
[9274711]250# # Last of the sas.models
251# package_dir["sas.models"] = os.path.join("src", "sas", "models")
252# packages.append("sas.models")
[2d1b700]253
[d6bc28cf]254EXTENSIONS = [".c", ".cpp"]
255
256def append_file(file_list, dir_path):
257    """
258    Add sources file to sources
259    """
260    for f in os.listdir(dir_path):
261        if os.path.isfile(os.path.join(dir_path, f)):
262            _, ext = os.path.splitext(f)
[4c29e4d]263            if ext.lower() in EXTENSIONS:
[9e531f2]264                file_list.append(os.path.join(dir_path, f))
[d6bc28cf]265        elif os.path.isdir(os.path.join(dir_path, f)) and \
266                not f.startswith("."):
267            sub_dir = os.path.join(dir_path, f)
268            for new_f in os.listdir(sub_dir):
269                if os.path.isfile(os.path.join(sub_dir, new_f)):
270                    _, ext = os.path.splitext(new_f)
[4c29e4d]271                    if ext.lower() in EXTENSIONS:
[9e531f2]272                        file_list.append(os.path.join(sub_dir, new_f))
[820df88]273
274# Comment out the following to avoid rebuilding all the models
[9e531f2]275file_sources = []
276append_file(file_sources, gen_dir)
[820df88]277
[5881b17]278#Wojtek's hacky way to add doc files while bundling egg
279#def add_doc_files(directory):
280#    paths = []
281#    for (path, directories, filenames) in os.walk(directory):
282#        for filename in filenames:
283#            paths.append(os.path.join(path, filename))
284#    return paths
285
286#doc_files = add_doc_files('doc')
287
[c329f4d]288# SasView
[3a39c2e]289package_dir["sas.sasview"] = "sasview"
[5881b17]290package_data['sas.sasview'] = ['images/*',
[bbb8a56]291                               'media/*',
[d4c88e24]292                               'test/*.txt',
[bbb8a56]293                               'test/1d_data/*',
294                               'test/2d_data/*',
295                               'test/save_states/*',
296                               'test/upcoming_formats/*', 
[27b7acc]297                                 'default_categories.json']
[3a39c2e]298packages.append("sas.sasview")
[d6bc28cf]299
[9f32c57]300required = [
[243fbc0]301    'bumps>=0.7.5.9', 'periodictable>=1.3.1', 'pyparsing<2.0.0',
[9f32c57]302
303    # 'lxml>=2.2.2',
[db74ee8]304    'lxml', 'h5py',
[9f32c57]305
306    ## The following dependecies won't install automatically, so assume them
307    ## The numbers should be bumped up for matplotlib and wxPython as well.
308    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
309    # 'wxPython>=2.8.11', 'pil',
310    ]
[213b445]311
[95fe70d]312if os.name=='nt':
[7a211030]313    required.extend(['html5lib', 'reportlab'])
[7f59928e]314else:
[775d06f]315    # 'pil' is now called 'pillow'
[5f6336f]316    required.extend(['pillow'])
[5881b17]317
[5980b1a]318# Set up SasView   
[d6bc28cf]319setup(
[c329f4d]320    name="sasview",
[5548954]321    version = VERSION,
[c329f4d]322    description = "SasView application",
[038ccfe6]323    author = "SasView Team",
324    author_email = "developers@sasview.org",
[5980b1a]325    url = "http://sasview.org",
[d6bc28cf]326    license = "PSF",
[c329f4d]327    keywords = "small-angle x-ray and neutron scattering analysis",
[038ccfe6]328    download_url = "https://github.com/SasView/sasview.git",
[d6bc28cf]329    package_dir = package_dir,
330    packages = packages,
331    package_data = package_data,
332    ext_modules = ext_modules,
333    install_requires = required,
[60f7d19]334    zip_safe = False,
[a7b774d]335    entry_points = {
336                    'console_scripts':[
[3a39c2e]337                                       "sasview = sas.sasview.sasview:run",
[a7b774d]338                                       ]
[13f00a0]339                    },
[968aa6e]340    cmdclass = {'build_ext': build_ext_subclass,
[5972029]341                'docs': BuildSphinxCommand,
342                'disable_openmp': DisableOpenMPCommand}
[d113531]343    )   
Note: See TracBrowser for help on using the repository browser.