source: sasview/setup.py @ 6c7e4cc1

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.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 6c7e4cc1 was 6c7e4cc1, checked in by ajj, 7 years ago

Updating setup.py to call sasmodels doc build

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