source: sasview/setup.py @ d6bc9901

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d6bc9901 was 7152c82, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

include upcoming_formats directory in the sample data

  • Property mode set to 100755
File size: 15.3 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
[2cef9d3]14from distutils.command.build_ext import build_ext
[968aa6e]15from distutils.core import Command
[d6bc28cf]16
[9a5097c]17import numpy as np
[f36e01f]18from setuptools import Extension, setup
[d6bc28cf]19
[5548954]20# Manage version number ######################################
[efe730d]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")
[5548954]28##############################################################
29
[d6bc28cf]30package_dir = {}
31package_data = {}
32packages = []
33ext_modules = []
34
[8ab3302]35# Remove all files that should be updated by this setup
[3a39c2e]36# We do this here because application updates these files from .sasview
[8ab3302]37# except when there is no such file
38# Todo : make this list generic
[f36e01f]39# plugin_model_list = ['polynominal5.py', 'sph_bessel_jn.py',
[a62945e]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']
[c8843be]45
46CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
47SASVIEW_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build")
48
[914ba0a]49# TODO: build step should not be messing with existing installation!!
[f36e01f]50sas_dir = os.path.join(os.path.expanduser("~"), '.sasview')
[3a39c2e]51if os.path.isdir(sas_dir):
52    f_path = os.path.join(sas_dir, "sasview.log")
[e615a0d]53    if os.path.isfile(f_path):
54        os.remove(f_path)
[50008e3]55    f_path = os.path.join(sas_dir, "categories.json")
[ea5fa58]56    if os.path.isfile(f_path):
57        os.remove(f_path)
[3a39c2e]58    f_path = os.path.join(sas_dir, 'config', "custom_config.py")
[e615a0d]59    if os.path.isfile(f_path):
60        os.remove(f_path)
[5881b17]61    #f_path = os.path.join(sas_dir, 'plugin_models')
[f36e01f]62    # if os.path.isdir(f_path):
[a62945e]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)
[899e084]67
68if os.path.exists(SASVIEW_BUILD):
[d66dbcc]69    print("Removing existing build directory", SASVIEW_BUILD, "for a clean build")
[899e084]70    shutil.rmtree(SASVIEW_BUILD)
[18e7309]71
[e615a0d]72# 'sys.maxsize' and 64bit: Not supported for python2.5
[899e084]73is_64bits = sys.maxsize > 2**32
[e79a467]74
[7a04dbb]75enable_openmp = False
[f36e01f]76if sys.platform == 'darwin':
[f468791]77    if not is_64bits:
78        # Disable OpenMP
79        enable_openmp = False
80    else:
81        # Newer versions of Darwin don't support openmp
82        try:
83            darwin_ver = int(os.uname()[2].split('.')[0])
84            if darwin_ver >= 12:
85                enable_openmp = False
86        except:
[f3bf622]87            print("PROBLEM determining Darwin version")
[b30ed8f]88
89# Options to enable OpenMP
[f36e01f]90copt = {'msvc': ['/openmp'],
91        'mingw32': ['-fopenmp'],
92        'unix': ['-fopenmp']}
93lopt = {'msvc': ['/MANIFEST'],
94        'mingw32': ['-fopenmp'],
95        'unix': ['-lgomp']}
[13f00a0]96
[ebdb833]97# Platform-specific link options
[f36e01f]98platform_lopt = {'msvc': ['/MANIFEST']}
[307fa4f]99platform_copt = {}
[b9c8fc5]100
101# Set copts to get compile working on OS X >= 10.9 using clang
[f36e01f]102if sys.platform == 'darwin':
[b9c8fc5]103    try:
104        darwin_ver = int(os.uname()[2].split('.')[0])
[4adf48e]105        if darwin_ver >= 13 and darwin_ver < 14:
[f36e01f]106            platform_copt = {
107                'unix': ['-Wno-error=unused-command-line-argument-hard-error-in-future']}
[b9c8fc5]108    except:
[f3bf622]109        print("PROBLEM determining Darwin version")
[b9c8fc5]110
111
[5972029]112class DisableOpenMPCommand(Command):
113    description = "The version of MinGW that comes with Anaconda does not come with OpenMP :( "\
114                  "This commands means we can turn off compiling with OpenMP for this or any "\
115                  "other reason."
116    user_options = []
117
118    def initialize_options(self):
119        self.cwd = None
120
121    def finalize_options(self):
122        self.cwd = os.getcwd()
123        global enable_openmp
124        enable_openmp = False
[1829835]125
[5972029]126    def run(self):
127        pass
[ebdb833]128
[f36e01f]129
130class build_ext_subclass(build_ext):
[13f00a0]131    def build_extensions(self):
132        # Get 64-bitness
133        c = self.compiler.compiler_type
[f3bf622]134        print("Compiling with %s (64bit=%s)" % (c, str(is_64bits)))
[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")
233package_dir["sas.sascalc.calculator.core"] = gen_dir
[f36e01f]234package_dir["sas.sascalc.calculator"] = os.path.join(
235    "src", "sas", "sascalc", "calculator")
236packages.extend(["sas.sascalc.calculator", "sas.sascalc.calculator.core"])
237ext_modules.append(Extension("sas.sascalc.calculator.core.sld2i",
238                             sources=[
239                                 os.path.join(gen_dir, "sld2i_module.cpp"),
240                                 os.path.join(gen_dir, "sld2i.cpp"),
241                                 os.path.join(gen_dir, "libfunc.c"),
242                                 os.path.join(gen_dir, "librefl.c"),
243                             ],
244                             include_dirs=[gen_dir],
245                             )
246                   )
[9e531f2]247
[b699768]248# sas.sascalc.pr
[f36e01f]249srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions")
[b699768]250package_dir["sas.sascalc.pr.core"] = srcdir
[f36e01f]251package_dir["sas.sascalc.pr"] = os.path.join("src", "sas", "sascalc", "pr")
252packages.extend(["sas.sascalc.pr", "sas.sascalc.pr.core"])
253ext_modules.append(Extension("sas.sascalc.pr.core.pr_inversion",
254                             sources=[os.path.join(srcdir, "Cinvertor.c"),
255                                      os.path.join(srcdir, "invertor.c"),
256                                      ],
257                             include_dirs=[],
258                             ))
[18e7309]259
260
261# sas.sascalc.file_converter
262mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext")
263package_dir["sas.sascalc.file_converter.core"] = mydir
[f36e01f]264package_dir["sas.sascalc.file_converter"] = os.path.join(
265    "src", "sas", "sascalc", "file_converter")
266packages.extend(["sas.sascalc.file_converter",
267                 "sas.sascalc.file_converter.core"])
268ext_modules.append(Extension("sas.sascalc.file_converter.core.bsl_loader",
269                             sources=[os.path.join(mydir, "bsl_loader.c")],
270                             include_dirs=[np.get_include()],
271                             ))
272
273# sas.sascalc.corfunc
274package_dir["sas.sascalc.corfunc"] = os.path.join(
275    "src", "sas", "sascalc", "corfunc")
[b854587]276
[1e13b53]277packages.extend(["sas.sascalc.corfunc"])
278
[b699768]279# sas.sascalc.fit
280package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit")
281packages.append("sas.sascalc.fit")
[3d24489]282
283# Perspectives
[f36e01f]284package_dir["sas.sasgui.perspectives"] = os.path.join(
285    "src", "sas", "sasgui", "perspectives")
286package_dir["sas.sasgui.perspectives.pr"] = os.path.join(
287    "src", "sas", "sasgui", "perspectives", "pr")
288packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.pr"])
[1e13b53]289package_data["sas.sasgui.perspectives.pr"] = ['media/*']
[d85c194]290
[f36e01f]291package_dir["sas.sasgui.perspectives.invariant"] = os.path.join(
292    "src", "sas", "sasgui", "perspectives", "invariant")
[d85c194]293packages.extend(["sas.sasgui.perspectives.invariant"])
[f36e01f]294package_data['sas.sasgui.perspectives.invariant'] = [
295    os.path.join("media", '*')]
296
297package_dir["sas.sasgui.perspectives.fitting"] = os.path.join(
298    "src", "sas", "sasgui", "perspectives", "fitting")
299package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join(
300    "src", "sas", "sasgui", "perspectives", "fitting", "plugin_models")
301packages.extend(["sas.sasgui.perspectives.fitting",
302                 "sas.sasgui.perspectives.fitting.plugin_models"])
303package_data['sas.sasgui.perspectives.fitting'] = [
304    'media/*', 'plugin_models/*']
305
306packages.extend(["sas.sasgui.perspectives",
307                 "sas.sasgui.perspectives.calculator"])
[d85c194]308package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*']
309
[f36e01f]310package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join(
311    "src", "sas", "sasgui", "perspectives", "corfunc")
[1e13b53]312packages.extend(["sas.sasgui.perspectives.corfunc"])
313package_data['sas.sasgui.perspectives.corfunc'] = ['media/*']
314
[f36e01f]315package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join(
316    "src", "sas", "sasgui", "perspectives", "file_converter")
[1e13b53]317packages.extend(["sas.sasgui.perspectives.file_converter"])
318package_data['sas.sasgui.perspectives.file_converter'] = ['media/*']
[d85c194]319
[d6bc28cf]320# Data util
[f36e01f]321package_dir["sas.sascalc.data_util"] = os.path.join(
322    "src", "sas", "sascalc", "data_util")
[b699768]323packages.append("sas.sascalc.data_util")
[d6bc28cf]324
325# Plottools
[f36e01f]326package_dir["sas.sasgui.plottools"] = os.path.join(
327    "src", "sas", "sasgui", "plottools")
[d7bb526]328packages.append("sas.sasgui.plottools")
[d6bc28cf]329
[9274711]330# # Last of the sas.models
331# package_dir["sas.models"] = os.path.join("src", "sas", "models")
332# packages.append("sas.models")
[2d1b700]333
[d6bc28cf]334EXTENSIONS = [".c", ".cpp"]
335
[f36e01f]336
[d6bc28cf]337def append_file(file_list, dir_path):
338    """
339    Add sources file to sources
340    """
341    for f in os.listdir(dir_path):
342        if os.path.isfile(os.path.join(dir_path, f)):
343            _, ext = os.path.splitext(f)
[4c29e4d]344            if ext.lower() in EXTENSIONS:
[9e531f2]345                file_list.append(os.path.join(dir_path, f))
[d6bc28cf]346        elif os.path.isdir(os.path.join(dir_path, f)) and \
347                not f.startswith("."):
348            sub_dir = os.path.join(dir_path, f)
349            for new_f in os.listdir(sub_dir):
350                if os.path.isfile(os.path.join(sub_dir, new_f)):
351                    _, ext = os.path.splitext(new_f)
[4c29e4d]352                    if ext.lower() in EXTENSIONS:
[9e531f2]353                        file_list.append(os.path.join(sub_dir, new_f))
[820df88]354
[f36e01f]355
[820df88]356# Comment out the following to avoid rebuilding all the models
[9e531f2]357file_sources = []
358append_file(file_sources, gen_dir)
[820df88]359
[f36e01f]360# Wojtek's hacky way to add doc files while bundling egg
361# def add_doc_files(directory):
[5881b17]362#    paths = []
363#    for (path, directories, filenames) in os.walk(directory):
364#        for filename in filenames:
365#            paths.append(os.path.join(path, filename))
366#    return paths
367
368#doc_files = add_doc_files('doc')
369
[c329f4d]370# SasView
[ed03b99]371package_data['sas'] = ['logging.ini']
[5881b17]372package_data['sas.sasview'] = ['images/*',
[bbb8a56]373                               'media/*',
[d4c88e24]374                               'test/*.txt',
[bbb8a56]375                               'test/1d_data/*',
376                               'test/2d_data/*',
[27109e5]377                               'test/convertible_files/*',
378                               'test/coordinate_data/*',
379                               'test/image_data/*',
380                               'test/media/*',
381                               'test/other_files/*',
[bbb8a56]382                               'test/save_states/*',
[7152c82]383                               'test/sesans_data/*',
384                               'test/upcoming_formats/*',
[27109e5]385                               ]
[3a39c2e]386packages.append("sas.sasview")
[d6bc28cf]387
[9f32c57]388required = [
[243fbc0]389    'bumps>=0.7.5.9', 'periodictable>=1.3.1', 'pyparsing<2.0.0',
[9f32c57]390
391    # 'lxml>=2.2.2',
[db74ee8]392    'lxml', 'h5py',
[9f32c57]393
[f36e01f]394    # The following dependecies won't install automatically, so assume them
395    # The numbers should be bumped up for matplotlib and wxPython as well.
[9f32c57]396    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
397    # 'wxPython>=2.8.11', 'pil',
[f36e01f]398]
[213b445]399
[f36e01f]400if os.name == 'nt':
[7a211030]401    required.extend(['html5lib', 'reportlab'])
[7f59928e]402else:
[775d06f]403    # 'pil' is now called 'pillow'
[5f6336f]404    required.extend(['pillow'])
[5881b17]405
[18e7309]406# Set up SasView
[d6bc28cf]407setup(
[c329f4d]408    name="sasview",
[f36e01f]409    version=VERSION,
410    description="SasView application",
411    author="SasView Team",
412    author_email="developers@sasview.org",
413    url="http://sasview.org",
414    license="PSF",
415    keywords="small-angle x-ray and neutron scattering analysis",
416    download_url="https://github.com/SasView/sasview.git",
417    package_dir=package_dir,
418    packages=packages,
419    package_data=package_data,
420    ext_modules=ext_modules,
421    install_requires=required,
422    zip_safe=False,
423    entry_points={
424        'console_scripts': [
425            "sasview = sas.sasview.sasview:run",
426        ]
427    },
428    cmdclass={'build_ext': build_ext_subclass,
429              'docs': BuildSphinxCommand,
430              'disable_openmp': DisableOpenMPCommand}
431)
Note: See TracBrowser for help on using the repository browser.