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