source: sasmodels/setup_py2exe.py @ 1105286

core_shell_microgelscostrafo411magnetic_modelticket-1257-vesicle-productticket_1156ticket_1265_superballticket_822_more_unit_tests
Last change on this file since 1105286 was 87985ca, checked in by Paul Kienzle <pkienzle@…>, 10 years ago

clean up source tree

  • Property mode set to 100755
File size: 11.9 KB
RevLine 
[14de349]1#!/usr/bin/env python
2
3# Copyright (C) 2006-2010, University of Maryland
4#
5# Permission is hereby granted, free of charge, to any person obtaining a copy
6# of this software and associated documentation files (the "Software"), to deal
7# in the Software without restriction, including without limitation the rights
8# to use, copy, modify, merge, publish, distribute, sublicense, and/ or sell
9# copies of the Software, and to permit persons to whom the Software is
10# furnished to do so, subject to the following conditions:
11#
12# The above copyright notice and this permission notice shall be included in
13# all copies or substantial portions of the Software.
14#
15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21# THE SOFTWARE.
22
23# Author: James Krycka
24
25"""
26This script uses py2exe to create dist\bumps.exe and dist\bumps_gui.exe for
27running the Bumps application in either CLI or GUI mode.
28
29These executables start the application and import the rest of the application
30code stored in library.zip.  The python interpreter and other required python
31packages and dlls are also placed in the zip file.  Additional resource files
32that are needed when Bumps is run are copied to the dist directory tree.  On
33completion, the contents of the dist directory tree can be used by the Inno
34Setup Compiler (via a separate script) to build a Windows installer/uninstaller
35for deployment of the Bumps application.  For testing purposes, bumps.exe or
36bumps_gui.exe can be run from the dist directory.
37"""
38
39import os
40import sys
41
[87985ca]42#sys.dont_write_bytecode = True
[14de349]43
44# Force build before continuing
45os.system('"%s" setup.py build' % sys.executable)
46
47# Remove the current directory from the python path
48here = os.path.abspath(os.path.dirname(__file__))
49sys.path = [p for p in sys.path if os.path.abspath(p) != here]
50
51import glob
52
53from distutils.core import setup
54from distutils.util import get_platform
55
56# Augment the setup interface with the py2exe command and make sure the py2exe
57# option is passed to setup.
58import py2exe
59
60if len(sys.argv) == 1:
61    sys.argv.append('py2exe')
62
63# Put the build lib on the start of the path.
64# For packages with binary extensions, need platform.  If it is a pure
65# script library, use an empty platform string.
66platform = '.%s-%s' % (get_platform(), sys.version[:3])
67#platform = ''
68build_lib = os.path.abspath('build/lib' + platform)
69sys.path.insert(0, build_lib)
70
71# print "\n".join(sys.path)
72
73import wx
74import matplotlib
75matplotlib.use('WXAgg')
76import periodictable
77
78# Retrieve the application version string.
79import bumps
80version = bumps.__version__
81from bumps.gui.resources import resources as gui_resources
82
83# A manifest is required to be included in a py2exe image (or accessible as a
84# file in the image directory) when wxPython is included so that the Windows XP
85# theme is used when rendering wx widgets.  The manifest must be matched to the
86# version of Python that is being used.
87#
88# Create a manifest for use with Python 2.5 on Windows XP or Vista.  It is
89# adapted from the Python manifest file (C:\Python25\pythonw.exe.manifest).
90
91manifest_for_python25 = """
92<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
93<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
94<assemblyIdentity
95    version="1.0.0.0"
96    processorArchitecture="x86"
97    name="%(prog)s"
98    type="win32"
99/>
100<description>%(prog)s</description>
101<dependency>
102    <dependentAssembly>
103        <assemblyIdentity
104            type="win32"
105            name="Microsoft.Windows.Common-Controls"
106            version="6.0.0.0"
107            processorArchitecture="X86"
108            publicKeyToken="6595b64144ccf1df"
109            language="*"
110        />
111    </dependentAssembly>
112</dependency>
113</assembly>
114"""
115
116# Create a manifest for use with Python 2.6 or 2.7 on Windows XP or Vista.
117
118manifest_for_python26 = """
119<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
120<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
121  <assemblyIdentity
122    version="5.0.0.0"
123    processorArchitecture="x86"
124    name="%(prog)s"
125    type="win32">
126  </assemblyIdentity>
127  <description>%(prog)s</description>
128  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
129    <security>
130      <requestedPrivileges>
131        <requestedExecutionLevel
132          level="asInvoker"
133          uiAccess="false">
134        </requestedExecutionLevel>
135      </requestedPrivileges>
136    </security>
137  </trustInfo>
138  <dependency>
139    <dependentAssembly>
140      <assemblyIdentity
141        type="win32"
142        name="Microsoft.VC90.CRT"
143        version="9.0.21022.8"
144        processorArchitecture="x86"
145        publicKeyToken="1fc8b3b9a1e18e3b">
146      </assemblyIdentity>
147    </dependentAssembly>
148  </dependency>
149  <dependency>
150    <dependentAssembly>
151      <assemblyIdentity
152        type="win32"
153        name="Microsoft.Windows.Common-Controls"
154        version="6.0.0.0"
155        processorArchitecture="x86"
156        publicKeyToken="6595b64144ccf1df"
157        language="*">
158      </assemblyIdentity>
159    </dependentAssembly>
160  </dependency>
161</assembly>
162"""
163
164# Select the appropriate manifest to use.
165if sys.version_info >= (3, 0) or sys.version_info < (2, 5):
166    print("*** This script only works with Python 2.5, 2.6, or 2.7.")
167    sys.exit()
168elif sys.version_info >= (2, 6):
169    manifest = manifest_for_python26
170elif sys.version_info >= (2, 5):
171    manifest = manifest_for_python25
172
173# Create a list of all files to include along side the executable being built
174# in the dist directory tree.  Each element of the data_files list is a tuple
175# consisting of a path (relative to dist\) and a list of files in that path.
176data_files = []
177
178# Add resource files that need to reside in the same directory as the image.
179data_files.append(('.', [os.path.join('.', 'LICENSE.txt')]))
180data_files.append(('.', [os.path.join('.', 'README.txt')]))
181data_files.append(('.', [os.path.join('.', 'bin', 'bumps_launch.bat')]))
182
183# Add application specific data files from the bumps\bumps-data folder.
184data_files += gui_resources.data_files()
185
186# Add data files from the matplotlib\mpl-data folder and its subfolders.
187# For matploblib prior to version 0.99 see the examples at the end of the file.
188data_files += matplotlib.get_py2exe_datafiles()
189
190# Add data files from the periodictable\xsf folder.
191data_files += periodictable.data_files()
192
193# Add example directories and their files.  An empty directory is ignored.
194# Note that Inno Setup will determine where these files will be placed such as
195# C:\My Documents\... instead of the installation folder.
196for path in glob.glob(os.path.join('examples', '*')):
197    if os.path.isdir(path):
198        for file in glob.glob(os.path.join(path, '*.*')):
199            data_files.append((path, [file]))
200    else:
201        data_files.append(('examples', [path]))
202
203for path in glob.glob(os.path.join('doc', 'examples', '*')):
204    if os.path.isdir(path):
205        for file in glob.glob(os.path.join(path, '*.*')):
206            data_files.append((path, [file]))
207    else:
208        data_files.append(('doc', [path]))
209
210# Add PDF documentation to the dist staging directory.
211pdf = os.path.join('doc', 'Bumps.pdf')
212if os.path.isfile(pdf):
213    data_files.append(('doc', [pdf]))
214else:
215    print("*** %s not found - building frozen image without it ***" % pdf)
216
217# Add the Microsoft Visual C++ 2008 redistributable kit if we are building with
218# Python 2.6 or 2.7.  This kit will be installed on the target system as part
219# of the installation process for the frozen image.  Note that the Python 2.5
220# interpreter requires msvcr71.dll which is included in the Python25 package,
221# however, Python 2.6 and 2.7 require the msvcr90.dll but they do not bundle it
222# with the Python26 or Python27 package.  Thus, for Python 2.6 and later, the
223# appropriate dll must be present on the target system at runtime.
224if sys.version_info >= (2, 6):
225    pypath = os.path.dirname(sys.executable)
226    data_files.append(('.', [os.path.join(pypath, 'vcredist_x86.exe')]))
227
228# Specify required packages to bundle in the executable image.
229packages = ['numpy', 'scipy', 'matplotlib', 'pytz', 'pyparsing',
[87985ca]230            'periodictable', 'bumps', 'sasmodels', 'pyopencl',
[14de349]231            ]
232
233# Specify files to include in the executable image.
234includes = []
235
236# Specify files to exclude from the executable image.
237# - We can safely exclude Tk/Tcl and Qt modules because our app uses wxPython.
238# - We do not use ssl services so they are omitted.
239# - We can safely exclude the TkAgg matplotlib backend because our app uses
240#   "matplotlib.use('WXAgg')" to override the default matplotlib configuration.
241# - On the web it is widely recommended to exclude certain lib*.dll modules
242#   but this does not seem necessary any more (but adding them does not hurt).
243# - Python25 requires mscvr71.dll, however, Win XP includes this file.
244# - Since we do not support Win 9x systems, w9xpopen.dll is not needed.
245# - For some reason cygwin1.dll gets included by default, but it is not needed.
246
247excludes = ['Tkinter', 'PyQt4', '_ssl', '_tkagg', 'numpy.distutils.test']
248
249dll_excludes = ['libgdk_pixbuf-2.0-0.dll',
250                'libgobject-2.0-0.dll',
251                'libgdk-win32-2.0-0.dll',
252                'tcl84.dll',
253                'tk84.dll',
254                'QtGui4.dll',
255                'QtCore4.dll',
256                'msvcr71.dll',
257                'msvcp90.dll',
258                'w9xpopen.exe',
259                'cygwin1.dll']
260
261
262class Target(object):
263
264    """This class stores metadata about the distribution in a dictionary."""
265
266    def __init__(self, **kw):
267        self.__dict__.update(kw)
268        self.version = version
269
270clientCLI = Target(
271    name='Bumps',
272    description='Bumps CLI application',
273    # module to run on application start
274    script=os.path.join('bin', 'bumps_cli.py'),
275    dest_base='bumps',  # file name part of the exe file to create
276    # also need to specify in data_files
277    icon_resources=[
278        (1, os.path.join('bumps', 'gui', 'resources', 'bumps.ico'))],
279    bitmap_resources=[],
280    other_resources=[(24, 1, manifest % dict(prog='Bumps'))])
281
282clientGUI = Target(
283    name='Bumps',
284    description='Bumps GUI application',
285    # module to run on application start
286    script=os.path.join('bin', 'bumps_gui.py'),
287    dest_base='bumps_gui',  # file name part of the exe file to create
288    # also need to specify in data_files
289    icon_resources=[
290        (1, os.path.join('bumps', 'gui', 'resources', 'bumps.ico'))],
291    bitmap_resources=[],
292    other_resources=[(24, 1, manifest % dict(prog='Bumps'))])
293
294# Now we do the work to create a standalone distribution using py2exe.
295#
296# When the application is run in console mode, a console window will be created
297# to receive any logging or error messages and the application will then create
298# a separate GUI application window.
299#
300# When the application is run in windows mode, it will create a GUI application
301# window and no console window will be provided.  Output to stderr will be
302# written to <app-image-name>.log.
303setup(
304    console=[clientCLI],
305    windows=[clientGUI],
306    options={'py2exe': {
307        'packages': packages,
308        'includes': includes,
309        'excludes': excludes,
310        'dll_excludes': dll_excludes,
311        'compressed': 1,   # standard compression
312        'optimize': 0,     # no byte-code optimization
313        'dist_dir': "dist",  # where to put py2exe results
314        'xref': False,     # display cross reference (as html doc)
315        'bundle_files': 1,  # bundle python25.dll in library.zip
316    }
317    },
318    # Since we are building two exe's, do not put the shared library in each
319    # of them.  Instead create a single, separate library.zip file.
320    # zipfile=None,               # bundle library.zip in exe
321    data_files=data_files           # list of files to copy to dist directory
322)
Note: See TracBrowser for help on using the repository browser.