Module setup
[hide private]
[frames] | no frames]

Source Code for Module setup

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011-2012 Edward d'Auvergne                                   # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 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  # Python module import. 
 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  # relax module imports. 
 47  from relax_errors import RelaxError 
 48  from status import Status; status = Status() 
 49  from version import version_full 
 50   
 51   
52 -class Setup:
53 """Class containing setuptools targets for different platforms.""" 54
55 - def __init__(self):
56 """Initialise and execute.""" 57 58 # The extension. 59 extension = sys.argv[1] 60 61 # Mac OS X application. 62 if extension == 'py2app': 63 self.mac_setup() 64 65 # Unsupported platform. 66 else: 67 raise RelaxError("The setuptools extension '%s' is not supported yet." % extension) 68 69 # Generic setup args. 70 self.args_generic() 71 72 # Execute the setuptools setup() method to actually do something. 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
83 - def args_generic(self):
84 """Set up the arguments which are independent of the target.""" 85 86 # Get a list of data files. 87 self.DATA_FILES = self.get_data_files() 88 #for i in range(len(self.DATA_FILES)): 89 # print self.DATA_FILES[i] 90 #sys.exit(1) 91 92 # Get the includes. 93 self.INCLUDES = self.get_includes()
94 #for i in range(len(self.INCLUDES)): 95 # print self.INCLUDES[i] 96 #sys.exit(1) 97 98
99 - def get_data_files(self):
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 # Blacklisted files and directories. 107 blacklist_dir = [ 108 'build', 109 'dist' 110 ] 111 blacklist_files = [ 112 ] 113 114 # All files and directories. 115 data_files = [] 116 cwd = getcwd() 117 for (dirpath, dirnames, filenames) in walk(cwd): 118 # Skip .svn directories. 119 split_path = split(dirpath, sep) 120 if '.svn' in split_path: 121 continue 122 123 # Skip blacklisted directories. 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 # The relative path. 132 rel_path = relpath(dirpath, cwd) 133 134 # Loop over the files. 135 file_list = [] 136 for file in filenames: 137 # Skip names starting with '.'. 138 if search('^\.', file): 139 continue 140 141 # Blacklist. 142 if file in blacklist_files: 143 continue 144 145 # Append the file with path to the list. 146 file_list.append("%s%s%s" % (rel_path, sep, file)) 147 148 # Append a tuple of the destination directory and the files. 149 data_files.append((rel_path, file_list)) 150 151 # Return the data files. 152 return data_files
153 154
155 - def get_includes(self):
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 # Blacklisted files and directories. 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 # All files and directories. 177 includes = [] 178 cwd = getcwd() 179 for (dirpath, dirnames, filenames) in walk(cwd): 180 # Skip .svn directories. 181 split_path = split(dirpath, sep) 182 if '.svn' in split_path: 183 continue 184 185 # The relative path. 186 rel_path = relpath(dirpath, cwd) 187 188 # Skip blacklisted directories. 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 # The module path. 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 # Loop over the files. 205 for file in filenames: 206 # Skip names starting with '.'. 207 if search('^\.', file): 208 continue 209 210 # Skip non-Python source files. 211 if not search('\.py$', file): 212 continue 213 214 # Blacklist. 215 if file in blacklist_files: 216 continue 217 218 # Append a tuple of the destination directory and the file. 219 includes.append("%s%s" % (module_path, file[:-3])) 220 221 # Return the data files. 222 return includes
223 224
225 - def mac_setup(self):
226 """Mac OS X setup.""" 227 228 # The relax settings. 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 # Execute the main class. 251 if __name__ == '__main__': 252 Setup() 253