source: sasview/setup.py @ 339e22b

ESS_GUIESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 339e22b 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
Line 
1# -*- coding: utf-8 -*-
2#!/usr/bin/env python
3
4"""
5    Setup for SasView
6    TODO: Add checks to see that all the dependencies are on the system
7"""
8from __future__ import print_function
9
10import os
11import subprocess
12import shutil
13import sys
14from distutils.command.build_ext import build_ext
15from distutils.core import Command
16
17import numpy as np
18from setuptools import Extension, setup
19
20try:
21    import tinycc.distutils
22except ImportError:
23    pass
24
25# Manage version number ######################################
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")
33##############################################################
34
35package_dir = {}
36package_data = {}
37packages = []
38ext_modules = []
39
40# Remove all files that should be updated by this setup
41# We do this here because application updates these files from .sasview
42# except when there is no such file
43# Todo : make this list generic
44# plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py',
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']
50
51CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
52SASVIEW_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build")
53
54# TODO: build step should not be messing with existing installation!!
55sas_dir = os.path.join(os.path.expanduser("~"), '.sasview')
56if os.path.isdir(sas_dir):
57    f_path = os.path.join(sas_dir, "sasview.log")
58    if os.path.isfile(f_path):
59        os.remove(f_path)
60    #f_path = os.path.join(sas_dir, "categories.json")
61    #if os.path.isfile(f_path):
62    #    os.remove(f_path)
63    f_path = os.path.join(sas_dir, 'config', "custom_config.py")
64    if os.path.isfile(f_path):
65        os.remove(f_path)
66    #f_path = os.path.join(sas_dir, 'plugin_models')
67    # if os.path.isdir(f_path):
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)
72
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):
79    print("Removing existing build directory", SASVIEW_BUILD, "for a clean build")
80    shutil.rmtree(SASVIEW_BUILD)
81
82# 'sys.maxsize' and 64bit: Not supported for python2.5
83is_64bits = sys.maxsize > 2**32
84
85enable_openmp = False
86if sys.platform == 'darwin':
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:
97            print("PROBLEM determining Darwin version")
98
99# Options to enable OpenMP
100copt = {'msvc': ['/openmp'],
101        'mingw32': ['-fopenmp'],
102        'unix': ['-fopenmp']}
103lopt = {'msvc': ['/MANIFEST'],
104        'mingw32': ['-fopenmp'],
105        'unix': ['-lgomp']}
106
107# Platform-specific link options
108platform_lopt = {'msvc': ['/MANIFEST']}
109platform_copt = {}
110
111# Set copts to get compile working on OS X >= 10.9 using clang
112if sys.platform == 'darwin':
113    try:
114        darwin_ver = int(os.uname()[2].split('.')[0])
115        if darwin_ver >= 13 and darwin_ver < 14:
116            platform_copt = {
117                'unix': ['-Wno-error=unused-command-line-argument-hard-error-in-future']}
118    except:
119        print("PROBLEM determining Darwin version")
120
121
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
135
136    def run(self):
137        pass
138
139
140class build_ext_subclass(build_ext):
141    def build_extensions(self):
142        # Get 64-bitness
143        c = self.compiler.compiler_type
144        print("Compiling with %s (64bit=%s)" % (c, str(is_64bits)))
145
146        # OpenMP build options
147        if enable_openmp:
148            if c in copt:
149                for e in self.extensions:
150                    e.extra_compile_args = copt[c]
151            if c in lopt:
152                for e in self.extensions:
153                    e.extra_link_args = lopt[c]
154
155        # Platform-specific build options
156        if c in platform_lopt:
157            for e in self.extensions:
158                e.extra_link_args = platform_lopt[c]
159
160        if c in platform_copt:
161            for e in self.extensions:
162                e.extra_compile_args = platform_copt[c]
163
164        build_ext.build_extensions(self)
165
166
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
177    def run(self):
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
183        SASMODELS_DOCPATH = os.path.abspath(os.path.join(os.getcwd(), '..', 'sasmodels', 'doc'))
184        print("========= check for sasmodels at", SASMODELS_DOCPATH, "============")
185        if os.path.exists(SASMODELS_DOCPATH):
186            if os.path.isdir(SASMODELS_DOCPATH):
187                # if available, build sasmodels docs
188                print("============= Building sasmodels model documentation ===============")
189                smdocbuild = subprocess.call(["make", "-C", SASMODELS_DOCPATH, "html"])
190        else:
191            # if not available warning message
192            print("== !!WARNING!! sasmodels directory not found. Cannot build model docs. ==")
193
194        #Now build sasview (+sasmodels) docs
195        sys.path.append("docs/sphinx-docs")
196        import build_sphinx
197        build_sphinx.rebuild()
198
199
200# sas module
201package_dir["sas"] = os.path.join("src", "sas")
202packages.append("sas")
203
204# sas module
205# qt module
206package_dir["sas.qtgui"] = os.path.join("src", "sas", "qtgui")
207packages.append("sas.qtgui")
208
209# sas module
210package_dir["sas.sascalc"] = os.path.join("src", "sas", "sascalc")
211packages.append("sas.sascalc")
212
213# sas.sascalc.invariant
214package_dir["sas.sascalc.invariant"] = os.path.join(
215    "src", "sas", "sascalc", "invariant")
216packages.extend(["sas.sascalc.invariant"])
217
218
219# sas.sascalc.dataloader
220package_dir["sas.sascalc.dataloader"] = os.path.join(
221    "src", "sas", "sascalc", "dataloader")
222package_data["sas.sascalc.dataloader.readers"] = ['schema/*.xsd']
223packages.extend(["sas.sascalc.dataloader", "sas.sascalc.dataloader.readers",
224                 "sas.sascalc.dataloader.readers.schema"])
225
226
227# sas.sascalc.calculator
228gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions")
229package_dir["sas.sascalc.calculator.core"] = gen_dir
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=[
235                                 os.path.join(gen_dir, "sld2i_module.c"),
236                                 os.path.join(gen_dir, "sld2i.c"),
237                                 os.path.join(gen_dir, "libfunc.c"),
238                                 os.path.join(gen_dir, "librefl.c"),
239                             ],
240                             include_dirs=[gen_dir],
241                             )
242                   )
243
244# sas.sascalc.pr
245srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions")
246package_dir["sas.sascalc.pr.core"] = srcdir
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                             ))
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
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"])
264
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                             ))
269
270# sas.sascalc.corfunc
271package_dir["sas.sascalc.corfunc"] = os.path.join(
272    "src", "sas", "sascalc", "corfunc")
273
274packages.extend(["sas.sascalc.corfunc"])
275
276# sas.sascalc.fit
277package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit")
278packages.append("sas.sascalc.fit")
279
280# Perspectives
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/*']
316
317# Data util
318package_dir["sas.sascalc.data_util"] = os.path.join(
319    "src", "sas", "sascalc", "data_util")
320packages.append("sas.sascalc.data_util")
321
322# # Plottools
323# package_dir["sas.sasgui.plottools"] = os.path.join(
324#     "src", "sas", "sasgui", "plottools")
325# packages.append("sas.sasgui.plottools")
326
327# QTGUI
328## UI
329package_dir["sas.qtgui.UI"] = os.path.join(
330    "src", "sas", "qtgui", "UI")
331packages.append("sas.qtgui.UI")
332
333## UnitTesting
334package_dir["sas.qtgui.UnitTesting"] = os.path.join(
335    "src", "sas", "qtgui", "UnitTesting")
336packages.append("sas.qtgui.UnitTesting")
337
338## Utilities
339package_dir["sas.qtgui.Utilities"] = os.path.join(
340    "src", "sas", "qtgui", "Utilities")
341packages.append("sas.qtgui.Utilities")
342package_dir["sas.qtgui.UtilitiesUI"] = os.path.join(
343    "src", "sas", "qtgui", "Utilities","UI")
344packages.append("sas.qtgui.Utilities.UI")
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
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
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
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")
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"])
398
399# # Last of the sas.models
400# package_dir["sas.models"] = os.path.join("src", "sas", "models")
401# packages.append("sas.models")
402
403EXTENSIONS = [".c", ".cpp"]
404
405
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)
413            if ext.lower() in EXTENSIONS:
414                file_list.append(os.path.join(dir_path, f))
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)
421                    if ext.lower() in EXTENSIONS:
422                        file_list.append(os.path.join(sub_dir, new_f))
423
424
425# Comment out the following to avoid rebuilding all the models
426file_sources = []
427append_file(file_sources, gen_dir)
428
429# Wojtek's hacky way to add doc files while bundling egg
430# def add_doc_files(directory):
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
439# SasView
440package_data['sas'] = ['logging.ini']
441package_data['sas.sasview'] = ['images/*',
442                               'media/*',
443                               'test/*.txt',
444                               'test/1d_data/*',
445                               'test/2d_data/*',
446                               'test/convertible_files/*',
447                               'test/coordinate_data/*',
448                               'test/image_data/*',
449                               'test/media/*',
450                               'test/other_files/*',
451                               'test/save_states/*',
452                               'test/sesans_data/*',
453                               'test/upcoming_formats/*',
454                               ]
455packages.append("sas.sasview")
456
457required = [
458    'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing>=2.0.0',
459    'lxml', 'h5py',
460
461    # The following dependecies won't install automatically, so assume them
462    # The numbers should be bumped up for matplotlib and wxPython as well.
463    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
464    # 'wxPython>=2.8.11', 'pil',
465]
466
467if os.name == 'nt':
468    required.extend(['html5lib', 'reportlab'])
469else:
470    # 'pil' is now called 'pillow'
471    required.extend(['pillow'])
472
473# Set up SasView
474setup(
475    name="sasview",
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': [
492            "sasview = sas.run",
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.