source: sasview/setup.py

ESS_GUI
Last change on this file was afdb3b3, checked in by Maksim Rakitin <mrakitin@…>, 6 months ago

FIX: add a proper entry point

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