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