source: sasview/setup.py @ 985ad94

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since 985ad94 was 985ad94, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Fixed pyinstaller build

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