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