source: sasview/setup.py @ f4a1433

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since f4a1433 was f4a1433, checked in by Piotr Rozyczko <rozyczko@…>, 22 months ago

Merge branch 'master' into ESS_GUI

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