[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') |
---|
[c329f4d] | 21 | # When using the SasView build script, we need to be able to pass |
---|
[fa597990] | 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: |
---|
[c329f4d] | 33 | print "Error processing extra python path needed to build SasView\n %s" % sys.exc_value |
---|
[fa597990] | 34 | |
---|
| 35 | from distutils.core import setup |
---|
| 36 | from distutils.filelist import findall |
---|
| 37 | import 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] | 41 | win32_folder = "win32comext" |
---|
[cc37badc] | 42 | try: |
---|
| 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] | 65 | except ImportError: |
---|
| 66 | # no build path setup, no worries. |
---|
| 67 | pass |
---|
| 68 | |
---|
[fa597990] | 69 | import py2exe |
---|
[59c6c1e] | 70 | import shutil |
---|
| 71 | # Remove the build folder |
---|
| 72 | shutil.rmtree("build", ignore_errors=True) |
---|
| 73 | # do the same for dist folder |
---|
| 74 | shutil.rmtree("dist", ignore_errors=True) |
---|
[fa597990] | 75 | |
---|
[59c6c1e] | 76 | if 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] | 84 | else: |
---|
| 85 | is_64bits = sys.maxsize > 2**32 |
---|
[a490860] | 86 | |
---|
[762984a] | 87 | if 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 | /> |
---|
[c329f4d] | 98 | <description>SasView</description> |
---|
[b08d3cd] | 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 | """ |
---|
| 113 | else: |
---|
[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" |
---|
[c329f4d] | 120 | name="SasView" |
---|
[59c6c1e] | 121 | type="win32"> |
---|
| 122 | </assemblyIdentity> |
---|
[c329f4d] | 123 | <description>SasView</description> |
---|
[59c6c1e] | 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 | /> |
---|
[c329f4d] | 169 | <description>SasView</description> |
---|
[b08d3cd] | 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] | 186 | py26MSdll_x86 = None |
---|
[59c6c1e] | 187 | if 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() |
---|
| 190 | elif 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] | 198 | elif sys.version_info >= (2, 5): |
---|
| 199 | manifest = manifest_for_python25 |
---|
| 200 | py26MSdll = None |
---|
[fa597990] | 201 | |
---|
| 202 | class 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" |
---|
[c329f4d] | 209 | self.name = "SasView" |
---|
[fa597990] | 210 | |
---|
| 211 | # |
---|
| 212 | # Adapted from http://www.py2exe.org/index.cgi/MatPlotLib |
---|
| 213 | # to use the MatPlotLib. |
---|
| 214 | # |
---|
[d4c19e5] | 215 | path = os.getcwd() |
---|
| 216 | |
---|
[fa597990] | 217 | media_dir = os.path.join(path, "media") |
---|
| 218 | images_dir = os.path.join(path, "images") |
---|
| 219 | test_dir = os.path.join(path, "test") |
---|
| 220 | |
---|
| 221 | matplotlibdatadir = matplotlib.get_data_path() |
---|
| 222 | matplotlibdata = findall(matplotlibdatadir) |
---|
| 223 | data_files = [] |
---|
| 224 | # Copying SLD data |
---|
| 225 | import periodictable |
---|
| 226 | import logging |
---|
| 227 | data_files += periodictable.data_files() |
---|
| 228 | |
---|
[d4c19e5] | 229 | import sans.perspectives.fitting as fitting |
---|
| 230 | data_files += fitting.data_files() |
---|
| 231 | |
---|
[fa597990] | 232 | import sans.perspectives.calculator as calculator |
---|
| 233 | data_files += calculator.data_files() |
---|
| 234 | |
---|
| 235 | import sans.perspectives.invariant as invariant |
---|
| 236 | data_files += invariant.data_files() |
---|
[d4c19e5] | 237 | |
---|
[fa597990] | 238 | import sans.guiframe as guiframe |
---|
| 239 | data_files += guiframe.data_files() |
---|
| 240 | |
---|
| 241 | import sans.models as models |
---|
| 242 | data_files += models.data_files() |
---|
| 243 | |
---|
| 244 | for 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 |
---|
| 249 | import sans.dataloader.readers |
---|
| 250 | f = os.path.join(sans.dataloader.readers.get_data_path(),'defaults.xml') |
---|
| 251 | if os.path.isfile(f): |
---|
| 252 | data_files.append(('.', [f])) |
---|
| 253 | f = 'custom_config.py' |
---|
| 254 | if os.path.isfile(f): |
---|
[8ab3302] | 255 | data_files.append(('.', [f])) |
---|
[f9505c30] | 256 | data_files.append(('config', [f])) |
---|
[d4c19e5] | 257 | f = 'local_config.py' |
---|
| 258 | if os.path.isfile(f): |
---|
| 259 | data_files.append(('.', [f])) |
---|
[3a6c3b9] | 260 | |
---|
| 261 | if os.path.isfile("BUILD_NUMBER"): |
---|
| 262 | data_files.append(('.',["BUILD_NUMBER"])) |
---|
| 263 | |
---|
[fa597990] | 264 | # Copying the images directory to the distribution directory. |
---|
| 265 | for 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 |
---|
| 270 | for 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 |
---|
| 275 | for 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] | 279 | if py26MSdll != None: |
---|
| 280 | # install the MSVC 9 runtime dll's into the application folder |
---|
| 281 | data_files.append(("Microsoft.VC90.CRT", py26MSdll)) |
---|
[7983000f] | 282 | if 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 | # |
---|
[213b445] | 289 | packages = ['matplotlib', 'scipy', 'pytz', 'encodings', 'comtypes', 'win32com', 'ho.pisa'] |
---|
| 290 | packages.extend([ |
---|
| 291 | 'reportlab', |
---|
| 292 | 'reportlab.graphics.charts', |
---|
| 293 | 'reportlab.graphics.samples', |
---|
| 294 | 'reportlab.graphics.widgets', |
---|
| 295 | 'reportlab.graphics.barcode', |
---|
| 296 | 'reportlab.graphics', |
---|
| 297 | 'reportlab.lib', |
---|
| 298 | 'reportlab.pdfbase', |
---|
| 299 | 'reportlab.pdfgen', |
---|
| 300 | 'reportlab.platypus', |
---|
| 301 | ]) |
---|
[535d9f6] | 302 | includes = ['site'] |
---|
[d42a24b] | 303 | |
---|
| 304 | # Exclude packages that are not needed but are often found on build systems |
---|
[59c6c1e] | 305 | excludes = ['Tkinter', 'PyQt4', '_ssl', '_tkagg', 'sip'] |
---|
[fa597990] | 306 | |
---|
[59c6c1e] | 307 | dll_excludes = ['libgdk_pixbuf-2.0-0.dll', |
---|
| 308 | 'libgobject-2.0-0.dll', |
---|
| 309 | 'libgdk-win32-2.0-0.dll', |
---|
| 310 | 'tcl84.dll', |
---|
| 311 | 'tk84.dll', |
---|
| 312 | 'QtGui4.dll', |
---|
| 313 | 'QtCore4.dll', |
---|
[ea32de3] | 314 | 'msvcp90.dll', |
---|
[59c6c1e] | 315 | 'w9xpopen.exe', |
---|
| 316 | 'cygwin1.dll'] |
---|
[fa597990] | 317 | |
---|
| 318 | target_wx_client = Target( |
---|
[c329f4d] | 319 | description = 'SasView', |
---|
[fa597990] | 320 | script = 'sansview.py', |
---|
| 321 | icon_resources = [(1, os.path.join(images_dir, "ball.ico"))], |
---|
| 322 | other_resources = [(24,1,manifest)], |
---|
[c329f4d] | 323 | dest_base = "SasView" |
---|
[fa597990] | 324 | ) |
---|
| 325 | |
---|
[7476d30] | 326 | bundle_option = 2 |
---|
[762984a] | 327 | if is_64bits: |
---|
[7476d30] | 328 | bundle_option = 3 |
---|
[fa597990] | 329 | |
---|
| 330 | setup( |
---|
| 331 | windows=[target_wx_client], |
---|
| 332 | console=[], |
---|
| 333 | options={ |
---|
| 334 | 'py2exe': { |
---|
| 335 | 'dll_excludes': dll_excludes, |
---|
| 336 | 'packages' : packages, |
---|
| 337 | 'includes':includes, |
---|
| 338 | 'excludes':excludes, |
---|
| 339 | "compressed": 1, |
---|
| 340 | "optimize": 0, |
---|
[7476d30] | 341 | "bundle_files":bundle_option, |
---|
[fa597990] | 342 | }, |
---|
| 343 | }, |
---|
| 344 | data_files=data_files, |
---|
| 345 | |
---|
| 346 | ) |
---|
| 347 | |
---|
| 348 | |
---|