source: sasview/sasview/setup_exe.py @ abb02db

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 abb02db was abb02db, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 8 years ago

Added h5py to the library

  • Property mode set to 100644
File size: 11.9 KB
Line 
1#!/usr/bin/env python
2
3#
4# The setup to create a Windows executable.
5# Inno Setup can then be used with the installer.iss file
6# in the top source directory to create an installer.
7#
8# Setuptools clashes with py2exe 0.6.8 (and probably later too).
9# For that reason, most of the code needs to have direct imports
10# that are not going through pkg_resources.
11#
12# Attention should be paid to dynamic imports. Data files can
13# be added to the distribution directory for that purpose.
14# See for example the 'images' directory below.
15
16import os
17import sys
18import warnings
19from glob import glob
20import shutil
21
22from distutils.util import get_platform
23from distutils.core import setup
24from distutils.filelist import findall
25from distutils.sysconfig import get_python_lib
26import py2exe
27
28#from idlelib.PyShell import warning_stream
29
30# put the build directory at the front of the path
31if os.path.abspath(os.path.dirname(__file__)) != os.path.abspath(os.getcwd()):
32    raise RuntimeError("Must run setup_exe from the sasview directory")
33root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
34platform = '%s-%s'%(get_platform(), sys.version[:3])
35build_path = os.path.join(root, 'build', 'lib.'+platform)
36#build_path = os.path.join(root, 'sasview-install', 'Lib', 'site-packages')
37sys.path.insert(0, build_path)
38
39import local_config
40from installer_generator import generate_installer
41
42import matplotlib
43try:
44    import tinycc
45except ImportError:
46    warnings.warn("TinyCC package is not available and will not be included")
47    tinycc = None
48
49if len(sys.argv) == 1:
50    sys.argv.append('py2exe')
51
52# When using the SasView build script, we need to be able to pass
53# an extra path to be added to the python path. The extra arguments
54# should be removed from the list so that the setup processing doesn't
55# fail.
56try:
57    if sys.argv.count('--extrapath'):
58        path_flag_idx = sys.argv.index('--extrapath')
59        extra_path = sys.argv[path_flag_idx+1]
60        sys.path.insert(0, extra_path)
61        del sys.argv[path_flag_idx+1]
62        sys.argv.remove('--extrapath')
63except:
64    print "Error processing extra python path needed to build SasView\n  %s" % \
65                sys.exc_value
66
67
68# Solution taken from here: http://www.py2exe.org/index.cgi/win32com.shell
69# ModuleFinder can't handle runtime changes to __path__, but win32com uses them
70win32_folder = "win32comext"
71try:
72    # py2exe 0.6.4 introduced a replacement modulefinder.
73    # This means we have to add package paths there, not to the built-in
74    # one.  If this new modulefinder gets integrated into Python, then
75    # we might be able to revert this some day.
76    # if this doesn't work, try import modulefinder
77    try:
78        import py2exe.mf as modulefinder
79    except ImportError:
80        import modulefinder
81    import win32com
82    for p in win32com.__path__[1:]:
83        modulefinder.AddPackagePath(win32_folder, p)
84    for extra in ["win32com.shell", "win32com.adsi", "win32com.axcontrol",
85                    "win32com.axscript", "win32com.bits", "win32com.ifilter",
86                    "win32com.internet", "win32com.mapi", "win32com.propsys",
87                    "win32com.taskscheduler"]:
88       
89            __import__(extra)
90            m = sys.modules[extra]
91            for p in m.__path__[1:]:
92                modulefinder.AddPackagePath(extra, p)
93
94except ImportError:
95    # no build path setup, no worries.
96    pass
97
98# Remove the build folder
99shutil.rmtree("build", ignore_errors=True)
100# do the same for dist folder
101shutil.rmtree("dist", ignore_errors=True)
102
103is_64bits = sys.maxsize > 2**32
104arch = "amd64" if is_64bits else "x86"
105manifest = """
106    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
107    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
108      <assemblyIdentity
109        version="5.0.0.0"
110        processorArchitecture="%(arch)s"
111        name="SasView"
112        type="win32">
113      </assemblyIdentity>
114      <description>SasView</description>
115      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
116        <security>
117          <requestedPrivileges>
118            <requestedExecutionLevel
119              level="asInvoker"
120              uiAccess="false">
121            </requestedExecutionLevel>
122          </requestedPrivileges>
123        </security>
124      </trustInfo>
125      <dependency>
126        <dependentAssembly>
127          <assemblyIdentity
128            type="win32"
129            name="Microsoft.VC90.CRT"
130            version="9.0.21022.8"
131            processorArchitecture="%(arch)s"
132            publicKeyToken="1fc8b3b9a1e18e3b">
133          </assemblyIdentity>
134        </dependentAssembly>
135      </dependency>
136      <dependency>
137        <dependentAssembly>
138          <assemblyIdentity
139            type="win32"
140            name="Microsoft.Windows.Common-Controls"
141            version="6.0.0.0"
142            processorArchitecture="%(arch)s"
143            publicKeyToken="6595b64144ccf1df"
144            language="*">
145          </assemblyIdentity>
146        </dependentAssembly>
147      </dependency>
148    </assembly>
149    """%{'arch': arch}
150
151if is_64bits:
152    msvcrtdll = glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")
153else:
154    msvcrtdll = glob(r"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")
155if msvcrtdll:
156    msvcrtdll_data_files = ("Microsoft.VC90.CRT", msvcrtdll)
157else:
158    msvcrtdll_data_files = None
159
160
161class Target:
162    def __init__(self, **kw):
163        self.__dict__.update(kw)
164        # for the versioninfo resources
165        self.version = local_config.__version__
166        self.company_name = "SasView.org"
167        self.copyright = "copyright 2009 - 2013"
168        self.name = "SasView"
169       
170#
171# Adapted from http://www.py2exe.org/index.cgi/MatPlotLib
172# to use the MatPlotLib.
173#
174path = os.getcwd()
175
176media_dir = os.path.join(path, "media")
177images_dir = os.path.join(path, "images")
178test_dir = os.path.join(path, "test")
179test_1d_dir = os.path.join(path, "test\\1d_data")
180test_2d_dir = os.path.join(path, "test\\2d_data")
181test_save_dir = os.path.join(path, "test\\save_states")
182test_upcoming_dir = os.path.join(path, "test\\upcoming_formats")
183
184matplotlibdatadir = matplotlib.get_data_path()
185matplotlibdata = findall(matplotlibdatadir)
186
187site_loc = get_python_lib()
188opencl_include_dir = os.path.join(site_loc, "pyopencl", "cl")
189
190data_files = []
191
192if tinycc:
193    data_files += tinycc.data_files()
194
195# Copying SLD data
196import periodictable
197data_files += periodictable.data_files()
198
199import sas.sasgui.perspectives.fitting as fitting
200data_files += fitting.data_files()
201
202import sas.sasgui.perspectives.calculator as calculator
203data_files += calculator.data_files()
204
205import sas.sasgui.perspectives.invariant as invariant
206data_files += invariant.data_files()
207
208import sas.sasgui.guiframe as guiframe
209data_files += guiframe.data_files()
210
211# precompile sas models into the sasview build path; doesn't matter too much
212# where it is so long as it is a place that will get cleaned up afterwards.
213import sasmodels.core
214dll_path = os.path.join(build_path, 'compiled_models')
215compiled_dlls = sasmodels.core.precompile_dlls(dll_path, dtype='double')
216
217# include the compiled models as data; coordinate the target path for the
218# data with installer_generator.py
219data_files.append(('compiled_models', compiled_dlls))
220
221import sasmodels
222data_files += sasmodels.data_files()
223
224for f in matplotlibdata:
225    dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:])
226    data_files.append((os.path.split(dirname)[0], [f]))
227
228# Copy the settings file for the sas.dataloader file extension associations
229import sas.sascalc.dataloader.readers
230f = os.path.join(sas.sascalc.dataloader.readers.get_data_path(), 'defaults.json')
231if os.path.isfile(f):
232    data_files.append(('.', [f]))
233f = 'custom_config.py'
234if os.path.isfile(f):
235    data_files.append(('.', [f]))
236    data_files.append(('config', [f]))
237f = 'local_config.py'
238if os.path.isfile(f):
239    data_files.append(('.', [f]))
240
241f = 'default_categories.json'
242if os.path.isfile(f):
243    data_files.append(('.', [f]))
244   
245if os.path.isfile("BUILD_NUMBER"):
246    data_files.append(('.', ["BUILD_NUMBER"]))
247
248# Copying the images directory to the distribution directory.
249for f in findall(images_dir):
250    if not ".svn" in f:
251        data_files.append(("images", [f]))
252
253# Copying the HTML help docs
254for f in findall(media_dir):
255    if not ".svn" in f:
256        data_files.append(("media", [f]))
257
258# Copying the sample data user data
259for f in findall(test_1d_dir):
260    if not ".svn" in f:
261        data_files.append(("test\\1d_data", [f]))
262
263# Copying the sample data user data
264for f in findall(test_2d_dir):
265    if not ".svn" in f:
266        data_files.append(("test\\2d_data", [f]))
267
268# Copying the sample data user data
269for f in findall(test_save_dir):
270    if not ".svn" in f:
271        data_files.append(("test\\save_states", [f]))
272
273# Copying the sample data user data
274for f in findall(test_upcoming_dir):
275    if not ".svn" in f:
276        data_files.append(("test\\upcoming_formats", [f]))
277
278# Copying opencl include files
279for f in findall(opencl_include_dir):
280    data_files.append(("includes\\pyopencl",[f]))
281
282# See if the documentation has been built, and if so include it.
283doc_path = os.path.join(build_path, "doc")
284if os.path.exists(doc_path):
285    for dirpath, dirnames, filenames in os.walk(doc_path):
286        for filename in filenames:
287            sub_dir = os.path.join("doc", os.path.relpath(dirpath, doc_path))
288            data_files.append((sub_dir, [os.path.join(dirpath, filename)]))
289else:
290    raise Exception("You must first build the documentation before creating an installer.")
291
292if msvcrtdll_data_files is not None:
293    # install the MSVC 9 runtime dll's into the application folder
294    data_files.append(msvcrtdll_data_files)
295
296# NOTE:
297#  need an empty __init__.py in site-packages/numpy/distutils/tests and site-packages/mpl_toolkits
298
299# packages
300#
301packages = [
302    'matplotlib', 'scipy', 'encodings', 'comtypes', 'h5py',
303    'win32com', 'xhtml2pdf', 'bumps','sasmodels', 'sas',
304    ]
305packages.extend([
306    'reportlab',
307    'reportlab.graphics.charts',
308    'reportlab.graphics.samples',
309    'reportlab.graphics.widgets',
310    'reportlab.graphics.barcode',
311    'reportlab.graphics',
312    'reportlab.lib',
313    'reportlab.pdfbase',
314    'reportlab.pdfgen',
315    'reportlab.platypus',
316    ])
317packages.append('periodictable.core') # not found automatically
318#packages.append('IPython')
319includes = ['site', 'lxml._elementpath', 'lxml.etree']
320
321if tinycc:
322    packages.append('tinycc')
323
324# Exclude packages that are not needed but are often found on build systems
325excludes = ['Tkinter', 'PyQt4', '_tkagg', 'sip', 'pytz', 'sympy']
326
327
328dll_excludes = [
329    # Various matplotlib backends we are not using
330    'libgdk_pixbuf-2.0-0.dll', 'libgobject-2.0-0.dll', 'libgdk-win32-2.0-0.dll',
331    'tcl84.dll', 'tk84.dll', 'QtGui4.dll', 'QtCore4.dll',
332    # numpy 1.8 openmp bindings (still seems to use all the cores without them)
333    'libiomp5md.dll', 'libifcoremd.dll', 'libmmd.dll', 'svml_dispmd.dll','libifportMD.dll',
334    # microsoft C runtime (not allowed to ship with the app; need to ship vcredist
335    'msvcp90.dll',
336    # 32-bit windows console piping
337    'w9xpopen.exe',
338    # accidental links to msys/cygwin binaries; shouldn't be needed
339    'cygwin1.dll',
340    # no need to distribute OpenCL.dll - users should have their own copy
341    'OpenCL.dll'
342    ]
343
344target_wx_client = Target(
345    description = 'SasView',
346    script = 'sasview.py',
347    icon_resources = [(1, os.path.join(images_dir, "ball.ico"))],
348    other_resources = [(24, 1, manifest)],
349    dest_base = "SasView"
350    )
351
352bundle_option = 2
353if is_64bits:
354    bundle_option = 3
355generate_installer()
356#initialize category stuff
357#from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller
358#CategoryInstaller.check_install(s)
359
360setup(
361    windows=[target_wx_client],
362    console=[],
363    options={
364        'py2exe': {
365            'dll_excludes': dll_excludes,
366            'packages': packages,
367            'includes': includes,
368            'excludes': excludes,
369            "compressed": 1,
370            "optimize": 0,
371            "bundle_files": bundle_option,
372            },
373    },
374    data_files=data_files,
375)
Note: See TracBrowser for help on using the repository browser.