source: sasview/setup.py @ 7ba6470

magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249
Last change on this file since 7ba6470 was 952ea1f, checked in by Paul Kienzle <pkienzle@…>, 6 years ago

move c extensions from core/module.so to _module.so

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