source: sasview/sansview/setup_exe.py @ 789ffc6

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

fix win32com problem

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