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, 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 lib.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 '.git' 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(r'^\.', 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 whitelist_dir = [
180 'test_suite'+sep+'shared_data'+sep+'frame_order'+sep+'cam'
181 ]
182
183
184 includes = []
185 cwd = getcwd()
186 for (dirpath, dirnames, filenames) in walk(cwd):
187
188 split_path = dirpath.split(sep)
189 if '.git' in split_path:
190 continue
191
192
193 rel_path = relpath(dirpath, cwd)
194
195
196 skip = False
197 for dir_name in blacklist_dir:
198 if search(dir_name, rel_path) and rel_path not in whitelist_dir:
199 skip = True
200 if skip:
201 continue
202
203
204 if rel_path == '.':
205 module_path = ''
206 else:
207 module_path = rel_path.replace(sep, '.')
208 if module_path:
209 module_path += '.'
210
211
212 for file in filenames:
213
214 if search(r'^\.', file):
215 continue
216
217
218 if not search(r'\.py$', file):
219 continue
220
221
222 if file in blacklist_files:
223 continue
224
225
226 includes.append("%s%s" % (module_path, file[:-3]))
227
228
229 return includes
230
231
233 """Mac OS X setup."""
234
235
236 self.APP = ['relax_gui_mode.py']
237 self.NAME = 'relax'
238 self.VERSION = version_full()
239 self.OPTIONS = {}
240 self.OPTIONS['py2app'] = {
241 'argv_emulation': False,
242 'iconfile': status.install_path + sep + 'graphics' + sep + 'ulysses_shadowless_trans_128x128.icns',
243 'packages': 'wx',
244 'site_packages': True,
245 'includes': self.get_includes(),
246 'excludes': ['build', 'dist'],
247 'plist': {
248 'CFBundleName': 'relax',
249 'CFBundleShortVersionString': version_full(),
250 'CFBundleGetInfoString': 'relax %s' % version_full(),
251 'CFBundleIdentifier': 'com.nmr-relax.relax'
252 }
253 }
254 self.REQUIRES = ['py2app']
255
256
257
258 if __name__ == '__main__':
259 Setup()
260