source: sasview/setup.py @ 12f7f24

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 12f7f24 was ed03b99, checked in by Paul Kienzle <pkienzle@…>, 8 years ago

move logger config into root of sas so it is available immediately

  • Property mode set to 100755
File size: 15.3 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
68if os.path.exists(SASVIEW_BUILD):
69    print("Removing existing build directory", SASVIEW_BUILD, "for a clean build")
70    shutil.rmtree(SASVIEW_BUILD)
71
72# 'sys.maxsize' and 64bit: Not supported for python2.5
73is_64bits = sys.maxsize > 2**32
74
75enable_openmp = False
76if sys.platform == 'darwin':
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:
87            print("PROBLEM determining Darwin version")
88
89# Options to enable OpenMP
90copt = {'msvc': ['/openmp'],
91        'mingw32': ['-fopenmp'],
92        'unix': ['-fopenmp']}
93lopt = {'msvc': ['/MANIFEST'],
94        'mingw32': ['-fopenmp'],
95        'unix': ['-lgomp']}
96
97# Platform-specific link options
98platform_lopt = {'msvc': ['/MANIFEST']}
99platform_copt = {}
100
101# Set copts to get compile working on OS X >= 10.9 using clang
102if sys.platform == 'darwin':
103    try:
104        darwin_ver = int(os.uname()[2].split('.')[0])
105        if darwin_ver >= 13 and darwin_ver < 14:
106            platform_copt = {
107                'unix': ['-Wno-error=unused-command-line-argument-hard-error-in-future']}
108    except:
109        print("PROBLEM determining Darwin version")
110
111
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
125
126    def run(self):
127        pass
128
129
130class build_ext_subclass(build_ext):
131    def build_extensions(self):
132        # Get 64-bitness
133        c = self.compiler.compiler_type
134        print("Compiling with %s (64bit=%s)" % (c, str(is_64bits)))
135
136        # OpenMP build options
137        if enable_openmp:
138            if c in copt:
139                for e in self.extensions:
140                    e.extra_compile_args = copt[c]
141            if c in lopt:
142                for e in self.extensions:
143                    e.extra_link_args = lopt[c]
144
145        # Platform-specific build options
146        if c in platform_lopt:
147            for e in self.extensions:
148                e.extra_link_args = platform_lopt[c]
149
150        if c in platform_copt:
151            for e in self.extensions:
152                e.extra_compile_args = platform_copt[c]
153
154        build_ext.build_extensions(self)
155
156
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
167    def run(self):
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
173        SASMODELS_DOCPATH = os.path.abspath(os.path.join(os.getcwd(), '..', 'sasmodels', 'doc'))
174        print("========= check for sasmodels at", SASMODELS_DOCPATH, "============")
175        if os.path.exists(SASMODELS_DOCPATH):
176            if os.path.isdir(SASMODELS_DOCPATH):
177                # if available, build sasmodels docs
178                print("============= Building sasmodels model documentation ===============")
179                smdocbuild = subprocess.call(["make", "-C", SASMODELS_DOCPATH, "html"])
180        else:
181            # if not available warning message
182            print("== !!WARNING!! sasmodels directory not found. Cannot build model docs. ==")
183
184        #Now build sasview (+sasmodels) docs
185        sys.path.append("docs/sphinx-docs")
186        import build_sphinx
187        build_sphinx.rebuild()
188
189
190# sas module
191package_dir["sas"] = os.path.join("src", "sas")
192packages.append("sas")
193
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
203package_dir["sas.sascalc.invariant"] = os.path.join(
204    "src", "sas", "sascalc", "invariant")
205packages.extend(["sas.sascalc.invariant"])
206
207# sas.sasgui.guiframe
208guiframe_path = os.path.join("src", "sas", "sasgui", "guiframe")
209package_dir["sas.sasgui.guiframe"] = guiframe_path
210package_dir["sas.sasgui.guiframe.local_perspectives"] = os.path.join(
211    os.path.join(guiframe_path, "local_perspectives"))
212package_data["sas.sasgui.guiframe"] = ['images/*', 'media/*']
213packages.extend(
214    ["sas.sasgui.guiframe", "sas.sasgui.guiframe.local_perspectives"])
215# build local plugin
216for d in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
217    if d not in ['.svn', '__init__.py', '__init__.pyc']:
218        package_name = "sas.sasgui.guiframe.local_perspectives." + d
219        packages.append(package_name)
220        package_dir[package_name] = os.path.join(
221            guiframe_path, "local_perspectives", d)
222
223# sas.sascalc.dataloader
224package_dir["sas.sascalc.dataloader"] = os.path.join(
225    "src", "sas", "sascalc", "dataloader")
226package_data["sas.sascalc.dataloader.readers"] = [
227    'defaults.json', 'schema/*.xsd']
228packages.extend(["sas.sascalc.dataloader", "sas.sascalc.dataloader.readers",
229                 "sas.sascalc.dataloader.readers.schema"])
230
231
232# sas.sascalc.calculator
233gen_dir = os.path.join("src", "sas", "sascalc", "calculator", "c_extensions")
234package_dir["sas.sascalc.calculator.core"] = gen_dir
235package_dir["sas.sascalc.calculator"] = os.path.join(
236    "src", "sas", "sascalc", "calculator")
237packages.extend(["sas.sascalc.calculator", "sas.sascalc.calculator.core"])
238ext_modules.append(Extension("sas.sascalc.calculator.core.sld2i",
239                             sources=[
240                                 os.path.join(gen_dir, "sld2i_module.cpp"),
241                                 os.path.join(gen_dir, "sld2i.cpp"),
242                                 os.path.join(gen_dir, "libfunc.c"),
243                                 os.path.join(gen_dir, "librefl.c"),
244                             ],
245                             include_dirs=[gen_dir],
246                             )
247                   )
248
249# sas.sascalc.pr
250srcdir = os.path.join("src", "sas", "sascalc", "pr", "c_extensions")
251package_dir["sas.sascalc.pr.core"] = srcdir
252package_dir["sas.sascalc.pr"] = os.path.join("src", "sas", "sascalc", "pr")
253packages.extend(["sas.sascalc.pr", "sas.sascalc.pr.core"])
254ext_modules.append(Extension("sas.sascalc.pr.core.pr_inversion",
255                             sources=[os.path.join(srcdir, "Cinvertor.c"),
256                                      os.path.join(srcdir, "invertor.c"),
257                                      ],
258                             include_dirs=[],
259                             ))
260
261
262# sas.sascalc.file_converter
263mydir = os.path.join("src", "sas", "sascalc", "file_converter", "c_ext")
264package_dir["sas.sascalc.file_converter.core"] = mydir
265package_dir["sas.sascalc.file_converter"] = os.path.join(
266    "src", "sas", "sascalc", "file_converter")
267packages.extend(["sas.sascalc.file_converter",
268                 "sas.sascalc.file_converter.core"])
269ext_modules.append(Extension("sas.sascalc.file_converter.core.bsl_loader",
270                             sources=[os.path.join(mydir, "bsl_loader.c")],
271                             include_dirs=[np.get_include()],
272                             ))
273
274# sas.sascalc.corfunc
275package_dir["sas.sascalc.corfunc"] = os.path.join(
276    "src", "sas", "sascalc", "corfunc")
277
278packages.extend(["sas.sascalc.corfunc"])
279
280# sas.sascalc.fit
281package_dir["sas.sascalc.fit"] = os.path.join("src", "sas", "sascalc", "fit")
282packages.append("sas.sascalc.fit")
283
284# Perspectives
285package_dir["sas.sasgui.perspectives"] = os.path.join(
286    "src", "sas", "sasgui", "perspectives")
287package_dir["sas.sasgui.perspectives.pr"] = os.path.join(
288    "src", "sas", "sasgui", "perspectives", "pr")
289packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.pr"])
290package_data["sas.sasgui.perspectives.pr"] = ['media/*']
291
292package_dir["sas.sasgui.perspectives.invariant"] = os.path.join(
293    "src", "sas", "sasgui", "perspectives", "invariant")
294packages.extend(["sas.sasgui.perspectives.invariant"])
295package_data['sas.sasgui.perspectives.invariant'] = [
296    os.path.join("media", '*')]
297
298package_dir["sas.sasgui.perspectives.fitting"] = os.path.join(
299    "src", "sas", "sasgui", "perspectives", "fitting")
300package_dir["sas.sasgui.perspectives.fitting.plugin_models"] = os.path.join(
301    "src", "sas", "sasgui", "perspectives", "fitting", "plugin_models")
302packages.extend(["sas.sasgui.perspectives.fitting",
303                 "sas.sasgui.perspectives.fitting.plugin_models"])
304package_data['sas.sasgui.perspectives.fitting'] = [
305    'media/*', 'plugin_models/*']
306
307packages.extend(["sas.sasgui.perspectives",
308                 "sas.sasgui.perspectives.calculator"])
309package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*']
310
311package_dir["sas.sasgui.perspectives.corfunc"] = os.path.join(
312    "src", "sas", "sasgui", "perspectives", "corfunc")
313packages.extend(["sas.sasgui.perspectives.corfunc"])
314package_data['sas.sasgui.perspectives.corfunc'] = ['media/*']
315
316package_dir["sas.sasgui.perspectives.file_converter"] = os.path.join(
317    "src", "sas", "sasgui", "perspectives", "file_converter")
318packages.extend(["sas.sasgui.perspectives.file_converter"])
319package_data['sas.sasgui.perspectives.file_converter'] = ['media/*']
320
321# Data util
322package_dir["sas.sascalc.data_util"] = os.path.join(
323    "src", "sas", "sascalc", "data_util")
324packages.append("sas.sascalc.data_util")
325
326# Plottools
327package_dir["sas.sasgui.plottools"] = os.path.join(
328    "src", "sas", "sasgui", "plottools")
329packages.append("sas.sasgui.plottools")
330
331# # Last of the sas.models
332# package_dir["sas.models"] = os.path.join("src", "sas", "models")
333# packages.append("sas.models")
334
335EXTENSIONS = [".c", ".cpp"]
336
337
338def append_file(file_list, dir_path):
339    """
340    Add sources file to sources
341    """
342    for f in os.listdir(dir_path):
343        if os.path.isfile(os.path.join(dir_path, f)):
344            _, ext = os.path.splitext(f)
345            if ext.lower() in EXTENSIONS:
346                file_list.append(os.path.join(dir_path, f))
347        elif os.path.isdir(os.path.join(dir_path, f)) and \
348                not f.startswith("."):
349            sub_dir = os.path.join(dir_path, f)
350            for new_f in os.listdir(sub_dir):
351                if os.path.isfile(os.path.join(sub_dir, new_f)):
352                    _, ext = os.path.splitext(new_f)
353                    if ext.lower() in EXTENSIONS:
354                        file_list.append(os.path.join(sub_dir, new_f))
355
356
357# Comment out the following to avoid rebuilding all the models
358file_sources = []
359append_file(file_sources, gen_dir)
360
361# Wojtek's hacky way to add doc files while bundling egg
362# def add_doc_files(directory):
363#    paths = []
364#    for (path, directories, filenames) in os.walk(directory):
365#        for filename in filenames:
366#            paths.append(os.path.join(path, filename))
367#    return paths
368
369#doc_files = add_doc_files('doc')
370
371# SasView
372package_data['sas'] = ['logging.ini']
373package_data['sas.sasview'] = ['images/*',
374                               'media/*',
375                               'test/*.txt',
376                               'test/1d_data/*',
377                               'test/2d_data/*',
378                               'test/convertible_files/*',
379                               'test/coordinate_data/*',
380                               'test/image_data/*',
381                               'test/media/*',
382                               'test/other_files/*',
383                               'test/save_states/*',
384                               'test/sesans_data/*'
385                               ]
386packages.append("sas.sasview")
387
388required = [
389    'bumps>=0.7.5.9', 'periodictable>=1.3.1', 'pyparsing<2.0.0',
390
391    # 'lxml>=2.2.2',
392    'lxml', 'h5py',
393
394    # The following dependecies won't install automatically, so assume them
395    # The numbers should be bumped up for matplotlib and wxPython as well.
396    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
397    # 'wxPython>=2.8.11', 'pil',
398]
399
400if os.name == 'nt':
401    required.extend(['html5lib', 'reportlab'])
402else:
403    # 'pil' is now called 'pillow'
404    required.extend(['pillow'])
405
406# Set up SasView
407setup(
408    name="sasview",
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.