source: sasview/setup.py @ 1780d8b

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 1780d8b was c8843be, checked in by smk78, 9 years ago

Modified setup.py to force it to remove the sasview build directory
before it starts to build sasview; kinda curious it didn't do that
anyway…

  • 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
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")
251packages.extend(["sas.sasgui.perspectives.fitting"])
252package_data['sas.sasgui.perspectives.fitting'] = ['media/*']
253
254packages.extend(["sas.sasgui.perspectives", "sas.sasgui.perspectives.calculator"])
255package_data['sas.sasgui.perspectives.calculator'] = ['images/*', 'media/*']
256   
257# Data util
258package_dir["sas.sascalc.data_util"] = os.path.join("src", "sas", "sascalc", "data_util")
259packages.append("sas.sascalc.data_util")
260
261# Plottools
262package_dir["sas.sasgui.plottools"] = os.path.join("src", "sas", "sasgui", "plottools")
263packages.append("sas.sasgui.plottools")
264
265# # Last of the sas.models
266# package_dir["sas.models"] = os.path.join("src", "sas", "models")
267# packages.append("sas.models")
268
269IGNORED_FILES = [".svn"]
270if not os.name=='nt':
271    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
272
273EXTENSIONS = [".c", ".cpp"]
274
275def append_file(file_list, dir_path):
276    """
277    Add sources file to sources
278    """
279    for f in os.listdir(dir_path):
280        if os.path.isfile(os.path.join(dir_path, f)):
281            _, ext = os.path.splitext(f)
282            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
283                file_list.append(os.path.join(dir_path, f))
284        elif os.path.isdir(os.path.join(dir_path, f)) and \
285                not f.startswith("."):
286            sub_dir = os.path.join(dir_path, f)
287            for new_f in os.listdir(sub_dir):
288                if os.path.isfile(os.path.join(sub_dir, new_f)):
289                    _, ext = os.path.splitext(new_f)
290                    if ext.lower() in EXTENSIONS and\
291                         new_f not in IGNORED_FILES:
292                        file_list.append(os.path.join(sub_dir, new_f))
293
294# Comment out the following to avoid rebuilding all the models
295file_sources = []
296append_file(file_sources, gen_dir)
297
298# SasView
299package_dir["sas.sasview"] = "sasview"
300package_data['sas.sasview'] = ['images/*', 
301                               'media/*',
302                               'test/*.txt',
303                               'test/1d_data/*',
304                               'test/2d_data/*',
305                               'test/save_states/*',
306                               'test/upcoming_formats/*', 
307                                 'default_categories.json']
308packages.append("sas.sasview")
309
310required = [
311    'bumps>=0.7.5.6', 'periodictable>=1.3.1', 'pyparsing<2.0.0',
312
313    # 'lxml>=2.2.2',
314    'lxml', 
315
316    ## The following dependecies won't install automatically, so assume them
317    ## The numbers should be bumped up for matplotlib and wxPython as well.
318    # 'numpy>=1.4.1', 'scipy>=0.7.2', 'matplotlib>=0.99.1.1',
319    # 'wxPython>=2.8.11', 'pil',
320    ]
321
322if os.name=='nt':
323    required.extend(['html5lib', 'reportlab'])
324else:
325    required.extend(['pil'])
326   
327# Set up SasView   
328setup(
329    name="sasview",
330    version = VERSION,
331    description = "SasView application",
332    author = "SasView Team",
333    author_email = "developers@sasview.org",
334    url = "http://sasview.org",
335    license = "PSF",
336    keywords = "small-angle x-ray and neutron scattering analysis",
337    download_url = "https://github.com/SasView/sasview.git",
338    package_dir = package_dir,
339    packages = packages,
340    package_data = package_data,
341    ext_modules = ext_modules,
342    install_requires = required,
343    zip_safe = False,
344    entry_points = {
345                    'console_scripts':[
346                                       "sasview = sas.sasview.sasview:run",
347                                       ]
348                    },
349    cmdclass = {'build_ext': build_ext_subclass,
350                'docs': BuildSphinxCommand,
351                'disable_openmp': DisableOpenMPCommand}
352    )   
Note: See TracBrowser for help on using the repository browser.