source: sasview/setup.py @ efe730d

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 efe730d was efe730d, checked in by Paul Kienzle <pkienzle@…>, 3 years ago

move sasview to src/sas/sasview and refactor bundled apps for easier debugging

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