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