source: sasview/setup.py @ ef63dd9

Last change on this file since ef63dd9 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
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        #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)
150
151        # OpenMP build options
152        if enable_openmp:
153            if c in copt:
154                for e in self.extensions:
155                    e.extra_compile_args = copt[c]
156            if c in lopt:
157                for e in self.extensions:
158                    e.extra_link_args = lopt[c]
159
160        # Platform-specific build options
161        if c in platform_lopt:
162            for e in self.extensions:
163                e.extra_link_args = platform_lopt[c]
164
165        if c in platform_copt:
166            for e in self.extensions:
167                e.extra_compile_args = platform_copt[c]
168
169        build_ext.build_extensions(self)
170
171
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
182    def run(self):
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
188        SASMODELS_DOCPATH = os.path.abspath(os.path.join(os.getcwd(), '..', 'sasmodels', 'doc'))
189        print("========= check for sasmodels at", SASMODELS_DOCPATH, "============")
190        if os.path.exists(SASMODELS_DOCPATH):
191            if os.path.isdir(SASMODELS_DOCPATH):
192                # if available, build sasmodels docs
193                print("============= Building sasmodels model documentation ===============")
194                smdocbuild = subprocess.call(["make", "-C", SASMODELS_DOCPATH, "html"])
195        else:
196            # if not available warning message
197            print("== !!WARNING!! sasmodels directory not found. Cannot build model docs. ==")
198
199        #Now build sasview (+sasmodels) docs
200        sys.path.append("docs/sphinx-docs")
201        import build_sphinx
202        build_sphinx.rebuild()
203
204
205# sas module
206package_dir["sas"] = os.path.join("src", "sas")
207packages.append("sas")
208
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
218package_dir["sas.sascalc.invariant"] = os.path.join(
219    "src", "sas", "sascalc", "invariant")
220packages.extend(["sas.sascalc.invariant"])
221
222# sas.sasgui.guiframe
223guiframe_path = os.path.join("src", "sas", "sasgui", "guiframe")
224package_dir["sas.sasgui.guiframe"] = guiframe_path
225package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join(
226    os.path.join(guiframe_path, "local_perspectives"))
227package_data["sas.sasgui.guiframe"] = ['images/*', 'media/*']
228packages.extend(
229    ["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"])
230# build local plugin
231for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
232    if d not in ['.svn', '__init__.py', '__init__.pyc']:
233        package_name = "sas.sasgui.guiframe.local_perspectives." + d
234        packages.append(package_name)
235        package_dir[package_name] = os.path.join(
236            guiframe_path, "local_perspectives", d)
237
238# sas.sascalc.dataloader
239package_dir["sas.sascalc.dataloader"] = os.path.join(
240    "src", "sas", "sascalc", "dataloader")
241package_data["sas.sascalc.dataloader.readers"] = ['schema/*.xsd']
242packages.extend(["sas.sascalc.dataloader", "sas.sascalc.dataloader.readers",
243                 "sas.sascalc.dataloader.readers.schema"])
244
245
246# sas.sascalc.calculator
247gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions")
248package_dir["sas.sascalc.calculator.core"] = gen_dir
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=[
254                                 os.path.join(gen_dir, "sld2i_module.c"),
255                                 os.path.join(gen_dir, "sld2i.c"),
256                                 os.path.join(gen_dir, "libfunc.c"),
257                                 os.path.join(gen_dir, "librefl.c"),
258                             ],
259                             include_dirs=[gen_dir],
260                             )
261                   )
262
263# sas.sascalc.pr
264srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions")
265package_dir["sas.sascalc.pr.core"] = srcdir
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                             ))
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
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")
291
292packages.extend(["sas.sascalc.corfunc"])
293
294# sas.sascalc.fit
295package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit")
296packages.append("sas.sascalc.fit")
297
298# Perspectives
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"])
304package_data["sas.sasgui.perspectives.pr"] = ['media/*']
305
306package_dir["sas.sasgui.perspectives.invariant"] = os.path.join(
307    "src", "sas", "sasgui", "perspectives", "invariant")
308packages.extend(["sas.sasgui.perspectives.invariant"])
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"])
323package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*']
324
325package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join(
326    "src", "sas", "sasgui", "perspectives", "corfunc")
327packages.extend(["sas.sasgui.perspectives.corfunc"])
328package_data['sas.sasgui.perspectives.corfunc'] = ['media/*']
329
330package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join(
331    "src", "sas", "sasgui", "perspectives", "file_converter")
332packages.extend(["sas.sasgui.perspectives.file_converter"])
333package_data['sas.sasgui.perspectives.file_converter'] = ['media/*']
334
335# Data util
336package_dir["sas.sascalc.data_util"] = os.path.join(
337    "src", "sas", "sascalc", "data_util")
338packages.append("sas.sascalc.data_util")
339
340# Plottools
341package_dir["sas.sasgui.plottools"] = os.path.join(
342    "src", "sas", "sasgui", "plottools")
343packages.append("sas.sasgui.plottools")
344
345# # Last of the sas.models
346# package_dir["sas.models"] = os.path.join("src", "sas", "models")
347# packages.append("sas.models")
348
349EXTENSIONS = [".c", ".cpp"]
350
351
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)
359            if ext.lower() in EXTENSIONS:
360                file_list.append(os.path.join(dir_path, f))
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)
367                    if ext.lower() in EXTENSIONS:
368                        file_list.append(os.path.join(sub_dir, new_f))
369
370
371# Comment out the following to avoid rebuilding all the models
372file_sources = []
373append_file(file_sources, gen_dir)
374
375# Wojtek's hacky way to add doc files while bundling egg
376# def add_doc_files(directory):
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
385# SasView
386package_data['sas'] = ['logging.ini']
387package_data['sas.sasview'] = ['images/*',
388                               'media/*',
389                               'test/*.txt',
390                               'test/1d_data/*',
391                               'test/2d_data/*',
392                               'test/convertible_files/*',
393                               'test/coordinate_data/*',
394                               'test/image_data/*',
395                               'test/media/*',
396                               'test/other_files/*',
397                               'test/save_states/*',
398                               'test/sesans_data/*',
399                               'test/upcoming_formats/*',
400                               ]
401packages.append("sas.sasview")
402
403required = [
404    'bumps>=0.7.5.9', 'periodictable>=1.5.0', 'pyparsing<2.0.0',
405
406    # 'lxml>=2.2.2',
407    'lxml', 'h5py',
408
409    # The following dependecies won't install automatically, so assume them
410    # The numbers should be bumped up for matplotlib and wxPython as well.
411    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
412    # 'wxPython>=2.8.11', 'pil',
413]
414
415if os.name == 'nt':
416    required.extend(['html5lib', 'reportlab'])
417else:
418    # 'pil' is now called 'pillow'
419    required.extend(['pillow'])
420
421# Set up SasView
422setup(
423    name="sasview",
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': [
440            "sasview = sas.sasview.sasview:run_gui",
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.