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