source: sasview/setup.py @ 6c7e4cc

ESS_GUIESS_GUI_CategroyManagerESS_GUI_PrESS_GUI_corfESS_GUI_py2_OLDSVCC-1costrafo411docsticket-1032-slditicket-776-orientationticket-873ticket-976ticket1007trueunittest-saveload
Last change on this file since 6c7e4cc was 6c7e4cc, checked in by ajj, 8 months ago

Updating setup.py to call sasmodels doc build

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