source: sasview/setup.py @ bdae317

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.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since bdae317 was db74ee8, checked in by krzywon, 8 years ago

Changed h5py requirement to latest version instead of specifying v2.5

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