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