source: sasview/sansview/setup_exe.py @ 66798ce

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

Fixing windows build

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