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