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