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 | import macholib_patch |
---|
27 | |
---|
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 |
---|
32 | root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
---|
33 | platform = '%s-%s'%(get_platform(), sys.version[:3]) |
---|
34 | doc_path = os.path.join(root, 'build', 'lib.'+platform, 'doc') |
---|
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) |
---|
38 | |
---|
39 | #Extending recursion limit |
---|
40 | sys.setrecursionlimit(10000) |
---|
41 | |
---|
42 | from sas.sasview import local_config |
---|
43 | |
---|
44 | ICON = local_config.SetupIconFile_mac |
---|
45 | data_files = [] |
---|
46 | |
---|
47 | # Include data for supporting packages |
---|
48 | import periodictable |
---|
49 | data_files += periodictable.data_files() |
---|
50 | |
---|
51 | import sasmodels |
---|
52 | data_files += sasmodels.data_files() |
---|
53 | |
---|
54 | # Data files for the different perspectives |
---|
55 | from sas.sasgui.perspectives import fitting |
---|
56 | data_files += fitting.data_files() |
---|
57 | |
---|
58 | from sas.sasgui.perspectives import calculator |
---|
59 | data_files += calculator.data_files() |
---|
60 | |
---|
61 | from sas.sasgui.perspectives import invariant |
---|
62 | data_files += invariant.data_files() |
---|
63 | |
---|
64 | from sas.sasgui import guiframe |
---|
65 | data_files += guiframe.data_files() |
---|
66 | |
---|
67 | # Copy the config files |
---|
68 | sasview_path = os.path.join('..', 'src', 'sas', 'sasview') |
---|
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')])) |
---|
72 | |
---|
73 | # Copy the logging config |
---|
74 | sas_path = os.path.join('..', 'src', 'sas') |
---|
75 | data_files.append(('.', [os.path.join(sas_path, 'logging.ini')])) |
---|
76 | |
---|
77 | if os.path.isfile("BUILD_NUMBER"): |
---|
78 | data_files.append(('.', ["BUILD_NUMBER"])) |
---|
79 | |
---|
80 | # Copying the images directory to the distribution directory. |
---|
81 | images_dir = local_config.icon_path |
---|
82 | for f in findall(images_dir): |
---|
83 | data_files.append(("images", [f])) |
---|
84 | |
---|
85 | # Copying the HTML help docs |
---|
86 | media_dir = local_config.media_path |
---|
87 | for f in findall(media_dir): |
---|
88 | data_files.append(("media", [f])) |
---|
89 | |
---|
90 | # Copying the sample data user data |
---|
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])) |
---|
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)) |
---|
106 | data_files.append((sub_dir, [os.path.join(dirpath, filename)])) |
---|
107 | else: |
---|
108 | raise Exception("You must first build the documentation before creating an installer.") |
---|
109 | |
---|
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 | |
---|
126 | # locate file extensions |
---|
127 | def find_extension(): |
---|
128 | """ |
---|
129 | Describe the extensions that can be read by the current application |
---|
130 | """ |
---|
131 | try: |
---|
132 | extensions = [] |
---|
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) |
---|
139 | if ext.strip() not in EXCEPTION_LIST and ext.strip() not in extensions: |
---|
140 | extensions.append(ext) |
---|
141 | except Exception: |
---|
142 | pass |
---|
143 | try: |
---|
144 | file_type, ext = string.split(local_config.APPLICATION_WLIST, "|*.", 1) |
---|
145 | if ext.strip() not in EXCEPTION_LIST and ext.strip() not in extensions: |
---|
146 | extensions.append(ext) |
---|
147 | except Exception: |
---|
148 | pass |
---|
149 | try: |
---|
150 | for item in local_config.PLUGINS_WLIST: |
---|
151 | file_type, ext = string.split(item, "|*.", 1) |
---|
152 | if ext.strip() not in EXCEPTION_LIST and ext.strip() not in extensions: |
---|
153 | extensions.append(ext) |
---|
154 | except Exception: |
---|
155 | pass |
---|
156 | |
---|
157 | return extensions |
---|
158 | |
---|
159 | EXTENSIONS_LIST = find_extension() |
---|
160 | |
---|
161 | plist = dict(CFBundleDocumentTypes=[dict(CFBundleTypeExtensions=EXTENSIONS_LIST, |
---|
162 | CFBundleTypeIconFile=ICON, |
---|
163 | CFBundleTypeName="sasview file", |
---|
164 | CFBundleTypeRole="Shell")],) |
---|
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 | |
---|
170 | from sas.sasview import __version__ as VERSION |
---|
171 | APPNAME = "SasView "+VERSION |
---|
172 | DMGNAME = "SasView-"+VERSION+"-MacOSX" |
---|
173 | APP = ['sasview_gui.py'] |
---|
174 | |
---|
175 | EXCLUDES = ['PyQt4', 'sip', 'QtGui'] |
---|
176 | |
---|
177 | OPTIONS = {'argv_emulation': True, |
---|
178 | 'packages': ['lxml', 'numpy', 'scipy', 'pytz', 'encodings', |
---|
179 | 'encodings', 'matplotlib', 'periodictable', |
---|
180 | 'reportlab', 'sasmodels', 'pyopencl', 'h5py', |
---|
181 | ], |
---|
182 | 'iconfile': ICON, |
---|
183 | 'frameworks': [libxml_path], |
---|
184 | 'resources': [], |
---|
185 | 'plist': plist, |
---|
186 | 'excludes' : EXCLUDES, |
---|
187 | } |
---|
188 | setup( |
---|
189 | name=APPNAME, |
---|
190 | app=APP, |
---|
191 | data_files=data_files, |
---|
192 | include_package_data=True, |
---|
193 | options={'py2app': OPTIONS}, |
---|
194 | setup_requires=['py2app'], |
---|
195 | ) |
---|
196 | |
---|
197 | #Build dmg |
---|
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)) |
---|
202 | os.system('chmod a+r "%s"'%DMG) |
---|