1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """This script is used to build relax as an application on certain platforms.
25
26 The Mac OS X component was initially generated by py2applet, but has been highly modified. To use this script to build a Mac app, the following command needs to be run:
27
28 Usage:
29
30 python setup.py py2app
31
32
33 To then create a DMG file for installation, type:
34
35 hdiutil create -fs HFS+ -volname "relax" -srcfolder dist/relax.app relax.dmg
36 """
37
38
39 from os import getcwd, listdir, sep, walk
40 from os.path import relpath, sep
41 from re import search
42 from setuptools import setup
43 from string import replace, split
44 import sys
45
46
47 from relax_errors import RelaxError
48 from status import Status; status = Status()
49 from version import version_full
50
51
53 """Class containing setuptools targets for different platforms."""
54
56 """Initialise and execute."""
57
58
59 extension = sys.argv[1]
60
61
62 if extension == 'py2app':
63 self.mac_setup()
64
65
66 else:
67 raise RelaxError("The setuptools extension '%s' is not supported yet." % extension)
68
69
70 self.args_generic()
71
72
73 setup(
74 app=self.APP,
75 name=self.NAME,
76 version=self.VERSION,
77 data_files=self.DATA_FILES,
78 options=self.OPTIONS,
79 setup_requires=self.REQUIRES
80 )
81
82
84 """Set up the arguments which are independent of the target."""
85
86
87 self.DATA_FILES = self.get_data_files()
88
89
90
91
92
93 self.INCLUDES = self.get_includes()
94
95
96
97
98
100 """Collect and return a list of data files.
101
102 @return: The list of data files as full paths.
103 @rtype: list of str
104 """
105
106
107 blacklist_dir = [
108 'build',
109 'dist'
110 ]
111 blacklist_files = [
112 ]
113
114
115 data_files = []
116 cwd = getcwd()
117 for (dirpath, dirnames, filenames) in walk(cwd):
118
119 split_path = split(dirpath, sep)
120 if '.svn' in split_path:
121 continue
122
123
124 skip = False
125 for dir_name in blacklist_dir:
126 if dir_name in split_path:
127 skip = True
128 if skip:
129 continue
130
131
132 rel_path = relpath(dirpath, cwd)
133
134
135 file_list = []
136 for file in filenames:
137
138 if search('^\.', file):
139 continue
140
141
142 if file in blacklist_files:
143 continue
144
145
146 file_list.append("%s%s%s" % (rel_path, sep, file))
147
148
149 data_files.append((rel_path, file_list))
150
151
152 return data_files
153
154
156 """Collect and return a list of modules to include.
157
158 @return: The list of modules.
159 @rtype: list of str
160 """
161
162
163 blacklist_dir = [
164 'build',
165 'dist',
166 'bmrblib'+sep+'html_dictionary',
167 'graphics',
168 'sample_scripts',
169 'scripts',
170 'test_suite'+sep+'system_tests'+sep+'scripts',
171 'test_suite'+sep+'shared_data'
172 ]
173 blacklist_files = [
174 ]
175
176
177 includes = []
178 cwd = getcwd()
179 for (dirpath, dirnames, filenames) in walk(cwd):
180
181 split_path = split(dirpath, sep)
182 if '.svn' in split_path:
183 continue
184
185
186 rel_path = relpath(dirpath, cwd)
187
188
189 skip = False
190 for dir_name in blacklist_dir:
191 if search(dir_name, rel_path):
192 skip = True
193 if skip:
194 continue
195
196
197 if rel_path == '.':
198 module_path = ''
199 else:
200 module_path = replace(rel_path, sep, '.')
201 if module_path:
202 module_path += '.'
203
204
205 for file in filenames:
206
207 if search('^\.', file):
208 continue
209
210
211 if not search('\.py$', file):
212 continue
213
214
215 if file in blacklist_files:
216 continue
217
218
219 includes.append("%s%s" % (module_path, file[:-3]))
220
221
222 return includes
223
224
226 """Mac OS X setup."""
227
228
229 self.APP = ['relax_gui_mode.py']
230 self.NAME = 'relax'
231 self.VERSION = version_full()
232 self.OPTIONS = {}
233 self.OPTIONS['py2app'] = {
234 'argv_emulation': False,
235 'iconfile': status.install_path + sep + 'graphics' + sep + 'ulysses_shadowless_trans_128x128.icns',
236 'packages': 'wx',
237 'site_packages': True,
238 'includes': self.get_includes(),
239 'excludes': ['build', 'dist'],
240 'plist': {
241 'CFBundleName': 'relax',
242 'CFBundleShortVersionString': version_full(),
243 'CFBundleGetInfoString': 'relax %s' % version_full(),
244 'CFBundleIdentifier': 'com.nmr-relax.relax'
245 }
246 }
247 self.REQUIRES = ['py2app']
248
249
250
251 if __name__ == '__main__':
252 Setup()
253