source: sasview/sansview/setup_exe.py @ bd26a85

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 bd26a85 was bd26a85, checked in by Jae Cho <jhjcho@…>, 12 years ago

win32com also works now on 2.7

  • Property mode set to 100644
File size: 11.0 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, sys
17import platform
18
19if len(sys.argv) == 1:
20    sys.argv.append('py2exe')
21# When using the SansView build script, we need to be able to pass
22# an extra path to be added to the python path. The extra arguments
23# should be removed from the list so that the setup processing doesn't
24# fail.
25try:
26    if sys.argv.count('--extrapath'):
27        path_flag_idx = sys.argv.index('--extrapath')
28        extra_path = sys.argv[path_flag_idx+1]
29        sys.path.insert(0, extra_path)
30        del sys.argv[path_flag_idx+1]
31        sys.argv.remove('--extrapath')
32except:
33    print "Error processing extra python path needed to build SansView\n  %s" % sys.exc_value
34
35from distutils.core import setup
36from distutils.filelist import findall
37import matplotlib
38
39# Solution taken from here: http://www.py2exe.org/index.cgi/win32com.shell
40# ModuleFinder can't handle runtime changes to __path__, but win32com uses them
41win32_folder = "win32com"
42if sys.version_info >= (2, 7) or sys.version_info < (2, 6):
43    win32_folder = "win32comext"
44try:
45    # py2exe 0.6.4 introduced a replacement modulefinder.
46    # This means we have to add package paths there, not to the built-in
47    # one.  If this new modulefinder gets integrated into Python, then
48    # we might be able to revert this some day.
49    # if this doesn't work, try import modulefinder
50    try:
51        import py2exe.mf as modulefinder
52    except ImportError:
53        import modulefinder
54    import win32com, sys
55    for p in win32com.__path__[1:]:
56        modulefinder.AddPackagePath(win32_folder, p)
57    for extra in ["win32com.shell", "win32com.adsi", "win32com.axcontrol",
58                    "win32com.axscript", "win32com.bits", "win32com.ifilter",
59                    "win32com.internet", "win32com.mapi", "win32com.propsys",
60                    "win32com.taskscheduler"]:
61       
62            __import__(extra)
63            m = sys.modules[extra]
64            for p in m.__path__[1:]:
65                modulefinder.AddPackagePath(extra, p)
66
67except ImportError:
68    # no build path setup, no worries.
69    pass
70
71import py2exe
72import shutil
73# Remove the build folder
74shutil.rmtree("build", ignore_errors=True)
75# do the same for dist folder
76shutil.rmtree("dist", ignore_errors=True)
77
78if sys.version_info < (2, 6):
79    is_64bits = False 
80    origIsSystemDLL = py2exe.build_exe.isSystemDLL
81    def isSystemDLL(pathname):
82            if os.path.basename(pathname).lower() in ("msvcp71.dll", "comctl32.dll"):
83                    return 0
84            return origIsSystemDLL(pathname)
85    py2exe.build_exe.isSystemDLL = isSystemDLL
86else:
87    is_64bits = sys.maxsize > 2**32
88
89if is_64bits and sys.version_info >= (2, 6):
90    manifest = """
91       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
92       <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
93       manifestVersion="1.0">
94       <assemblyIdentity
95           version="0.64.1.0"
96           processorArchitecture="amd64"
97           name="Controls"
98           type="win32"
99       />
100       <description>SansView</description>
101       <dependency>
102           <dependentAssembly>
103               <assemblyIdentity
104                   type="win32"
105                   name="Microsoft.Windows.Common-Controls"
106                   version="6.0.0.0"
107                   processorArchitecture="amd64"
108                   publicKeyToken="6595b64144ccf1df"
109                   language="*"
110               />
111           </dependentAssembly>
112       </dependency>
113       </assembly>
114      """
115else:
116    manifest_for_python26 = """
117        <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
118        <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
119          <assemblyIdentity
120            version="5.0.0.0"
121            processorArchitecture="x86"
122            name="SansView"
123            type="win32">
124          </assemblyIdentity>
125          <description>SansView</description>
126          <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
127            <security>
128              <requestedPrivileges>
129                <requestedExecutionLevel
130                  level="asInvoker"
131                  uiAccess="false">
132                </requestedExecutionLevel>
133              </requestedPrivileges>
134            </security>
135          </trustInfo>
136          <dependency>
137            <dependentAssembly>
138              <assemblyIdentity
139                type="win32"
140                name="Microsoft.VC90.CRT"
141                version="9.0.21022.8"
142                processorArchitecture="x86"
143                publicKeyToken="1fc8b3b9a1e18e3b">
144              </assemblyIdentity>
145            </dependentAssembly>
146          </dependency>
147          <dependency>
148            <dependentAssembly>
149              <assemblyIdentity
150                type="win32"
151                name="Microsoft.Windows.Common-Controls"
152                version="6.0.0.0"
153                processorArchitecture="x86"
154                publicKeyToken="6595b64144ccf1df"
155                language="*">
156              </assemblyIdentity>
157            </dependentAssembly>
158          </dependency>
159        </assembly>
160        """
161    manifest_for_python25 = """
162       <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
163       <assembly xmlns="urn:schemas-microsoft-com:asm.v1"
164       manifestVersion="1.0">
165       <assemblyIdentity
166           version="0.64.1.0"
167           processorArchitecture="x86"
168           name="Controls"
169           type="win32"
170       />
171       <description>SansView</description>
172       <dependency>
173           <dependentAssembly>
174               <assemblyIdentity
175                   type="win32"
176                   name="Microsoft.Windows.Common-Controls"
177                   version="6.0.0.0"
178                   processorArchitecture="X86"
179                   publicKeyToken="6595b64144ccf1df"
180                   language="*"
181               />
182           </dependentAssembly>
183       </dependency>
184       </assembly>
185      """
186
187# Select the appropriate manifest to use.
188py26MSdll_x86 = None
189if sys.version_info >= (3, 0) or sys.version_info < (2, 5):
190    print "*** This script only works with Python 2.5, 2.6, or 2.7."
191    sys.exit()
192elif sys.version_info >= (2, 6):
193    manifest = manifest_for_python26
194    from glob import glob
195    py26MSdll = glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")
196    try:
197        py26MSdll_x86 = glob(r"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*")
198    except:
199        pass
200elif sys.version_info >= (2, 5):
201    manifest = manifest_for_python25
202    py26MSdll = None
203   
204class Target:
205    def __init__(self, **kw):
206        self.__dict__.update(kw)
207        # for the versioninfo resources
208        self.version = "2.1.0"
209        self.company_name = "U Tennessee"
210        self.copyright = "copyright 2009 - 2012"
211        self.name = "SansView"
212       
213#
214# Adapted from http://www.py2exe.org/index.cgi/MatPlotLib
215# to use the MatPlotLib.
216#
217path = os.getcwd()
218
219media_dir = os.path.join(path, "media")
220images_dir = os.path.join(path, "images")
221test_dir = os.path.join(path, "test")
222
223matplotlibdatadir = matplotlib.get_data_path()
224matplotlibdata = findall(matplotlibdatadir)
225data_files = []
226# Copying SLD data
227import periodictable
228import logging
229data_files += periodictable.data_files()
230
231import sans.perspectives.fitting as fitting
232data_files += fitting.data_files()
233
234import sans.perspectives.calculator as calculator
235data_files += calculator.data_files()
236
237import sans.perspectives.invariant as invariant
238data_files += invariant.data_files()
239
240import sans.guiframe as guiframe
241data_files += guiframe.data_files()
242
243import sans.models as models
244data_files += models.data_files()
245
246for f in matplotlibdata:
247    dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:])
248    data_files.append((os.path.split(dirname)[0], [f]))
249
250# Copy the settings file for the sans.dataloader file extension associations
251import sans.dataloader.readers
252f = os.path.join(sans.dataloader.readers.get_data_path(),'defaults.xml')
253if os.path.isfile(f):
254    data_files.append(('.', [f]))
255f = 'custom_config.py'
256if os.path.isfile(f):
257    data_files.append(('.', [f]))
258    data_files.append(('config', [f]))
259f = 'local_config.py'
260if os.path.isfile(f):
261    data_files.append(('.', [f]))
262   
263if os.path.isfile("BUILD_NUMBER"):
264    data_files.append(('.',["BUILD_NUMBER"]))
265
266# Copying the images directory to the distribution directory.
267for f in findall(images_dir):
268    if os.path.split(f)[0].count('.svn')==0:
269        data_files.append(("images", [f]))
270
271# Copying the HTML help docs
272for f in findall(media_dir):
273    if os.path.split(f)[0].count('.svn')==0:
274        data_files.append(("media", [f]))
275
276# Copying the sample data user data
277for f in findall(test_dir):
278    if os.path.split(f)[0].count('.svn')==0:
279        data_files.append(("test", [f]))
280       
281if py26MSdll != None:
282    # install the MSVC 9 runtime dll's into the application folder
283    data_files.append(("Microsoft.VC90.CRT", py26MSdll))
284if py26MSdll_x86 != None:
285    # install the MSVC 9 runtime dll's into the application folder
286    data_files.append(("Microsoft.VC90.CRT", py26MSdll_x86))
287
288
289# packages
290#
291packages = ['matplotlib', 'scipy', 'pytz', 'encodings', 'comtypes', 'win32com']
292includes = ['site']
293
294# Exclude packages that are not needed but are often found on build systems
295excludes = ['Tkinter', 'PyQt4', '_ssl', '_tkagg', 'sip']
296
297dll_excludes = ['libgdk_pixbuf-2.0-0.dll',
298                'libgobject-2.0-0.dll',
299                'libgdk-win32-2.0-0.dll',
300                'tcl84.dll',
301                'tk84.dll',
302                'QtGui4.dll',
303                'QtCore4.dll',
304                'msvcp90.dll',
305                'w9xpopen.exe',
306                'cygwin1.dll']
307
308target_wx_client = Target(
309    description = 'SansView',
310    script = 'sansview.py',
311    icon_resources = [(1, os.path.join(images_dir, "ball.ico"))],
312    other_resources = [(24,1,manifest)],
313    dest_base = "SansView"
314    )
315
316bundle_option = 2
317if is_64bits:
318    bundle_option = 3
319
320setup(
321    windows=[target_wx_client],
322    console=[],
323    options={
324        'py2exe': {
325            'dll_excludes': dll_excludes,
326            'packages' : packages,
327            'includes':includes,
328            'excludes':excludes,
329            "compressed": 1,
330            "optimize": 0,
331            "bundle_files":bundle_option,
332            },
333    },
334    data_files=data_files,
335   
336)
337
338
Note: See TracBrowser for help on using the repository browser.