source: sasview/sasview/setup_exe.py @ f36e01f

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f36e01f was f36e01f, checked in by Ricardo Ferraz Leal <ricleal@…>, 7 years ago

Some pylint enhancements

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