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 | from __future__ import print_function |
---|
16 | |
---|
17 | import os |
---|
18 | import sys |
---|
19 | import warnings |
---|
20 | from glob import glob |
---|
21 | import shutil |
---|
22 | |
---|
23 | from distutils.util import get_platform |
---|
24 | from distutils.core import setup |
---|
25 | from distutils.filelist import findall |
---|
26 | from distutils.sysconfig import get_python_lib |
---|
27 | import py2exe |
---|
28 | |
---|
29 | #from idlelib.PyShell import warning_stream |
---|
30 | |
---|
31 | # put the build directory at the front of the path |
---|
32 | if os.path.abspath(os.path.dirname(__file__)) != os.path.abspath(os.getcwd()): |
---|
33 | raise RuntimeError("Must run setup_exe from the sasview directory") |
---|
34 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
---|
35 | platform = '%s-%s'%(get_platform(), sys.version[:3]) |
---|
36 | doc_path = os.path.join(root, 'build', 'lib.'+platform, 'doc') |
---|
37 | build_path = os.path.join(root, 'sasview-install', 'Lib', 'site-packages') |
---|
38 | sys.path.insert(0, build_path) |
---|
39 | |
---|
40 | from sas.sasview import local_config |
---|
41 | from installer_generator import generate_installer |
---|
42 | |
---|
43 | import matplotlib |
---|
44 | try: |
---|
45 | import tinycc |
---|
46 | except ImportError: |
---|
47 | warnings.warn("TinyCC package is not available and will not be included") |
---|
48 | tinycc = None |
---|
49 | |
---|
50 | if len(sys.argv) == 1: |
---|
51 | sys.argv.append('py2exe') |
---|
52 | |
---|
53 | # When using the SasView build script, we need to be able to pass |
---|
54 | # an extra path to be added to the python path. The extra arguments |
---|
55 | # should be removed from the list so that the setup processing doesn't |
---|
56 | # fail. |
---|
57 | try: |
---|
58 | if sys.argv.count('--extrapath'): |
---|
59 | path_flag_idx = sys.argv.index('--extrapath') |
---|
60 | extra_path = sys.argv[path_flag_idx+1] |
---|
61 | sys.path.insert(0, extra_path) |
---|
62 | del sys.argv[path_flag_idx+1] |
---|
63 | sys.argv.remove('--extrapath') |
---|
64 | except: |
---|
65 | print("Error processing extra python path needed to build SasView\n %s" % |
---|
66 | sys.exc_value) |
---|
67 | |
---|
68 | |
---|
69 | # Solution taken from here: http://www.py2exe.org/index.cgi/win32com.shell |
---|
70 | # ModuleFinder can't handle runtime changes to __path__, but win32com uses them |
---|
71 | win32_folder = "win32comext" |
---|
72 | try: |
---|
73 | # py2exe 0.6.4 introduced a replacement modulefinder. |
---|
74 | # This means we have to add package paths there, not to the built-in |
---|
75 | # one. If this new modulefinder gets integrated into Python, then |
---|
76 | # we might be able to revert this some day. |
---|
77 | # if this doesn't work, try import modulefinder |
---|
78 | try: |
---|
79 | import py2exe.mf as modulefinder |
---|
80 | except ImportError: |
---|
81 | import modulefinder |
---|
82 | import win32com |
---|
83 | for p in win32com.__path__[1:]: |
---|
84 | modulefinder.AddPackagePath(win32_folder, p) |
---|
85 | for extra in ["win32com.shell", "win32com.adsi", "win32com.axcontrol", |
---|
86 | "win32com.axscript", "win32com.bits", "win32com.ifilter", |
---|
87 | "win32com.internet", "win32com.mapi", "win32com.propsys", |
---|
88 | "win32com.taskscheduler"]: |
---|
89 | __import__(extra) |
---|
90 | m = sys.modules[extra] |
---|
91 | for p in m.__path__[1:]: |
---|
92 | modulefinder.AddPackagePath(extra, p) |
---|
93 | |
---|
94 | except ImportError: |
---|
95 | # no build path setup, no worries. |
---|
96 | pass |
---|
97 | |
---|
98 | # Remove the build folder |
---|
99 | shutil.rmtree("build", ignore_errors=True) |
---|
100 | # do the same for dist folder |
---|
101 | shutil.rmtree("dist", ignore_errors=True) |
---|
102 | |
---|
103 | is_64bits = sys.maxsize > 2**32 |
---|
104 | arch = "amd64" if is_64bits else "x86" |
---|
105 | manifest = """ |
---|
106 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
---|
107 | <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> |
---|
108 | <assemblyIdentity |
---|
109 | version="5.0.0.0" |
---|
110 | processorArchitecture="%(arch)s" |
---|
111 | name="SasView" |
---|
112 | type="win32"> |
---|
113 | </assemblyIdentity> |
---|
114 | <description>SasView</description> |
---|
115 | <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> |
---|
116 | <security> |
---|
117 | <requestedPrivileges> |
---|
118 | <requestedExecutionLevel |
---|
119 | level="asInvoker" |
---|
120 | uiAccess="false"> |
---|
121 | </requestedExecutionLevel> |
---|
122 | </requestedPrivileges> |
---|
123 | </security> |
---|
124 | </trustInfo> |
---|
125 | <dependency> |
---|
126 | <dependentAssembly> |
---|
127 | <assemblyIdentity |
---|
128 | type="win32" |
---|
129 | name="Microsoft.VC90.CRT" |
---|
130 | version="9.0.21022.8" |
---|
131 | processorArchitecture="%(arch)s" |
---|
132 | publicKeyToken="1fc8b3b9a1e18e3b"> |
---|
133 | </assemblyIdentity> |
---|
134 | </dependentAssembly> |
---|
135 | </dependency> |
---|
136 | <dependency> |
---|
137 | <dependentAssembly> |
---|
138 | <assemblyIdentity |
---|
139 | type="win32" |
---|
140 | name="Microsoft.Windows.Common-Controls" |
---|
141 | version="6.0.0.0" |
---|
142 | processorArchitecture="%(arch)s" |
---|
143 | publicKeyToken="6595b64144ccf1df" |
---|
144 | language="*"> |
---|
145 | </assemblyIdentity> |
---|
146 | </dependentAssembly> |
---|
147 | </dependency> |
---|
148 | </assembly> |
---|
149 | """%{'arch': arch} |
---|
150 | |
---|
151 | if is_64bits: |
---|
152 | msvcrtdll = glob(r"C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*") |
---|
153 | else: |
---|
154 | msvcrtdll = glob(r"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*") |
---|
155 | if msvcrtdll: |
---|
156 | msvcrtdll_data_files = ("Microsoft.VC90.CRT", msvcrtdll) |
---|
157 | else: |
---|
158 | msvcrtdll_data_files = None |
---|
159 | |
---|
160 | |
---|
161 | class Target: |
---|
162 | def __init__(self, **kw): |
---|
163 | self.__dict__.update(kw) |
---|
164 | # for the versioninfo resources |
---|
165 | self.version = local_config.__version__ |
---|
166 | self.company_name = "SasView.org" |
---|
167 | self.copyright = "copyright 2009 - 2016" |
---|
168 | self.name = "SasView" |
---|
169 | |
---|
170 | # |
---|
171 | # Adapted from http://www.py2exe.org/index.cgi/MatPlotLib |
---|
172 | # to use the MatPlotLib. |
---|
173 | # |
---|
174 | path = os.getcwd() |
---|
175 | |
---|
176 | matplotlibdatadir = matplotlib.get_data_path() |
---|
177 | matplotlibdata = findall(matplotlibdatadir) |
---|
178 | |
---|
179 | DATA_FILES = [] |
---|
180 | |
---|
181 | if tinycc: |
---|
182 | DATA_FILES += tinycc.data_files() |
---|
183 | |
---|
184 | # Copying SLD data |
---|
185 | import periodictable |
---|
186 | DATA_FILES += periodictable.data_files() |
---|
187 | |
---|
188 | from sas.sasgui.perspectives import fitting |
---|
189 | DATA_FILES += fitting.data_files() |
---|
190 | |
---|
191 | from sas.sasgui.perspectives import calculator |
---|
192 | DATA_FILES += calculator.data_files() |
---|
193 | |
---|
194 | from sas.sasgui.perspectives import invariant |
---|
195 | DATA_FILES += invariant.data_files() |
---|
196 | |
---|
197 | from sas.sasgui import guiframe |
---|
198 | DATA_FILES += guiframe.data_files() |
---|
199 | |
---|
200 | # precompile sas models into the sasview build path; doesn't matter too much |
---|
201 | # where it is so long as it is a place that will get cleaned up afterwards. |
---|
202 | import sasmodels.core |
---|
203 | dll_path = os.path.join(build_path, 'compiled_models') |
---|
204 | compiled_dlls = sasmodels.core.precompile_dlls(dll_path, dtype='double') |
---|
205 | |
---|
206 | # include the compiled models as data; coordinate the target path for the |
---|
207 | # data with installer_generator.py |
---|
208 | DATA_FILES.append(('compiled_models', compiled_dlls)) |
---|
209 | |
---|
210 | import sasmodels |
---|
211 | DATA_FILES += sasmodels.data_files() |
---|
212 | |
---|
213 | for f in matplotlibdata: |
---|
214 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
215 | DATA_FILES.append((os.path.split(dirname)[0], [f])) |
---|
216 | |
---|
217 | # Copy the settings file for the sas.dataloader file extension associations |
---|
218 | from sas.sascalc.dataloader import readers |
---|
219 | reader_config = os.path.join(readers.get_data_path(), 'defaults.json') |
---|
220 | if os.path.isfile(reader_config): |
---|
221 | DATA_FILES.append(('.', [reader_config])) |
---|
222 | |
---|
223 | # Copy the config files |
---|
224 | sas_path = os.path.join('..', 'src', 'sas') |
---|
225 | DATA_FILES.append(('.', [os.path.join(sas_path, 'logging.ini')])) |
---|
226 | sasview_path = os.path.join(sas_path,'sasview') |
---|
227 | config_files = [ |
---|
228 | 'custom_config.py', |
---|
229 | 'local_config.py', |
---|
230 | #'default_categories.json', |
---|
231 | ] |
---|
232 | DATA_FILES.append(('.', [os.path.join(sasview_path, v) for v in config_files])) |
---|
233 | DATA_FILES.append(('config', [os.path.join(sasview_path, 'custom_config.py')])) |
---|
234 | |
---|
235 | # default_categories.json is beside the config files |
---|
236 | category_config = os.path.join(os.path.dirname(local_config_file), |
---|
237 | 'default_categories.json') |
---|
238 | if os.path.isfile(category_config): |
---|
239 | DATA_FILES.append(('.', [category_config])) |
---|
240 | |
---|
241 | if os.path.isfile("BUILD_NUMBER"): |
---|
242 | DATA_FILES.append(('.', ["BUILD_NUMBER"])) |
---|
243 | |
---|
244 | images_dir = local_config.icon_path |
---|
245 | media_dir = local_config.media_path |
---|
246 | test_dir = local_config.test_path |
---|
247 | test_1d_dir = os.path.join(test_dir, "1d_data") |
---|
248 | test_2d_dir = os.path.join(test_dir, "2d_data") |
---|
249 | test_save_dir = os.path.join(test_dir, "save_states") |
---|
250 | test_upcoming_dir = os.path.join(test_dir, "upcoming_formats") |
---|
251 | |
---|
252 | # Copying the images directory to the distribution directory. |
---|
253 | for f in findall(images_dir): |
---|
254 | DATA_FILES.append(("images", [f])) |
---|
255 | |
---|
256 | # Copying the HTML help docs |
---|
257 | for f in findall(media_dir): |
---|
258 | DATA_FILES.append(("media", [f])) |
---|
259 | |
---|
260 | # Copying the sample data user data |
---|
261 | for f in findall(test_1d_dir): |
---|
262 | DATA_FILES.append((os.path.join("test","1d_data"), [f])) |
---|
263 | |
---|
264 | # Copying the sample data user data |
---|
265 | for f in findall(test_2d_dir): |
---|
266 | DATA_FILES.append((os.path.join("test","2d_data"), [f])) |
---|
267 | |
---|
268 | # Copying the sample data user data |
---|
269 | for f in findall(test_save_dir): |
---|
270 | DATA_FILES.append((os.path.join("test","save_states"), [f])) |
---|
271 | |
---|
272 | # Copying the sample data user data |
---|
273 | for f in findall(test_upcoming_dir): |
---|
274 | DATA_FILES.append((os.path.join("test","upcoming_formats"), [f])) |
---|
275 | |
---|
276 | # Copying opencl include files |
---|
277 | site_loc = get_python_lib() |
---|
278 | opencl_include_dir = os.path.join(site_loc, "pyopencl", "cl") |
---|
279 | for f in findall(opencl_include_dir): |
---|
280 | DATA_FILES.append((os.path.join("includes","pyopencl"), [f])) |
---|
281 | |
---|
282 | # Numerical libraries |
---|
283 | python_root = os.path.dirname(os.path.abspath(sys.executable)) |
---|
284 | def dll_check(dll_path, dlls): |
---|
285 | dll_includes = [os.path.join(dll_path, dll+'.dll') for dll in dlls] |
---|
286 | return [dll for dll in dll_includes if os.path.exists(dll)] |
---|
287 | |
---|
288 | # Check for ATLAS |
---|
289 | numpy_path = os.path.join(python_root, 'lib', 'site-packages', 'numpy', 'core') |
---|
290 | atlas_dlls = dll_check(numpy_path, ['numpy-atlas']) |
---|
291 | |
---|
292 | # Check for MKL |
---|
293 | mkl_path = os.path.join(python_root, 'Library', 'bin') |
---|
294 | mkl_dlls = dll_check(mkl_path, ['mkl_core', 'mkl_def', 'libiomp5md']) |
---|
295 | |
---|
296 | if atlas_dlls: |
---|
297 | DATA_FILES.append(('.', atlas_dlls)) |
---|
298 | elif mkl_dlls: |
---|
299 | DATA_FILES.append(('.', mkl_dlls)) |
---|
300 | |
---|
301 | # See if the documentation has been built, and if so include it. |
---|
302 | if os.path.exists(doc_path): |
---|
303 | for dirpath, dirnames, filenames in os.walk(doc_path): |
---|
304 | for filename in filenames: |
---|
305 | sub_dir = os.path.join("doc", os.path.relpath(dirpath, doc_path)) |
---|
306 | DATA_FILES.append((sub_dir, [os.path.join(dirpath, filename)])) |
---|
307 | else: |
---|
308 | raise Exception("You must first build the documentation before creating an installer.") |
---|
309 | |
---|
310 | if msvcrtdll_data_files is not None: |
---|
311 | # install the MSVC 9 runtime dll's into the application folder |
---|
312 | DATA_FILES.append(msvcrtdll_data_files) |
---|
313 | |
---|
314 | # NOTE: |
---|
315 | # need an empty __init__.py in site-packages/numpy/distutils/tests and site-packages/mpl_toolkits |
---|
316 | |
---|
317 | # packages |
---|
318 | # |
---|
319 | packages = [ |
---|
320 | 'matplotlib', 'scipy', 'encodings', 'comtypes', 'h5py', |
---|
321 | 'win32com', 'xhtml2pdf', 'bumps','sasmodels', 'sas', |
---|
322 | ] |
---|
323 | packages.extend([ |
---|
324 | 'reportlab', |
---|
325 | 'reportlab.graphics.charts', |
---|
326 | 'reportlab.graphics.samples', |
---|
327 | 'reportlab.graphics.widgets', |
---|
328 | 'reportlab.graphics.barcode', |
---|
329 | 'reportlab.graphics', |
---|
330 | 'reportlab.lib', |
---|
331 | 'reportlab.pdfbase', |
---|
332 | 'reportlab.pdfgen', |
---|
333 | 'reportlab.platypus', |
---|
334 | ]) |
---|
335 | packages.append('periodictable.core') # not found automatically |
---|
336 | |
---|
337 | # For an interactive interpreter, SasViewCom |
---|
338 | packages.extend(['IPython','pyreadline','pyreadline.unicode_helper']) |
---|
339 | |
---|
340 | # individual models |
---|
341 | includes = ['site', 'lxml._elementpath', 'lxml.etree'] |
---|
342 | |
---|
343 | if tinycc: |
---|
344 | packages.append('tinycc') |
---|
345 | |
---|
346 | # Exclude packages that are not needed but are often found on build systems |
---|
347 | excludes = ['Tkinter', 'PyQt4', '_tkagg', 'sip', 'pytz', 'sympy'] |
---|
348 | |
---|
349 | |
---|
350 | # Various matplotlib backends we are not using |
---|
351 | 'libgdk_pixbuf-2.0-0.dll', 'libgobject-2.0-0.dll', 'libgdk-win32-2.0-0.dll', |
---|
352 | 'tcl84.dll', 'tk84.dll', 'QtGui4.dll', 'QtCore4.dll', |
---|
353 | # numpy 1.8 openmp bindings (still seems to use all the cores without them) |
---|
354 | # ... but we seem to need them when building from anaconda, so don't exclude ... |
---|
355 | #'libiomp5md.dll', 'libifcoremd.dll', 'libmmd.dll', 'svml_dispmd.dll','libifportMD.dll', |
---|
356 | 'numpy-atlas.dll', |
---|
357 | # microsoft C runtime (not allowed to ship with the app; need to ship vcredist |
---|
358 | 'msvcp90.dll', |
---|
359 | # 32-bit windows console piping |
---|
360 | 'w9xpopen.exe', |
---|
361 | # accidental links to msys/cygwin binaries; shouldn't be needed |
---|
362 | 'cygwin1.dll', |
---|
363 | # no need to distribute OpenCL.dll - users should have their own copy |
---|
364 | 'OpenCL.dll' |
---|
365 | ] |
---|
366 | |
---|
367 | target_wx_client = Target( |
---|
368 | description = 'SasView', |
---|
369 | script = 'sasview_gui.py', |
---|
370 | icon_resources = [(1, local_config.SetupIconFile_win)], |
---|
371 | other_resources = [(24, 1, manifest)], |
---|
372 | dest_base = "SasView" |
---|
373 | ) |
---|
374 | |
---|
375 | target_console_client = Target( |
---|
376 | description = 'SasView console', |
---|
377 | script = 'sasview_console.py', |
---|
378 | icon_resources = [(1, local_config.SetupIconFile_win)], |
---|
379 | other_resources = [(24, 1, manifest)], |
---|
380 | dest_base = "SasViewCom" |
---|
381 | ) |
---|
382 | |
---|
383 | bundle_option = 3 if is_64bits else 2 |
---|
384 | generate_installer() |
---|
385 | #initialize category stuff |
---|
386 | #from sas.sasgui.guiframe.CategoryInstaller import CategoryInstaller |
---|
387 | #CategoryInstaller.check_install(s) |
---|
388 | |
---|
389 | setup( |
---|
390 | windows=[target_wx_client], |
---|
391 | console=[target_console_client], |
---|
392 | options={ |
---|
393 | 'py2exe': { |
---|
394 | 'dll_excludes': dll_excludes, |
---|
395 | 'packages': packages, |
---|
396 | 'includes': includes, |
---|
397 | 'excludes': excludes, |
---|
398 | "compressed": 1, |
---|
399 | "optimize": 0, |
---|
400 | "bundle_files": bundle_option, |
---|
401 | }, |
---|
402 | }, |
---|
403 | data_files=DATA_FILES, |
---|
404 | ) |
---|