source: sasview/setup.py @ 5548954

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 5548954 was 5548954, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

Re #3 Refactoring version handling

  • Property mode set to 100644
File size: 11.0 KB
Line 
1"""
2    Setup for SansView
3    #TODO: Add checks to see that all the dependencies are on the system
4"""
5import sys
6import os
7import platform
8from setuptools import setup, Extension, find_packages
9from distutils.command.build_ext import build_ext
10
11try:
12    from numpy.distutils.misc_util import get_numpy_include_dirs
13    NUMPY_INC = get_numpy_include_dirs()[0]
14except:
15    try:
16        import numpy
17        NUMPY_INC = os.path.join(os.path.split(numpy.__file__)[0],"core","include")
18    except:
19        print "\nNumpy is needed to build SansView. Try easy_install numpy.\n  %s" % str(sys.exc_value)
20        sys.exit(0)
21
22# Manage version number ######################################
23IS_RELEASE = False
24VERSION = "2.0.1"
25##############################################################
26vfile = open("sansview/__init__.py", 'w')
27vfile.write("__version__ = %s\n" % VERSION)
28vfile.write("__is_release__ = %s\n" % str(IS_RELEASE))
29vfile.close()
30
31package_dir = {}
32package_data = {}
33packages = []
34ext_modules = []
35
36# Options to enable OpenMP
37copt =  {'msvc': ['/openmp'],
38         'mingw32' : ['-fopenmp'],
39         'unix' : ['-fopenmp']}
40lopt =  {'msvc': ['/MANIFEST'],
41         'mingw32' : ['-fopenmp'],
42         'unix' : ['-lgomp']}
43
44class build_ext_subclass( build_ext ):
45    def build_extensions(self):
46        # Get 64-bitness
47        if sys.version_info >= (2, 6):
48            is_64bits = sys.maxsize > 2**32
49        else:
50            # 'sys.maxsize' and 64bit: Not supported for python2.5
51            is_64bits = False
52       
53        c = self.compiler.compiler_type
54        print "Compiling with %s (64bit=%s)" % (c, str(is_64bits))
55       
56        if not (sys.platform=='darwin' and not is_64bits):
57            if copt.has_key(c):
58               for e in self.extensions:
59                   e.extra_compile_args = copt[ c ]
60            if lopt.has_key(c):
61                for e in self.extensions:
62                    e.extra_link_args = lopt[ c ]
63                   
64        build_ext.build_extensions(self)
65
66
67# sans.invariant
68package_dir["sans.invariant"] = "sansinvariant/src/sans/invariant"
69packages.extend(["sans.invariant"])
70
71# sans.guiframe
72guiframe_path = os.path.join("sansguiframe", "src", "sans", "guiframe")
73package_dir["sans.guiframe"] = guiframe_path
74package_dir["sans.guiframe.local_perspectives"] = os.path.join(guiframe_path, "local_perspectives")
75package_data["sans.guiframe"] = ['images/*', 'media/*']
76packages.extend(["sans.guiframe", "sans.guiframe.local_perspectives"])
77# build local plugin
78for dir in os.listdir(os.path.join(guiframe_path, "local_perspectives")):
79    if dir not in ['.svn','__init__.py', '__init__.pyc']:
80        package_name = "sans.guiframe.local_perspectives." + dir
81        packages.append(package_name)
82        package_dir[package_name] = os.path.join(guiframe_path, "local_perspectives", dir)
83
84# sans.dataloader
85package_dir["sans.dataloader"] = os.path.join("sansdataloader", "src", "sans", "dataloader")
86package_data["sans.dataloader.readers"] = ['defaults.xml']
87packages.extend(["sans.dataloader","sans.dataloader.readers"])
88
89# sans.calculator
90package_dir["sans.calculator"] = "sanscalculator/src/sans/calculator"
91packages.extend(["sans.calculator"])
92   
93# sans.pr
94numpy_incl_path = os.path.join(NUMPY_INC, "numpy")
95srcdir  = os.path.join("pr_inversion", "src", "sans", "pr", "c_extensions")
96
97
98   
99package_dir["sans.pr.core"] = srcdir
100package_dir["sans.pr"] = os.path.join("pr_inversion", "src","sans", "pr")
101packages.extend(["sans.pr","sans.pr.core"])
102ext_modules.append( Extension("sans.pr.core.pr_inversion",
103                              sources = [ os.path.join(srcdir, "Cinvertor.c"),
104                                         os.path.join(srcdir, "invertor.c"),
105                                         ],
106                              include_dirs=[numpy_incl_path],
107                              ) )
108       
109# sans.fit (park integration)
110package_dir["sans.fit"] = "park_integration/src/sans/fit"
111packages.append("sans.fit")
112
113# inversion view
114package_dir["sans.perspectives"] = "inversionview/src/sans/perspectives"
115package_dir["sans.perspectives.pr"] = "inversionview/src/sans/perspectives/pr"
116packages.extend(["sans.perspectives","sans.perspectives.pr"])
117package_data["sans.perspectives.pr"] = ['images/*']
118
119# Invariant view
120package_dir["sans.perspectives"] = os.path.join("invariantview", "src", "sans", "perspectives")
121package_dir["sans.perspectives.invariant"] = os.path.join("invariantview", "src", "sans", "perspectives", "invariant")
122               
123package_data['sans.perspectives.invariant'] = [os.path.join("media",'*')]
124packages.extend(["sans.perspectives","sans.perspectives.invariant"]) 
125
126# Fitting view
127package_dir["sans.perspectives"] = os.path.join("fittingview", "src", "sans", "perspectives"),
128package_dir["sans.perspectives.fitting"] = os.path.join("fittingview", "src", "sans", "perspectives", "fitting")
129package_data['sans.perspectives.fitting'] = ['media/*','plugin_models/*']
130packages.extend(["sans.perspectives", "sans.perspectives.fitting"])
131
132# Calculator view
133package_dir["sans.perspectives"] = "calculatorview/src/sans/perspectives"
134package_dir["sans.perspectives.calculator"] = os.path.join("calculatorview", "src", "sans", "perspectives", "calculator")
135package_data['sans.perspectives.calculator'] = ['images/*', 'media/*']
136packages.extend(["sans.perspectives", "sans.perspectives.calculator"])
137     
138# Data util
139package_dir["data_util"] = "sansutil"
140packages.extend(["data_util"])
141
142# Plottools
143package_dir["danse"] = os.path.join("plottools", "src", "danse")
144package_dir["danse.common"] = os.path.join("plottools", "src", "danse", "common")
145package_dir["danse.common.plottools"] = os.path.join("plottools", "src", "danse", "common", "plottools")
146packages.extend(["danse", "danse.common", "danse.common.plottools"])
147
148# Park 1.2.1
149package_dir["park"]="park-1.2.1/park"
150packages.extend(["park"])
151package_data["park"] = ['park-1.2.1/*.txt', 'park-1.2.1/park.epydoc']
152ext_modules.append( Extension("park._modeling",
153                              sources = [ os.path.join("park-1.2.1", "park", "lib", "modeling.cc"),
154                                         os.path.join("park-1.2.1", "park", "lib", "resolution.c"),
155                                         ],
156                              ) )
157
158# Sans models
159srcdir  = os.path.join("sansmodels", "src", "sans", "models", "c_extensions")
160igordir = os.path.join("sansmodels", "src","sans", "models", "libigor")
161c_model_dir = os.path.join("sansmodels", "src", "sans", "models", "c_models")
162smear_dir  = os.path.join("sansmodels", "src", "sans", "models", "c_smearer")
163
164IGNORED_FILES = ["a.exe",
165                 "__init__.py"
166                 ".svn",
167                   "lineparser.py",
168                   "run.py",
169                   "CGaussian.cpp",
170                   "CLogNormal.cpp",
171                   "CLorentzian.cpp",
172                   "CSchulz.cpp",
173                   "WrapperGenerator.py",
174                   "wrapping.py"
175                   ]
176
177if not os.name=='nt':
178    IGNORED_FILES.extend(["gamma_win.c","winFuncs.c"])
179
180
181EXTENSIONS = [".c", ".cpp"]
182
183def append_file(file_list, dir_path):
184    """
185    Add sources file to sources
186    """
187    for f in os.listdir(dir_path):
188        if os.path.isfile(os.path.join(dir_path, f)):
189            _, ext = os.path.splitext(f)
190            if ext.lower() in EXTENSIONS and f not in IGNORED_FILES:
191                file_list.append(os.path.join(dir_path, f)) 
192        elif os.path.isdir(os.path.join(dir_path, f)) and \
193                not f.startswith("."):
194            sub_dir = os.path.join(dir_path, f)
195            for new_f in os.listdir(sub_dir):
196                if os.path.isfile(os.path.join(sub_dir, new_f)):
197                    _, ext = os.path.splitext(new_f)
198                    if ext.lower() in EXTENSIONS and\
199                         new_f not in IGNORED_FILES:
200                        file_list.append(os.path.join(sub_dir, new_f)) 
201       
202model_sources = []
203append_file(file_list=model_sources, dir_path=srcdir)
204append_file(file_list=model_sources, dir_path=igordir)
205append_file(file_list=model_sources, dir_path=c_model_dir)
206smear_sources = []
207append_file(file_list=smear_sources, dir_path=smear_dir)
208
209
210package_dir["sans"] = os.path.join("sansmodels", "src", "sans")
211package_dir["sans.models"] = os.path.join("sansmodels", "src", "sans", "models")
212package_dir["sans.models.sans_extension"] = srcdir
213           
214package_data['sans.models'] = [os.path.join('media', "*")]
215packages.extend(["sans","sans.models","sans.models.sans_extension"])
216   
217smearer_sources = [os.path.join(smear_dir, "smearer.cpp"),
218                  os.path.join(smear_dir, "smearer_module.cpp")]
219
220if os.name=='nt':
221    smearer_sources.append(os.path.join(igordir, "winFuncs.c"))
222
223ext_modules.extend( [ Extension("sans.models.sans_extension.c_models",
224                                sources=model_sources,                 
225                                include_dirs=[igordir, srcdir, c_model_dir, numpy_incl_path],
226                                ),       
227                    # Smearer extension
228                    Extension("sans.models.sans_extension.smearer",
229                              sources = smearer_sources,
230                              include_dirs=[igordir, smear_dir, numpy_incl_path],
231                              ),
232                   
233                    Extension("sans.models.sans_extension.smearer2d_helper",
234                              sources = [os.path.join(smear_dir, 
235                                                      "smearer2d_helper_module.cpp"),
236                                         os.path.join(smear_dir, "smearer2d_helper.cpp"),],
237                              include_dirs=[smear_dir,numpy_incl_path],
238                              )
239                    ] )
240       
241# SansView
242package_dir["sans.sansview"] = "sansview"
243package_data['sans.sansview'] = ['images/*', 'media/*', 'test/*']
244packages.append("sans.sansview")
245
246#required = ['lxml>=2.2.2', 'numpy>=1.4.1', 'matplotlib>=0.99.1.1', 'wxPython>=2.8.11',
247#            'pil','periodictable>=1.3.0', 'scipy>=0.7.2']
248required = ['lxml','periodictable>=1.3.0']
249
250if os.name=='nt':
251    #required.extend(['comtypes', 'pisa', 'html5lib', 'reportlab'])
252    required.extend(['pisa', 'html5lib'])
253    if sys.version_info < (2, 7):
254        required.append('comtypes')
255else:
256    required.extend(['pil'])
257   
258 # Set up SansView   
259setup(
260    name="sansview",
261    version = VERSION,
262    description = "SansView application",
263    author = "University of Tennessee",
264    author_email = "sansdanse@gmail.com",
265    url = "http://danse.chem.utk.edu",
266    license = "PSF",
267    keywords = "small-angle neutron scattering analysis",
268    download_url = "https://sourceforge.net/projects/sansviewproject/files/",
269    package_dir = package_dir,
270    packages = packages,
271    package_data = package_data,
272    ext_modules = ext_modules,
273    install_requires = required,
274    zip_safe = False,
275    entry_points = {
276                    'console_scripts':[
277                                       "sansview = sans.sansview.sansview:run",
278                                       ]
279                    },
280    cmdclass = {'build_ext': build_ext_subclass }
281    )   
Note: See TracBrowser for help on using the repository browser.