source: sasview/setup.py @ 115eb7e

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 115eb7e was 115eb7e, checked in by ajj, 7 years ago

Added warnings to build_sphix about missing directories.

Initial work to run sasmodels build from sasview setup.py

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