source: sasview/setup.py @ 1309205b

Last change on this file since 1309205b was e20870bc, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Masking dialog for fitting

  • Property mode set to 100644
File size: 17.8 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
[f36e01f]16
[9a5097c]17import numpy as np
[f36e01f]18from setuptools import Extension, setup
[d6bc28cf]19
[3010f68]20try:
21    import tinycc.distutils
22except ImportError:
23    pass
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)
[14ec91c5]60    #f_path = os.path.join(sas_dir, "categories.json")
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
[18e7309]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
[f36e01f]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)))
[18e7309]145
[ebdb833]146        # OpenMP build options
[b30ed8f]147        if enable_openmp:
[f3bf622]148            if c in copt:
[5980b1a]149                for e in self.extensions:
[f36e01f]150                    e.extra_compile_args = copt[c]
[f3bf622]151            if c in lopt:
[13f00a0]152                for e in self.extensions:
[f36e01f]153                    e.extra_link_args = lopt[c]
[18e7309]154
[ebdb833]155        # Platform-specific build options
[f3bf622]156        if c in platform_lopt:
[ebdb833]157            for e in self.extensions:
[f36e01f]158                e.extra_link_args = platform_lopt[c]
[ebdb833]159
[f3bf622]160        if c in platform_copt:
[1829835]161            for e in self.extensions:
[f36e01f]162                e.extra_compile_args = platform_copt[c]
[1829835]163
[13f00a0]164        build_ext.build_extensions(self)
[d6bc28cf]165
[f36e01f]166
[968aa6e]167class BuildSphinxCommand(Command):
168    description = "Build Sphinx documentation."
169    user_options = []
170
171    def initialize_options(self):
172        self.cwd = None
173
174    def finalize_options(self):
175        self.cwd = os.getcwd()
176
[d8c4019]177    def run(self):
[115eb7e]178        ''' First builds the sasmodels documentation if the directory
179        is present. Then builds the sasview docs.
180        '''
181        ### AJJ - Add code for building sasmodels docs here:
182        # check for doc path
[14bb7a4]183        SASMODELS_DOCPATH = os.path.abspath(os.path.join(os.getcwd(), '..', 'sasmodels', 'doc'))
184        print("========= check for sasmodels at", SASMODELS_DOCPATH, "============")
[6c7e4cc1]185        if os.path.exists(SASMODELS_DOCPATH):
186            if os.path.isdir(SASMODELS_DOCPATH):
[115eb7e]187                # if available, build sasmodels docs
[21bba86]188                print("============= Building sasmodels model documentation ===============")
[14bb7a4]189                smdocbuild = subprocess.call(["make", "-C", SASMODELS_DOCPATH, "html"])
[6c7e4cc1]190        else:
191            # if not available warning message
[21bba86]192            print("== !!WARNING!! sasmodels directory not found. Cannot build model docs. ==")
[115eb7e]193
194        #Now build sasview (+sasmodels) docs
[d8c4019]195        sys.path.append("docs/sphinx-docs")
196        import build_sphinx
[c2ee2b1]197        build_sphinx.rebuild()
[968aa6e]198
[f36e01f]199
[3a39c2e]200# sas module
201package_dir["sas"] = os.path.join("src", "sas")
202packages.append("sas")
[29e96f3]203
[e0bbb7c]204# sas module
[985ad94]205# qt module
206package_dir["sas.qtgui"] = os.path.join("src", "sas", "qtgui")
207packages.append("sas.qtgui")
208
[e0bbb7c]209# sas module
210package_dir["sas.sascalc"] = os.path.join("src", "sas", "sascalc")
211packages.append("sas.sascalc")
212
213# sas.sascalc.invariant
[f36e01f]214package_dir["sas.sascalc.invariant"] = os.path.join(
215    "src", "sas", "sascalc", "invariant")
[e0bbb7c]216packages.extend(["sas.sascalc.invariant"])
[d6bc28cf]217
218
[e0bbb7c]219# sas.sascalc.dataloader
[f36e01f]220package_dir["sas.sascalc.dataloader"] = os.path.join(
221    "src", "sas", "sascalc", "dataloader")
[7a5d066]222package_data["sas.sascalc.dataloader.readers"] = ['schema/*.xsd']
[f36e01f]223packages.extend(["sas.sascalc.dataloader", "sas.sascalc.dataloader.readers",
224                 "sas.sascalc.dataloader.readers.schema"])
[d6bc28cf]225
226
[e0bbb7c]227# sas.sascalc.calculator
[9e531f2]228gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions")
229package_dir["sas.sascalc.calculator.core"] = gen_dir
[f36e01f]230package_dir["sas.sascalc.calculator"] = os.path.join(
231    "src", "sas", "sascalc", "calculator")
232packages.extend(["sas.sascalc.calculator", "sas.sascalc.calculator.core"])
233ext_modules.append(Extension("sas.sascalc.calculator.core.sld2i",
234                             sources=[
[3010f68]235                                 os.path.join(gen_dir, "sld2i_module.c"),
236                                 os.path.join(gen_dir, "sld2i.c"),
[f36e01f]237                                 os.path.join(gen_dir, "libfunc.c"),
238                                 os.path.join(gen_dir, "librefl.c"),
239                             ],
240                             include_dirs=[gen_dir],
241                             )
242                   )
[9e531f2]243
[b699768]244# sas.sascalc.pr
[f36e01f]245srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions")
[b699768]246package_dir["sas.sascalc.pr.core"] = srcdir
[f36e01f]247package_dir["sas.sascalc.pr"] = os.path.join("src", "sas", "sascalc", "pr")
248packages.extend(["sas.sascalc.pr", "sas.sascalc.pr.core"])
249ext_modules.append(Extension("sas.sascalc.pr.core.pr_inversion",
250                             sources=[os.path.join(srcdir, "Cinvertor.c"),
251                                      os.path.join(srcdir, "invertor.c"),
252                                      ],
253                             include_dirs=[],
254                             ))
[18e7309]255
256
257# sas.sascalc.file_converter
258mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext")
259package_dir["sas.sascalc.file_converter.core"] = mydir
[f36e01f]260package_dir["sas.sascalc.file_converter"] = os.path.join(
261    "src", "sas", "sascalc", "file_converter")
262packages.extend(["sas.sascalc.file_converter",
263                 "sas.sascalc.file_converter.core"])
[985ad94]264
[f36e01f]265ext_modules.append(Extension("sas.sascalc.file_converter.core.bsl_loader",
266                             sources=[os.path.join(mydir, "bsl_loader.c")],
267                             include_dirs=[np.get_include()],
268                             ))
[3010f68]269
[f36e01f]270# sas.sascalc.corfunc
271package_dir["sas.sascalc.corfunc"] = os.path.join(
272    "src", "sas", "sascalc", "corfunc")
[3010f68]273
[1e13b53]274packages.extend(["sas.sascalc.corfunc"])
275
[b699768]276# sas.sascalc.fit
277package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit")
278packages.append("sas.sascalc.fit")
[3d24489]279
280# Perspectives
[417c03f]281# package_dir["sas.sasgui.perspectives"] = os.path.join(
282#     "src", "sas", "sasgui", "perspectives")
283# package_dir["sas.sasgui.perspectives.pr"] = os.path.join(
284#     "src", "sas", "sasgui", "perspectives", "pr")
285# packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.pr"])
286# package_data["sas.sasgui.perspectives.pr"] = ['media/*']
287
288# package_dir["sas.sasgui.perspectives.invariant"] = os.path.join(
289#     "src", "sas", "sasgui", "perspectives", "invariant")
290# packages.extend(["sas.sasgui.perspectives.invariant"])
291# package_data['sas.sasgui.perspectives.invariant'] = [
292#     os.path.join("media", '*')]
293
294# package_dir["sas.sasgui.perspectives.fitting"] = os.path.join(
295#     "src", "sas", "sasgui", "perspectives", "fitting")
296# package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join(
297#     "src", "sas", "sasgui", "perspectives", "fitting", "plugin_models")
298# packages.extend(["sas.sasgui.perspectives.fitting",
299#                  "sas.sasgui.perspectives.fitting.plugin_models"])
300# package_data['sas.sasgui.perspectives.fitting'] = [
301#     'media/*', 'plugin_models/*']
302
303# packages.extend(["sas.sasgui.perspectives",
304#                  "sas.sasgui.perspectives.calculator"])
305# package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*']
306
307# package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join(
308#     "src", "sas", "sasgui", "perspectives", "corfunc")
309# packages.extend(["sas.sasgui.perspectives.corfunc"])
310# package_data['sas.sasgui.perspectives.corfunc'] = ['media/*']
311
312# package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join(
313#     "src", "sas", "sasgui", "perspectives", "file_converter")
314# packages.extend(["sas.sasgui.perspectives.file_converter"])
315# package_data['sas.sasgui.perspectives.file_converter'] = ['media/*']
[1e13b53]316
[d6bc28cf]317# Data util
[f36e01f]318package_dir["sas.sascalc.data_util"] = os.path.join(
319    "src", "sas", "sascalc", "data_util")
[b699768]320packages.append("sas.sascalc.data_util")
[d6bc28cf]321
[417c03f]322# # Plottools
323# package_dir["sas.sasgui.plottools"] = os.path.join(
324#     "src", "sas", "sasgui", "plottools")
325# packages.append("sas.sasgui.plottools")
[d6bc28cf]326
[985ad94]327# QTGUI
328## UI
329package_dir["sas.qtgui.UI"] = os.path.join(
330    "src", "sas", "qtgui", "UI")
331packages.append("sas.qtgui.UI")
332
[377ade1]333## UnitTesting
334package_dir["sas.qtgui.UnitTesting"] = os.path.join(
335    "src", "sas", "qtgui", "UnitTesting")
336packages.append("sas.qtgui.UnitTesting")
337
[985ad94]338## Utilities
339package_dir["sas.qtgui.Utilities"] = os.path.join(
340    "src", "sas", "qtgui", "Utilities")
341packages.append("sas.qtgui.Utilities")
[3b3b40b]342package_dir["sas.qtgui.UtilitiesUI"] = os.path.join(
343    "src", "sas", "qtgui", "Utilities","UI")
344packages.append("sas.qtgui.Utilities.UI")
[985ad94]345
346package_dir["sas.qtgui.Calculators"] = os.path.join(
347    "src", "sas", "qtgui", "Calculators")
348package_dir["sas.qtgui.Calculators.UI"] = os.path.join(
349    "src", "sas", "qtgui", "Calculators", "UI")
350packages.extend(["sas.qtgui.Calculators", "sas.qtgui.Calculators.UI"])
351
352package_dir["sas.qtgui.MainWindow"] = os.path.join(
353    "src", "sas", "qtgui", "MainWindow")
354package_dir["sas.qtgui.MainWindow.UI"] = os.path.join(
355    "src", "sas", "qtgui", "MainWindow", "UI")
356packages.extend(["sas.qtgui.MainWindow", "sas.qtgui.MainWindow.UI"])
357
358## Perspectives
359package_dir["sas.qtgui.Perspectives"] = os.path.join(
360    "src", "sas", "qtgui", "Perspectives")
361packages.append("sas.qtgui.Perspectives")
362
363package_dir["sas.qtgui.Perspectives.Invariant"] = os.path.join(
364    "src", "sas", "qtgui", "Perspectives", "Invariant")
365package_dir["sas.qtgui.Perspectives.Invariant.UI"] = os.path.join(
366    "src", "sas", "qtgui", "Perspectives", "Invariant", "UI")
367packages.extend(["sas.qtgui.Perspectives.Invariant", "sas.qtgui.Perspectives.Invariant.UI"])
368
369package_dir["sas.qtgui.Perspectives.Fitting"] = os.path.join(
370    "src", "sas", "qtgui", "Perspectives", "Fitting")
371package_dir["sas.qtgui.Perspectives.Fitting.UI"] = os.path.join(
372    "src", "sas", "qtgui", "Perspectives", "Fitting", "UI")
373packages.extend(["sas.qtgui.Perspectives.Fitting", "sas.qtgui.Perspectives.Fitting.UI"])
374
[fa81e94]375package_dir["sas.qtgui.Perspectives.Inversion"] = os.path.join(
376    "src", "sas", "qtgui", "Perspectives", "Inversion")
377package_dir["sas.qtgui.Perspectives.Inversion.UI"] = os.path.join(
378    "src", "sas", "qtgui", "Perspectives", "Inversion", "UI")
379packages.extend(["sas.qtgui.Perspectives.Inversion", "sas.qtgui.Perspectives.Inversion.UI"])
380
[0261bc1]381package_dir["sas.qtgui.Perspectives.Corfunc"] = os.path.join(
382    "src", "sas", "qtgui", "Perspectives", "Corfunc")
383package_dir["sas.qtgui.Perspectives.Corfunc.UI"] = os.path.join(
384    "src", "sas", "qtgui", "Perspectives", "Corfunc", "UI")
385packages.extend(["sas.qtgui.Perspectives.Corfunc", "sas.qtgui.Perspectives.Corfunc.UI"])
386
[985ad94]387## Plotting
388package_dir["sas.qtgui.Plotting"] = os.path.join(
389    "src", "sas", "qtgui", "Plotting")
390package_dir["sas.qtgui.Plotting.UI"] = os.path.join(
391    "src", "sas", "qtgui", "Plotting", "UI")
392package_dir["sas.qtgui.Plotting.Slicers"] = os.path.join(
393    "src", "sas", "qtgui", "Plotting", "Slicers")
[e20870bc]394package_dir["sas.qtgui.Plotting.Masks"] = os.path.join(
395    "src", "sas", "qtgui", "Plotting", "Masks")
396packages.extend(["sas.qtgui.Plotting", "sas.qtgui.Plotting.UI",
397                 "sas.qtgui.Plotting.Slicers", "sas.qtgui.Plotting.Masks"])
[985ad94]398
[9274711]399# # Last of the sas.models
400# package_dir["sas.models"] = os.path.join("src", "sas", "models")
401# packages.append("sas.models")
[2d1b700]402
[d6bc28cf]403EXTENSIONS = [".c", ".cpp"]
404
[f36e01f]405
[d6bc28cf]406def append_file(file_list, dir_path):
407    """
408    Add sources file to sources
409    """
410    for f in os.listdir(dir_path):
411        if os.path.isfile(os.path.join(dir_path, f)):
412            _, ext = os.path.splitext(f)
[4c29e4d]413            if ext.lower() in EXTENSIONS:
[9e531f2]414                file_list.append(os.path.join(dir_path, f))
[d6bc28cf]415        elif os.path.isdir(os.path.join(dir_path, f)) and \
416                not f.startswith("."):
417            sub_dir = os.path.join(dir_path, f)
418            for new_f in os.listdir(sub_dir):
419                if os.path.isfile(os.path.join(sub_dir, new_f)):
420                    _, ext = os.path.splitext(new_f)
[4c29e4d]421                    if ext.lower() in EXTENSIONS:
[9e531f2]422                        file_list.append(os.path.join(sub_dir, new_f))
[820df88]423
[f36e01f]424
[820df88]425# Comment out the following to avoid rebuilding all the models
[9e531f2]426file_sources = []
427append_file(file_sources, gen_dir)
[820df88]428
[f36e01f]429# Wojtek's hacky way to add doc files while bundling egg
430# def add_doc_files(directory):
[5881b17]431#    paths = []
432#    for (path, directories, filenames) in os.walk(directory):
433#        for filename in filenames:
434#            paths.append(os.path.join(path, filename))
435#    return paths
436
437#doc_files = add_doc_files('doc')
438
[c329f4d]439# SasView
[ed03b99]440package_data['sas'] = ['logging.ini']
[5881b17]441package_data['sas.sasview'] = ['images/*',
[bbb8a56]442                               'media/*',
[d4c88e24]443                               'test/*.txt',
[bbb8a56]444                               'test/1d_data/*',
445                               'test/2d_data/*',
[27109e5]446                               'test/convertible_files/*',
447                               'test/coordinate_data/*',
448                               'test/image_data/*',
449                               'test/media/*',
450                               'test/other_files/*',
[bbb8a56]451                               'test/save_states/*',
[7152c82]452                               'test/sesans_data/*',
453                               'test/upcoming_formats/*',
[27109e5]454                               ]
[3a39c2e]455packages.append("sas.sasview")
[d6bc28cf]456
[9f32c57]457required = [
[3010f68]458    'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing>=2.0.0',
[db74ee8]459    'lxml', 'h5py',
[9f32c57]460
[f36e01f]461    # The following dependecies won't install automatically, so assume them
462    # The numbers should be bumped up for matplotlib and wxPython as well.
[9f32c57]463    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
464    # 'wxPython>=2.8.11', 'pil',
[f36e01f]465]
[213b445]466
[f36e01f]467if os.name == 'nt':
[7a211030]468    required.extend(['html5lib', 'reportlab'])
[7f59928e]469else:
[775d06f]470    # 'pil' is now called 'pillow'
[5f6336f]471    required.extend(['pillow'])
[5881b17]472
[18e7309]473# Set up SasView
[d6bc28cf]474setup(
[c329f4d]475    name="sasview",
[f36e01f]476    version=VERSION,
477    description="SasView application",
478    author="SasView Team",
479    author_email="developers@sasview.org",
480    url="http://sasview.org",
481    license="PSF",
482    keywords="small-angle x-ray and neutron scattering analysis",
483    download_url="https://github.com/SasView/sasview.git",
484    package_dir=package_dir,
485    packages=packages,
486    package_data=package_data,
487    ext_modules=ext_modules,
488    install_requires=required,
489    zip_safe=False,
490    entry_points={
491        'console_scripts': [
[985ad94]492            "sasview = sas.run",
[f36e01f]493        ]
494    },
495    cmdclass={'build_ext': build_ext_subclass,
496              'docs': BuildSphinxCommand,
497              'disable_openmp': DisableOpenMPCommand}
498)
Note: See TracBrowser for help on using the repository browser.