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