[959eb01] | 1 | """ |
---|
| 2 | This is a setup.py script partly generated by py2applet |
---|
| 3 | |
---|
| 4 | Usage: |
---|
| 5 | python setup.py py2app |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | NOTES: |
---|
[25a42f99] | 9 | 12/01/2011: When seeing an error related to pytz.zoneinfo not being found, |
---|
| 10 | change the following line in py2app/recipes/matplotlib.py |
---|
[959eb01] | 11 | mf.import_hook('pytz.tzinfo', m, ['UTC']) |
---|
| 12 | 12/05/2011: Needs macholib >= 1.4.3 and py2app >= 0.6.4 to create a 64-bit app |
---|
| 13 | """ |
---|
[d66dbcc] | 14 | from __future__ import print_function |
---|
| 15 | |
---|
[959eb01] | 16 | import os |
---|
| 17 | import sys |
---|
[0046c6a] | 18 | import string |
---|
[914ba0a] | 19 | |
---|
[959eb01] | 20 | from distutils.util import get_platform |
---|
[914ba0a] | 21 | from distutils.filelist import findall |
---|
| 22 | from distutils.sysconfig import get_python_lib |
---|
[d66dbcc] | 23 | |
---|
| 24 | from setuptools import setup |
---|
| 25 | |
---|
[92df9cbd] | 26 | # Need the installer dir on the python path to find helper modules |
---|
| 27 | installer_dir = os.path.abspath(os.path.dirname(__file__)) |
---|
| 28 | if installer_dir != os.path.abspath(os.getcwd()): |
---|
[0046c6a] | 29 | raise RuntimeError("Must run setup_exe from the installers directory") |
---|
[92df9cbd] | 30 | sys.path.append(installer_dir) |
---|
[0046c6a] | 31 | |
---|
| 32 | # put the build directory at the front of the path |
---|
[959eb01] | 33 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
---|
[d66dbcc] | 34 | platform = '%s-%s'%(get_platform(), sys.version[:3]) |
---|
[914ba0a] | 35 | doc_path = os.path.join(root, 'build', 'lib.'+platform, 'doc') |
---|
[0046c6a] | 36 | build_path = os.path.join(root, 'sasview-install', 'lib', 'python2.7', 'site-packages') |
---|
| 37 | #sys.path.insert(0, build_path) |
---|
[914ba0a] | 38 | |
---|
[d66dbcc] | 39 | #Extending recursion limit |
---|
| 40 | sys.setrecursionlimit(10000) |
---|
| 41 | |
---|
[ce81f70] | 42 | if len(sys.argv) == 1: |
---|
| 43 | sys.argv.append('py2app') |
---|
| 44 | |
---|
[92df9cbd] | 45 | import macholib_patch |
---|
| 46 | |
---|
[b963b20] | 47 | from sas import get_local_config |
---|
| 48 | local_config = get_local_config() |
---|
[914ba0a] | 49 | |
---|
[959eb01] | 50 | ICON = local_config.SetupIconFile_mac |
---|
[0046c6a] | 51 | data_files = [] |
---|
[959eb01] | 52 | |
---|
[0046c6a] | 53 | # Include data for supporting packages |
---|
[914ba0a] | 54 | import periodictable |
---|
[0046c6a] | 55 | data_files += periodictable.data_files() |
---|
| 56 | |
---|
| 57 | import sasmodels |
---|
| 58 | data_files += sasmodels.data_files() |
---|
| 59 | |
---|
| 60 | # Data files for the different perspectives |
---|
[914ba0a] | 61 | from sas.sasgui.perspectives import fitting |
---|
[0046c6a] | 62 | data_files += fitting.data_files() |
---|
| 63 | |
---|
[914ba0a] | 64 | from sas.sasgui.perspectives import calculator |
---|
[0046c6a] | 65 | data_files += calculator.data_files() |
---|
| 66 | |
---|
[914ba0a] | 67 | from sas.sasgui.perspectives import invariant |
---|
[0046c6a] | 68 | data_files += invariant.data_files() |
---|
[959eb01] | 69 | |
---|
[0046c6a] | 70 | from sas.sasgui import guiframe |
---|
| 71 | data_files += guiframe.data_files() |
---|
[914ba0a] | 72 | |
---|
| 73 | # Copy the config files |
---|
[0ccbd36] | 74 | sasview_path = os.path.join('..', 'src', 'sas', 'sasview') |
---|
[0046c6a] | 75 | data_files.append(('.', [os.path.join(sasview_path, 'custom_config.py')])) |
---|
| 76 | data_files.append(('config', [os.path.join(sasview_path, 'custom_config.py')])) |
---|
| 77 | data_files.append(('.', [os.path.join(sasview_path, 'local_config.py')])) |
---|
[914ba0a] | 78 | |
---|
[0046c6a] | 79 | # Copy the logging config |
---|
| 80 | sas_path = os.path.join('..', 'src', 'sas') |
---|
| 81 | data_files.append(('.', [os.path.join(sas_path, 'logging.ini')])) |
---|
[914ba0a] | 82 | |
---|
[0046c6a] | 83 | if os.path.isfile("BUILD_NUMBER"): |
---|
| 84 | data_files.append(('.', ["BUILD_NUMBER"])) |
---|
[914ba0a] | 85 | |
---|
| 86 | # Copying the images directory to the distribution directory. |
---|
[92df9cbd] | 87 | data_files.append(("images", findall(local_config.icon_path))) |
---|
[914ba0a] | 88 | |
---|
| 89 | # Copying the HTML help docs |
---|
[92df9cbd] | 90 | data_files.append(("media", findall(local_config.media_path))) |
---|
[914ba0a] | 91 | |
---|
| 92 | # Copying the sample data user data |
---|
[0046c6a] | 93 | test_dir = local_config.test_path |
---|
[92df9cbd] | 94 | for dirpath, dirnames, filenames in os.walk(test_dir): |
---|
| 95 | target_dir = os.path.join("test", os.path.relpath(dirpath, test_dir)) |
---|
| 96 | source_files = [os.path.join(dirpath, f) for f in filenames] |
---|
| 97 | data_files.append((target_dir, source_files)) |
---|
[959eb01] | 98 | |
---|
| 99 | # See if the documentation has been built, and if so include it. |
---|
| 100 | if os.path.exists(doc_path): |
---|
| 101 | for dirpath, dirnames, filenames in os.walk(doc_path): |
---|
[92df9cbd] | 102 | target_dir = os.path.join("doc", os.path.relpath(dirpath, doc_path)) |
---|
| 103 | source_files = [os.path.join(dirpath, f) for f in filenames] |
---|
| 104 | data_files.append((target_dir, source_files)) |
---|
[959eb01] | 105 | else: |
---|
| 106 | raise Exception("You must first build the documentation before creating an installer.") |
---|
| 107 | |
---|
[0046c6a] | 108 | # Copying opencl include files |
---|
[92df9cbd] | 109 | opencl_source = os.path.join(get_python_lib(), "pyopencl", "cl") |
---|
| 110 | opencl_target = os.path.join("includes", "pyopencl") |
---|
| 111 | data_files.append((opencl_target, findall(opencl_source))) |
---|
[0046c6a] | 112 | |
---|
| 113 | # Locate libxml2 library |
---|
| 114 | lib_locs = ['/usr/local/lib', '/usr/lib'] |
---|
| 115 | libxml_path = None |
---|
| 116 | for item in lib_locs: |
---|
| 117 | libxml_path_test = '%s/libxml2.2.dylib' % item |
---|
| 118 | if os.path.isfile(libxml_path_test): |
---|
| 119 | libxml_path = libxml_path_test |
---|
| 120 | if libxml_path is None: |
---|
| 121 | raise RuntimeError("Could not find libxml2 on the system") |
---|
| 122 | |
---|
[959eb01] | 123 | # locate file extensions |
---|
| 124 | def find_extension(): |
---|
| 125 | """ |
---|
| 126 | Describe the extensions that can be read by the current application |
---|
| 127 | """ |
---|
| 128 | try: |
---|
[a67ec83] | 129 | extensions = [] |
---|
[959eb01] | 130 | EXCEPTION_LIST = ['*', '.', ''] |
---|
| 131 | from sas.sascalc.dataloader.loader import Loader |
---|
| 132 | wild_cards = Loader().get_wildcards() |
---|
| 133 | for item in wild_cards: |
---|
| 134 | #['All (*.*)|*.*'] |
---|
| 135 | file_type, ext = string.split(item, "|*.", 1) |
---|
[a67ec83] | 136 | if ext.strip() not in EXCEPTION_LIST and ext.strip() not in extensions: |
---|
| 137 | extensions.append(ext) |
---|
| 138 | except Exception: |
---|
[959eb01] | 139 | pass |
---|
| 140 | try: |
---|
| 141 | file_type, ext = string.split(local_config.APPLICATION_WLIST, "|*.", 1) |
---|
[a67ec83] | 142 | if ext.strip() not in EXCEPTION_LIST and ext.strip() not in extensions: |
---|
| 143 | extensions.append(ext) |
---|
| 144 | except Exception: |
---|
[959eb01] | 145 | pass |
---|
| 146 | try: |
---|
| 147 | for item in local_config.PLUGINS_WLIST: |
---|
| 148 | file_type, ext = string.split(item, "|*.", 1) |
---|
[a67ec83] | 149 | if ext.strip() not in EXCEPTION_LIST and ext.strip() not in extensions: |
---|
| 150 | extensions.append(ext) |
---|
| 151 | except Exception: |
---|
[959eb01] | 152 | pass |
---|
| 153 | |
---|
[a67ec83] | 154 | return extensions |
---|
[959eb01] | 155 | |
---|
| 156 | EXTENSIONS_LIST = find_extension() |
---|
| 157 | |
---|
| 158 | plist = dict(CFBundleDocumentTypes=[dict(CFBundleTypeExtensions=EXTENSIONS_LIST, |
---|
| 159 | CFBundleTypeIconFile=ICON, |
---|
[25a42f99] | 160 | CFBundleTypeName="sasview file", |
---|
| 161 | CFBundleTypeRole="Shell")],) |
---|
[959eb01] | 162 | |
---|
| 163 | #Get version - NB nasty hack. Need to find correct way to give path to installed sasview (AJJ) |
---|
| 164 | #h5py has been added to packages. It requires hdf5 to be installed separetly |
---|
| 165 | # |
---|
| 166 | |
---|
[914ba0a] | 167 | from sas.sasview import __version__ as VERSION |
---|
[959eb01] | 168 | APPNAME = "SasView "+VERSION |
---|
| 169 | DMGNAME = "SasView-"+VERSION+"-MacOSX" |
---|
[914ba0a] | 170 | APP = ['sasview_gui.py'] |
---|
[959eb01] | 171 | |
---|
| 172 | EXCLUDES = ['PyQt4', 'sip', 'QtGui'] |
---|
| 173 | |
---|
| 174 | OPTIONS = {'argv_emulation': True, |
---|
[914ba0a] | 175 | 'packages': ['lxml', 'numpy', 'scipy', 'pytz', 'encodings', |
---|
| 176 | 'encodings', 'matplotlib', 'periodictable', |
---|
| 177 | 'reportlab', 'sasmodels', 'pyopencl', 'h5py', |
---|
| 178 | ], |
---|
[959eb01] | 179 | 'iconfile': ICON, |
---|
[914ba0a] | 180 | 'frameworks': [libxml_path], |
---|
| 181 | 'plist': plist, |
---|
[959eb01] | 182 | 'excludes' : EXCLUDES, |
---|
[914ba0a] | 183 | } |
---|
[92df9cbd] | 184 | |
---|
| 185 | #import pprint; pprint.pprint(data_files); sys.exit() |
---|
[959eb01] | 186 | setup( |
---|
| 187 | name=APPNAME, |
---|
| 188 | app=APP, |
---|
[0046c6a] | 189 | data_files=data_files, |
---|
[914ba0a] | 190 | include_package_data=True, |
---|
[959eb01] | 191 | options={'py2app': OPTIONS}, |
---|
| 192 | setup_requires=['py2app'], |
---|
| 193 | ) |
---|
| 194 | |
---|
| 195 | #Build dmg |
---|
[914ba0a] | 196 | DMG = "dist/%s.dmg"%DMGNAME |
---|
| 197 | if os.path.exists(DMG): |
---|
| 198 | os.unlink(DMG) |
---|
| 199 | os.system('cd dist && ../../build_tools/dmgpack.sh "%s" "%s.app"'%(DMGNAME, APPNAME)) |
---|
[959eb01] | 200 | os.system('chmod a+r "%s"'%DMG) |
---|