source: sasview/setup.py @ 5f6336f

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 5f6336f was 5f6336f, checked in by mathieu, 3 years ago

Update setup.py

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