[9909967] | 1 | import os |
---|
| 2 | import sys |
---|
| 3 | import scipy |
---|
| 4 | import matplotlib |
---|
| 5 | import cython |
---|
| 6 | |
---|
| 7 | import zmq.libzmq |
---|
| 8 | import periodictable |
---|
| 9 | import sasmodels |
---|
| 10 | import sasmodels.core |
---|
| 11 | |
---|
| 12 | from cx_Freeze import setup |
---|
| 13 | from cx_Freeze import Executable |
---|
| 14 | from distutils.filelist import findall |
---|
| 15 | from distutils.sysconfig import get_python_lib |
---|
| 16 | from distutils.filelist import findall |
---|
| 17 | from distutils.util import get_platform |
---|
| 18 | |
---|
| 19 | try: |
---|
| 20 | import tinycc |
---|
| 21 | except ImportError: |
---|
| 22 | warnings.warn("TinyCC package is not available and will not be included") |
---|
| 23 | tinycc = None |
---|
| 24 | |
---|
| 25 | # Full path to sasview/build/lib.<platform>-2.7 |
---|
| 26 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
---|
| 27 | platform = '%s-%s'%(get_platform(), sys.version[:3]) |
---|
| 28 | build_path = os.path.join(root, 'build', 'lib.'+platform) |
---|
| 29 | sys.path.insert(0, build_path) |
---|
| 30 | python_root = os.path.dirname(os.path.abspath(sys.executable)) |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | # Excluded packages |
---|
| 34 | excl = ['collections.sys', 'collections._weakref', 'Tkinter'] |
---|
| 35 | |
---|
| 36 | # Explicityl included modules |
---|
| 37 | incl = [ |
---|
| 38 | 'pygments', 'pygments.lexers','pygments.lexers.python', |
---|
| 39 | 'pygments.styles','pygments.styles.default', |
---|
| 40 | 'ipykernel', 'ipykernel.datapub', |
---|
| 41 | 'atexit', 'cython', 'sip', 'xhtml2pdf', |
---|
| 42 | 'zmq', 'zmq.utils', 'zmq.utils.strtypes', |
---|
| 43 | 'zmq.utils.jsonapi','zmq.utils.garbage', |
---|
| 44 | 'zmq.backend.cython','zmq.backend.cffi', |
---|
| 45 | 'site','lxml._elementpath','lxml.etree', |
---|
| 46 | ] |
---|
| 47 | |
---|
| 48 | # Extra packages |
---|
| 49 | packs = [ |
---|
| 50 | 'periodictable.core', |
---|
| 51 | 'matplotlib', |
---|
| 52 | 'encodings', |
---|
| 53 | 'comtypes', |
---|
| 54 | 'bumps', |
---|
| 55 | 'sasmodels', |
---|
| 56 | 'win32com', |
---|
| 57 | ] |
---|
| 58 | |
---|
| 59 | if tinycc: |
---|
| 60 | packs.append('tinycc') |
---|
| 61 | |
---|
| 62 | |
---|
| 63 | # Holder for extra files |
---|
| 64 | data_files = [] |
---|
| 65 | |
---|
| 66 | data_files.append(zmq.libzmq.__file__) |
---|
| 67 | data_files.append("local_config.py") |
---|
| 68 | data_files.append("custom_config.py") |
---|
| 69 | data_files.append("logging.ini") |
---|
| 70 | data_files.append("media/") |
---|
| 71 | data_files.append("images/") |
---|
| 72 | data_files.append("test/") |
---|
| 73 | data_files.append("plugin_models/") |
---|
[fef38e8] | 74 | data_files.append("compiled_models/") |
---|
[9909967] | 75 | |
---|
| 76 | def append_data(tups): |
---|
| 77 | # Convert py2exe tuple into cx_freeze tuple |
---|
| 78 | for tup in tups: |
---|
| 79 | target = tup[0] |
---|
| 80 | files = tup[1] |
---|
| 81 | for file in files: |
---|
| 82 | basename = os.path.basename(file) |
---|
| 83 | t = os.path.join(target, basename) |
---|
| 84 | data_files.append((file, t)) |
---|
| 85 | |
---|
| 86 | # Documents |
---|
| 87 | doc_source = os.path.join(build_path, 'doc/') |
---|
| 88 | data_files.append((doc_source, 'doc/')) |
---|
| 89 | |
---|
| 90 | # OPENCL |
---|
| 91 | site_loc = get_python_lib() |
---|
| 92 | opencl_include_dir = os.path.join(site_loc, "pyopencl", "cl") |
---|
| 93 | for f in findall(opencl_include_dir): |
---|
| 94 | target = os.path.join("includes", "pyopencl", os.path.basename(f)) |
---|
| 95 | data_files.append((f, target)) |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | append_data(periodictable.data_files()) |
---|
| 99 | append_data(sasmodels.data_files()) |
---|
| 100 | if tinycc: |
---|
| 101 | append_data(tinycc.data_files()) |
---|
| 102 | |
---|
| 103 | # MATPLOTLIB |
---|
| 104 | matplotlibdatadir = matplotlib.get_data_path() |
---|
| 105 | matplotlibdata = findall(matplotlibdatadir) |
---|
| 106 | for f in matplotlibdata: |
---|
| 107 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
| 108 | target = os.path.join(dirname, os.path.basename(f)) |
---|
| 109 | data_files.append((f, dirname)) |
---|
| 110 | |
---|
| 111 | # Numerical libraries |
---|
| 112 | def dll_check(dll_path, dlls): |
---|
| 113 | dll_includes = [os.path.join(dll_path, dll+'.dll') for dll in dlls] |
---|
| 114 | return [dll for dll in dll_includes if os.path.exists(dll)] |
---|
| 115 | |
---|
| 116 | # Check for ATLAS |
---|
| 117 | dll_path = os.path.join(python_root, 'lib', 'site-packages', 'numpy', 'core') |
---|
| 118 | dlls = ['numpy-atlas'] |
---|
| 119 | atlas_dlls = dll_check(dll_path, dlls) |
---|
| 120 | |
---|
| 121 | # Check for MKL |
---|
| 122 | dll_path = os.path.join(python_root, 'Library', 'bin') |
---|
| 123 | dlls = ['mkl_core', 'mkl_def', 'libiomp5md', 'libmmd', |
---|
| 124 | 'libmmdd', 'libiomp5md', 'libifcoremd', 'libifcoremdd'] |
---|
| 125 | mkl_dlls = dll_check(dll_path, dlls) |
---|
| 126 | |
---|
| 127 | to_include = mkl_dlls |
---|
| 128 | if atlas_dlls: |
---|
| 129 | to_include = atlas_dlls |
---|
| 130 | |
---|
| 131 | for library in to_include: |
---|
| 132 | target = os.path.basename(library) |
---|
| 133 | data_files.append((library, target)) |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | # Precompile models and add them |
---|
| 137 | dll_path = os.path.join(build_path, 'compiled_models') |
---|
| 138 | #compiled_dlls = sasmodels.core.precompile_dlls(dll_path, dtype='double') |
---|
| 139 | #for library in compiled_dlls: |
---|
| 140 | # target = os.path.join('compiled_models', os.path.basename(library)) |
---|
| 141 | # data_files.append((library, target)) |
---|
| 142 | |
---|
| 143 | # Extra logic for scipy |
---|
| 144 | scipy_path = os.path.dirname(scipy.__file__) |
---|
| 145 | data_files.append(scipy_path) |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | buildOptions = dict(packages = packs, excludes = excl, includes = incl, |
---|
| 149 | include_files = data_files) |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | base = 'Win32GUI' if sys.platform=='win32' else None |
---|
| 153 | |
---|
| 154 | icon = os.path.join('images','ball.ico') |
---|
| 155 | |
---|
| 156 | executables = [ |
---|
| 157 | Executable('sasview.py', |
---|
| 158 | icon=icon, |
---|
| 159 | base=base) |
---|
| 160 | ] |
---|
| 161 | |
---|
| 162 | setup( |
---|
| 163 | name='sasview', |
---|
| 164 | version = '5.0', |
---|
| 165 | description = 'SasviewQt Program', |
---|
| 166 | options = dict(build_exe = buildOptions), |
---|
| 167 | executables = executables |
---|
| 168 | ) |
---|
| 169 | |
---|
| 170 | |
---|