source: sasview/setup.py @ 45eddeb7

Last change on this file since 45eddeb7 was 1a3602d, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

tinycc support in setup (sldi branch)

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