source: sasview/setup.py @ e66f9c1

ticket-1094-headless
Last change on this file since e66f9c1 was 46119c2, checked in by wojciech, 6 years ago

cleaning up setup

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