source: sasview/setup.py @ f0ce6e2

magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f0ce6e2 was aab23e3, checked in by Paul Kienzle <pkienzle@…>, 7 years ago

remove garbage from setup.py

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