source: sasview/setup.py @ 914ba0a

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 914ba0a was 914ba0a, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

merge with master

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