[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 | |
---|
| 16 | import os, sys |
---|
[7476d30] | 17 | import platform |
---|
[535d9f6] | 18 | |
---|
[50f4401] | 19 | if 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. |
---|
| 25 | try: |
---|
| 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') |
---|
| 32 | except: |
---|
| 33 | print "Error processing extra python path needed to build SansView\n %s" % sys.exc_value |
---|
| 34 | |
---|
| 35 | from distutils.core import setup |
---|
| 36 | from distutils.filelist import findall |
---|
| 37 | import matplotlib |
---|
| 38 | import py2exe |
---|
[59c6c1e] | 39 | import shutil |
---|
| 40 | # Remove the build folder |
---|
| 41 | shutil.rmtree("build", ignore_errors=True) |
---|
| 42 | # do the same for dist folder |
---|
| 43 | shutil.rmtree("dist", ignore_errors=True) |
---|
[fa597990] | 44 | |
---|
[59c6c1e] | 45 | if sys.version_info < (2, 6): |
---|
[13bc1b3a] | 46 | is_64bits = False |
---|
[59c6c1e] | 47 | origIsSystemDLL = py2exe.build_exe.isSystemDLL |
---|
| 48 | def isSystemDLL(pathname): |
---|
| 49 | if os.path.basename(pathname).lower() in ("msvcp71.dll", "comctl32.dll"): |
---|
| 50 | return 0 |
---|
| 51 | return origIsSystemDLL(pathname) |
---|
| 52 | py2exe.build_exe.isSystemDLL = isSystemDLL |
---|
[13bc1b3a] | 53 | else: |
---|
| 54 | is_64bits = sys.maxsize > 2**32 |
---|
[a490860] | 55 | |
---|
[762984a] | 56 | if is_64bits and sys.version_info >= (2, 6): |
---|
[b08d3cd] | 57 | manifest = """ |
---|
| 58 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
| 59 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
| 60 | manifestVersion="1.0"> |
---|
| 61 | <assemblyIdentity |
---|
| 62 | version="0.64.1.0" |
---|
[a613fe0] | 63 | processorArchitecture="amd64" |
---|
[b08d3cd] | 64 | name="Controls" |
---|
| 65 | type="win32" |
---|
| 66 | /> |
---|
| 67 | <description>SansView</description> |
---|
| 68 | <dependency> |
---|
| 69 | <dependentAssembly> |
---|
| 70 | <assemblyIdentity |
---|
| 71 | type="win32" |
---|
| 72 | name="Microsoft.Windows.Common-Controls" |
---|
| 73 | version="6.0.0.0" |
---|
[a613fe0] | 74 | processorArchitecture="amd64" |
---|
[b08d3cd] | 75 | publicKeyToken="6595b64144ccf1df" |
---|
| 76 | language="*" |
---|
| 77 | /> |
---|
| 78 | </dependentAssembly> |
---|
| 79 | </dependency> |
---|
| 80 | </assembly> |
---|
| 81 | """ |
---|
| 82 | else: |
---|
[59c6c1e] | 83 | manifest_for_python26 = """ |
---|
| 84 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
| 85 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> |
---|
| 86 | <assemblyIdentity |
---|
| 87 | version="5.0.0.0" |
---|
| 88 | processorArchitecture="x86" |
---|
| 89 | name="SansView" |
---|
| 90 | type="win32"> |
---|
| 91 | </assemblyIdentity> |
---|
| 92 | <description>SansView</description> |
---|
| 93 | <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> |
---|
| 94 | <security> |
---|
| 95 | <requestedPrivileges> |
---|
| 96 | <requestedExecutionLevel |
---|
| 97 | level="asInvoker" |
---|
| 98 | uiAccess="false"> |
---|
| 99 | </requestedExecutionLevel> |
---|
| 100 | </requestedPrivileges> |
---|
| 101 | </security> |
---|
| 102 | </trustInfo> |
---|
| 103 | <dependency> |
---|
| 104 | <dependentAssembly> |
---|
| 105 | <assemblyIdentity |
---|
| 106 | type="win32" |
---|
| 107 | name="Microsoft.VC90.CRT" |
---|
| 108 | version="9.0.21022.8" |
---|
| 109 | processorArchitecture="x86" |
---|
| 110 | publicKeyToken="1fc8b3b9a1e18e3b"> |
---|
| 111 | </assemblyIdentity> |
---|
| 112 | </dependentAssembly> |
---|
| 113 | </dependency> |
---|
| 114 | <dependency> |
---|
| 115 | <dependentAssembly> |
---|
| 116 | <assemblyIdentity |
---|
| 117 | type="win32" |
---|
| 118 | name="Microsoft.Windows.Common-Controls" |
---|
| 119 | version="6.0.0.0" |
---|
| 120 | processorArchitecture="x86" |
---|
| 121 | publicKeyToken="6595b64144ccf1df" |
---|
| 122 | language="*"> |
---|
| 123 | </assemblyIdentity> |
---|
| 124 | </dependentAssembly> |
---|
| 125 | </dependency> |
---|
| 126 | </assembly> |
---|
| 127 | """ |
---|
| 128 | manifest_for_python25 = """ |
---|
[b08d3cd] | 129 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
| 130 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
| 131 | manifestVersion="1.0"> |
---|
| 132 | <assemblyIdentity |
---|
| 133 | version="0.64.1.0" |
---|
| 134 | processorArchitecture="x86" |
---|
| 135 | name="Controls" |
---|
| 136 | type="win32" |
---|
| 137 | /> |
---|
| 138 | <description>SansView</description> |
---|
| 139 | <dependency> |
---|
| 140 | <dependentAssembly> |
---|
| 141 | <assemblyIdentity |
---|
| 142 | type="win32" |
---|
| 143 | name="Microsoft.Windows.Common-Controls" |
---|
| 144 | version="6.0.0.0" |
---|
| 145 | processorArchitecture="X86" |
---|
| 146 | publicKeyToken="6595b64144ccf1df" |
---|
| 147 | language="*" |
---|
| 148 | /> |
---|
| 149 | </dependentAssembly> |
---|
| 150 | </dependency> |
---|
| 151 | </assembly> |
---|
| 152 | """ |
---|
[fa597990] | 153 | |
---|
[59c6c1e] | 154 | # Select the appropriate manifest to use. |
---|
| 155 | if sys.version_info >= (3, 0) or sys.version_info < (2, 5): |
---|
| 156 | print "*** This script only works with Python 2.5, 2.6, or 2.7." |
---|
| 157 | sys.exit() |
---|
| 158 | elif sys.version_info >= (2, 6): |
---|
| 159 | manifest = manifest_for_python26 |
---|
| 160 | from glob import glob |
---|
| 161 | py26MSdll = glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*") |
---|
| 162 | elif sys.version_info >= (2, 5): |
---|
| 163 | manifest = manifest_for_python25 |
---|
| 164 | py26MSdll = None |
---|
[fa597990] | 165 | |
---|
| 166 | class Target: |
---|
| 167 | def __init__(self, **kw): |
---|
| 168 | self.__dict__.update(kw) |
---|
| 169 | # for the versioninfo resources |
---|
[2d74016] | 170 | self.version = "2.0.1" |
---|
[fa597990] | 171 | self.company_name = "U Tennessee" |
---|
[50f4401] | 172 | self.copyright = "copyright 2009 - 2011" |
---|
[fa597990] | 173 | self.name = "SansView" |
---|
| 174 | |
---|
| 175 | # |
---|
| 176 | # Adapted from http://www.py2exe.org/index.cgi/MatPlotLib |
---|
| 177 | # to use the MatPlotLib. |
---|
| 178 | # |
---|
[d4c19e5] | 179 | path = os.getcwd() |
---|
| 180 | |
---|
[fa597990] | 181 | media_dir = os.path.join(path, "media") |
---|
| 182 | images_dir = os.path.join(path, "images") |
---|
| 183 | test_dir = os.path.join(path, "test") |
---|
| 184 | |
---|
| 185 | matplotlibdatadir = matplotlib.get_data_path() |
---|
| 186 | matplotlibdata = findall(matplotlibdatadir) |
---|
| 187 | data_files = [] |
---|
| 188 | # Copying SLD data |
---|
| 189 | import periodictable |
---|
| 190 | import logging |
---|
| 191 | data_files += periodictable.data_files() |
---|
| 192 | |
---|
[d4c19e5] | 193 | import sans.perspectives.fitting as fitting |
---|
| 194 | data_files += fitting.data_files() |
---|
| 195 | |
---|
[fa597990] | 196 | import sans.perspectives.calculator as calculator |
---|
| 197 | data_files += calculator.data_files() |
---|
| 198 | |
---|
| 199 | import sans.perspectives.invariant as invariant |
---|
| 200 | data_files += invariant.data_files() |
---|
[d4c19e5] | 201 | |
---|
[fa597990] | 202 | import sans.guiframe as guiframe |
---|
| 203 | data_files += guiframe.data_files() |
---|
| 204 | |
---|
| 205 | import sans.models as models |
---|
| 206 | data_files += models.data_files() |
---|
| 207 | |
---|
| 208 | for f in matplotlibdata: |
---|
| 209 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
| 210 | data_files.append((os.path.split(dirname)[0], [f])) |
---|
| 211 | |
---|
| 212 | # Copy the settings file for the sans.dataloader file extension associations |
---|
| 213 | import sans.dataloader.readers |
---|
| 214 | f = os.path.join(sans.dataloader.readers.get_data_path(),'defaults.xml') |
---|
| 215 | if os.path.isfile(f): |
---|
| 216 | data_files.append(('.', [f])) |
---|
| 217 | f = 'custom_config.py' |
---|
| 218 | if os.path.isfile(f): |
---|
| 219 | data_files.append(('.', [f])) |
---|
[d4c19e5] | 220 | f = 'local_config.py' |
---|
| 221 | if os.path.isfile(f): |
---|
| 222 | data_files.append(('.', [f])) |
---|
[fa597990] | 223 | # Copying the images directory to the distribution directory. |
---|
| 224 | for f in findall(images_dir): |
---|
| 225 | if os.path.split(f)[0].count('.svn')==0: |
---|
[f1044e9] | 226 | data_files.append(("images", [f])) |
---|
[fa597990] | 227 | |
---|
| 228 | # Copying the HTML help docs |
---|
| 229 | for f in findall(media_dir): |
---|
| 230 | if os.path.split(f)[0].count('.svn')==0: |
---|
[f1044e9] | 231 | data_files.append(("media", [f])) |
---|
[fa597990] | 232 | |
---|
| 233 | # Copying the sample data user data |
---|
| 234 | for f in findall(test_dir): |
---|
| 235 | if os.path.split(f)[0].count('.svn')==0: |
---|
[f1044e9] | 236 | data_files.append(("test", [f])) |
---|
[fa597990] | 237 | |
---|
[59c6c1e] | 238 | if py26MSdll != None: |
---|
| 239 | # install the MSVC 9 runtime dll's into the application folder |
---|
| 240 | data_files.append(("Microsoft.VC90.CRT", py26MSdll)) |
---|
[fa597990] | 241 | |
---|
| 242 | # packages |
---|
| 243 | # |
---|
[bb64650] | 244 | packages = ['matplotlib', 'scipy', 'pytz', 'encodings'] |
---|
[535d9f6] | 245 | includes = ['site'] |
---|
[d42a24b] | 246 | |
---|
| 247 | # Exclude packages that are not needed but are often found on build systems |
---|
[59c6c1e] | 248 | excludes = ['Tkinter', 'PyQt4', '_ssl', '_tkagg', 'sip'] |
---|
[fa597990] | 249 | |
---|
[59c6c1e] | 250 | dll_excludes = ['libgdk_pixbuf-2.0-0.dll', |
---|
| 251 | 'libgobject-2.0-0.dll', |
---|
| 252 | 'libgdk-win32-2.0-0.dll', |
---|
| 253 | 'tcl84.dll', |
---|
| 254 | 'tk84.dll', |
---|
| 255 | 'QtGui4.dll', |
---|
| 256 | 'QtCore4.dll', |
---|
[ea32de3] | 257 | 'msvcp90.dll', |
---|
[59c6c1e] | 258 | 'w9xpopen.exe', |
---|
| 259 | 'cygwin1.dll'] |
---|
[fa597990] | 260 | |
---|
| 261 | target_wx_client = Target( |
---|
| 262 | description = 'SansView', |
---|
| 263 | script = 'sansview.py', |
---|
| 264 | icon_resources = [(1, os.path.join(images_dir, "ball.ico"))], |
---|
| 265 | other_resources = [(24,1,manifest)], |
---|
| 266 | dest_base = "SansView" |
---|
| 267 | ) |
---|
| 268 | |
---|
[7476d30] | 269 | bundle_option = 2 |
---|
[762984a] | 270 | if is_64bits: |
---|
[7476d30] | 271 | bundle_option = 3 |
---|
[fa597990] | 272 | |
---|
| 273 | setup( |
---|
| 274 | windows=[target_wx_client], |
---|
| 275 | console=[], |
---|
| 276 | |
---|
| 277 | options={ |
---|
| 278 | 'py2exe': { |
---|
| 279 | 'dll_excludes': dll_excludes, |
---|
| 280 | 'packages' : packages, |
---|
| 281 | 'includes':includes, |
---|
| 282 | 'excludes':excludes, |
---|
| 283 | "compressed": 1, |
---|
| 284 | "optimize": 0, |
---|
[7476d30] | 285 | "bundle_files":bundle_option, |
---|
[fa597990] | 286 | }, |
---|
| 287 | }, |
---|
| 288 | data_files=data_files, |
---|
| 289 | |
---|
| 290 | ) |
---|
| 291 | |
---|
| 292 | |
---|