source: sasview/sansview/setup_exe.py @ 3d6b00c

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 3d6b00c was 27b7acc, checked in by butler, 11 years ago

converted stored category file from pickle to json and a bit of cleanup

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