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