[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/") |
---|
| 74 | |
---|
| 75 | def append_data(tups): |
---|
| 76 | # Convert py2exe tuple into cx_freeze tuple |
---|
| 77 | for tup in tups: |
---|
| 78 | target = tup[0] |
---|
| 79 | files = tup[1] |
---|
| 80 | for file in files: |
---|
| 81 | basename = os.path.basename(file) |
---|
| 82 | t = os.path.join(target, basename) |
---|
| 83 | data_files.append((file, t)) |
---|
| 84 | |
---|
| 85 | # Documents |
---|
| 86 | doc_source = os.path.join(build_path, 'doc/') |
---|
| 87 | data_files.append((doc_source, 'doc/')) |
---|
| 88 | |
---|
| 89 | # OPENCL |
---|
| 90 | site_loc = get_python_lib() |
---|
| 91 | opencl_include_dir = os.path.join(site_loc, "pyopencl", "cl") |
---|
| 92 | for f in findall(opencl_include_dir): |
---|
| 93 | target = os.path.join("includes", "pyopencl", os.path.basename(f)) |
---|
| 94 | data_files.append((f, target)) |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | append_data(periodictable.data_files()) |
---|
| 98 | append_data(sasmodels.data_files()) |
---|
| 99 | if tinycc: |
---|
| 100 | append_data(tinycc.data_files()) |
---|
| 101 | |
---|
| 102 | # MATPLOTLIB |
---|
| 103 | matplotlibdatadir = matplotlib.get_data_path() |
---|
| 104 | matplotlibdata = findall(matplotlibdatadir) |
---|
| 105 | for f in matplotlibdata: |
---|
| 106 | dirname = os.path.join('mpl-data', f[len(matplotlibdatadir)+1:]) |
---|
| 107 | target = os.path.join(dirname, os.path.basename(f)) |
---|
| 108 | data_files.append((f, dirname)) |
---|
| 109 | |
---|
| 110 | # Numerical libraries |
---|
| 111 | def dll_check(dll_path, dlls): |
---|
| 112 | dll_includes = [os.path.join(dll_path, dll+'.dll') for dll in dlls] |
---|
| 113 | return [dll for dll in dll_includes if os.path.exists(dll)] |
---|
| 114 | |
---|
| 115 | # Check for ATLAS |
---|
| 116 | dll_path = os.path.join(python_root, 'lib', 'site-packages', 'numpy', 'core') |
---|
| 117 | dlls = ['numpy-atlas'] |
---|
| 118 | atlas_dlls = dll_check(dll_path, dlls) |
---|
| 119 | |
---|
| 120 | # Check for MKL |
---|
| 121 | dll_path = os.path.join(python_root, 'Library', 'bin') |
---|
| 122 | dlls = ['mkl_core', 'mkl_def', 'libiomp5md', 'libmmd', |
---|
| 123 | 'libmmdd', 'libiomp5md', 'libifcoremd', 'libifcoremdd'] |
---|
| 124 | mkl_dlls = dll_check(dll_path, dlls) |
---|
| 125 | |
---|
| 126 | to_include = mkl_dlls |
---|
| 127 | if atlas_dlls: |
---|
| 128 | to_include = atlas_dlls |
---|
| 129 | |
---|
| 130 | for library in to_include: |
---|
| 131 | target = os.path.basename(library) |
---|
| 132 | data_files.append((library, target)) |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | # Precompile models and add them |
---|
| 136 | dll_path = os.path.join(build_path, 'compiled_models') |
---|
| 137 | #compiled_dlls = sasmodels.core.precompile_dlls(dll_path, dtype='double') |
---|
| 138 | #for library in compiled_dlls: |
---|
| 139 | # target = os.path.join('compiled_models', os.path.basename(library)) |
---|
| 140 | # data_files.append((library, target)) |
---|
| 141 | |
---|
| 142 | # Extra logic for scipy |
---|
| 143 | scipy_path = os.path.dirname(scipy.__file__) |
---|
| 144 | data_files.append(scipy_path) |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | buildOptions = dict(packages = packs, excludes = excl, includes = incl, |
---|
| 148 | include_files = data_files) |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | base = 'Win32GUI' if sys.platform=='win32' else None |
---|
| 152 | |
---|
| 153 | icon = os.path.join('images','ball.ico') |
---|
| 154 | |
---|
| 155 | executables = [ |
---|
| 156 | Executable('sasview.py', |
---|
| 157 | icon=icon, |
---|
| 158 | base=base) |
---|
| 159 | ] |
---|
| 160 | |
---|
| 161 | setup( |
---|
| 162 | name='sasview', |
---|
| 163 | version = '5.0', |
---|
| 164 | description = 'SasviewQt Program', |
---|
| 165 | options = dict(build_exe = buildOptions), |
---|
| 166 | executables = executables |
---|
| 167 | ) |
---|
| 168 | |
---|
| 169 | |
---|