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 | |
---|
40 | |
---|
41 | origIsSystemDLL = py2exe.build_exe.isSystemDLL |
---|
42 | def isSystemDLL(pathname): |
---|
43 | if os.path.basename(pathname).lower() in ("msvcp71.dll", "comctl32.dll", "msvcr90.dll", "dwmapi.dll"): |
---|
44 | return 0 |
---|
45 | return origIsSystemDLL(pathname) |
---|
46 | py2exe.build_exe.isSystemDLL = isSystemDLL |
---|
47 | |
---|
48 | if platform.architecture()[0] == '64bit': |
---|
49 | manifest = """ |
---|
50 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
51 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
52 | manifestVersion="1.0"> |
---|
53 | <assemblyIdentity |
---|
54 | version="0.64.1.0" |
---|
55 | processorArchitecture="amd64" |
---|
56 | name="Controls" |
---|
57 | type="win32" |
---|
58 | /> |
---|
59 | <description>SansView</description> |
---|
60 | <dependency> |
---|
61 | <dependentAssembly> |
---|
62 | <assemblyIdentity |
---|
63 | type="win32" |
---|
64 | name="Microsoft.Windows.Common-Controls" |
---|
65 | version="6.0.0.0" |
---|
66 | processorArchitecture="amd64" |
---|
67 | publicKeyToken="6595b64144ccf1df" |
---|
68 | language="*" |
---|
69 | /> |
---|
70 | </dependentAssembly> |
---|
71 | </dependency> |
---|
72 | </assembly> |
---|
73 | """ |
---|
74 | else: |
---|
75 | manifest = """ |
---|
76 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
77 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" |
---|
78 | manifestVersion="1.0"> |
---|
79 | <assemblyIdentity |
---|
80 | version="0.64.1.0" |
---|
81 | processorArchitecture="x86" |
---|
82 | name="Controls" |
---|
83 | type="win32" |
---|
84 | /> |
---|
85 | <description>SansView</description> |
---|
86 | <dependency> |
---|
87 | <dependentAssembly> |
---|
88 | <assemblyIdentity |
---|
89 | type="win32" |
---|
90 | name="Microsoft.Windows.Common-Controls" |
---|
91 | version="6.0.0.0" |
---|
92 | processorArchitecture="X86" |
---|
93 | publicKeyToken="6595b64144ccf1df" |
---|
94 | language="*" |
---|
95 | /> |
---|
96 | </dependentAssembly> |
---|
97 | </dependency> |
---|
98 | </assembly> |
---|
99 | """ |
---|
100 | |
---|
101 | |
---|
102 | class Target: |
---|
103 | def __init__(self, **kw): |
---|
104 | self.__dict__.update(kw) |
---|
105 | # for the versioninfo resources |
---|
106 | self.version = "2.0.1" |
---|
107 | self.company_name = "U Tennessee" |
---|
108 | self.copyright = "copyright 2009 - 2011" |
---|
109 | self.name = "SansView" |
---|
110 | |
---|
111 | # |
---|
112 | # Adapted from http://www.py2exe.org/index.cgi/MatPlotLib |
---|
113 | # to use the MatPlotLib. |
---|
114 | # |
---|
115 | path = os.getcwd() |
---|
116 | |
---|
117 | plugins_dir = os.path.join(path, "plugins") |
---|
118 | media_dir = os.path.join(path, "media") |
---|
119 | images_dir = os.path.join(path, "images") |
---|
120 | test_dir = os.path.join(path, "test") |
---|
121 | |
---|
122 | matplotlibdatadir = matplotlib.get_data_path() |
---|
123 | matplotlibdata = findall(matplotlibdatadir) |
---|
124 | data_files = [] |
---|
125 | # Copying SLD data |
---|
126 | import periodictable |
---|
127 | import logging |
---|
128 | data_files += periodictable.data_files() |
---|
129 | |
---|
130 | import sans.perspectives.fitting as fitting |
---|
131 | data_files += fitting.data_files() |
---|
132 | |
---|
133 | import sans.perspectives.calculator as calculator |
---|
134 | data_files += calculator.data_files() |
---|
135 | |
---|
136 | import sans.perspectives.invariant as invariant |
---|
137 | data_files += invariant.data_files() |
---|
138 | |
---|
139 | import sans.guiframe as guiframe |
---|
140 | data_files += guiframe.data_files() |
---|
141 | |
---|
142 | import sans.models as models |
---|
143 | data_files += models.data_files() |
---|
144 | |
---|
145 | for f in matplotlibdata: |
---|
146 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
147 | data_files.append((os.path.split(dirname)[0], [f])) |
---|
148 | |
---|
149 | # Copy the settings file for the sans.dataloader file extension associations |
---|
150 | import sans.dataloader.readers |
---|
151 | f = os.path.join(sans.dataloader.readers.get_data_path(),'defaults.xml') |
---|
152 | if os.path.isfile(f): |
---|
153 | data_files.append(('.', [f])) |
---|
154 | f = 'custom_config.py' |
---|
155 | if os.path.isfile(f): |
---|
156 | data_files.append(('.', [f])) |
---|
157 | f = 'local_config.py' |
---|
158 | if os.path.isfile(f): |
---|
159 | data_files.append(('.', [f])) |
---|
160 | # Copying the images directory to the distribution directory. |
---|
161 | for f in findall(images_dir): |
---|
162 | if os.path.split(f)[0].count('.svn')==0: |
---|
163 | data_files.append(("images", [f])) |
---|
164 | |
---|
165 | # Copying the HTML help docs |
---|
166 | for f in findall(media_dir): |
---|
167 | if os.path.split(f)[0].count('.svn')==0: |
---|
168 | data_files.append(("media", [f])) |
---|
169 | |
---|
170 | # Copying the sample data user data |
---|
171 | for f in findall(test_dir): |
---|
172 | if os.path.split(f)[0].count('.svn')==0: |
---|
173 | data_files.append(("test", [f])) |
---|
174 | |
---|
175 | # Copying the sample data user data |
---|
176 | for f in findall(plugins_dir): |
---|
177 | if os.path.split(f)[0].count('.svn')==0: |
---|
178 | data_files.append(('plugins', [f])) |
---|
179 | |
---|
180 | |
---|
181 | # |
---|
182 | # packages |
---|
183 | # |
---|
184 | |
---|
185 | packages = ['matplotlib', 'scipy', 'pytz', 'encodings'] |
---|
186 | includes = ['site'] |
---|
187 | |
---|
188 | # Exclude packages that are not needed but are often found on build systems |
---|
189 | excludes = ['PyQt4','sip','pylab'] |
---|
190 | |
---|
191 | dll_excludes = [ |
---|
192 | 'libgdk_pixbuf-2.0-0.dll', |
---|
193 | 'libgobject-2.0-0.dll', |
---|
194 | 'libgdk-win32-2.0-0.dll', |
---|
195 | ] |
---|
196 | |
---|
197 | target_wx_client = Target( |
---|
198 | description = 'SansView', |
---|
199 | script = 'sansview.py', |
---|
200 | icon_resources = [(1, os.path.join(images_dir, "ball.ico"))], |
---|
201 | other_resources = [(24,1,manifest)], |
---|
202 | dest_base = "SansView" |
---|
203 | ) |
---|
204 | |
---|
205 | bundle_option = 2 |
---|
206 | if platform.architecture()[0] == '64bit': |
---|
207 | bundle_option = 3 |
---|
208 | |
---|
209 | setup( |
---|
210 | windows=[target_wx_client], |
---|
211 | console=[], |
---|
212 | |
---|
213 | options={ |
---|
214 | 'py2exe': { |
---|
215 | 'dll_excludes': dll_excludes, |
---|
216 | 'packages' : packages, |
---|
217 | 'includes':includes, |
---|
218 | 'excludes':excludes, |
---|
219 | "compressed": 1, |
---|
220 | "optimize": 0, |
---|
221 | "bundle_files":bundle_option, |
---|
222 | }, |
---|
223 | }, |
---|
224 | data_files=data_files, |
---|
225 | |
---|
226 | ) |
---|
227 | |
---|
228 | |
---|