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

Source Code for Module dep_check

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2010,2012,2014 Edward d'Auvergne                         # 
  4  # Copyright (C) 2009 Sebastien Morin                                          # 
  5  # Copyright (C) 2014 Troels E. Linnet                                         # 
  6  #                                                                             # 
  7  # This file is part of the program relax (http://www.nmr-relax.com).          # 
  8  #                                                                             # 
  9  # This program is free software: you can redistribute it and/or modify        # 
 10  # it under the terms of the GNU General Public License as published by        # 
 11  # the Free Software Foundation, either version 3 of the License, or           # 
 12  # (at your option) any later version.                                         # 
 13  #                                                                             # 
 14  # This program is distributed in the hope that it will be useful,             # 
 15  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 16  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 17  # GNU General Public License for more details.                                # 
 18  #                                                                             # 
 19  # You should have received a copy of the GNU General Public License           # 
 20  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 21  #                                                                             # 
 22  ############################################################################### 
 23   
 24  # Module docstring. 
 25  """Module for checking relax dependencies. 
 26   
 27  If essential dependencies are missing, then an error message is printed and the program terminated. 
 28  """ 
 29   
 30  # Python modules. 
 31  import platform 
 32  from os import F_OK, access, environ, sep 
 33  from re import sub 
 34  import sys 
 35   
 36   
37 -def version_comparison(version1, version2):
38 """Compare software versions. 39 40 This will return: 41 42 - When version 1 is older, -1, 43 - When both versions are equal, 0, 44 - When version 1 is newer, 1. 45 46 47 @param version1: The first version number. 48 @type version1: str 49 @param version2: The second version number. 50 @type version2: str 51 @return: The comparison result of the Python cmp() function applied to two lists of integers. This will be one of [-1, 0, 1]. 52 @rtype: int 53 """ 54 55 # Strip out trailing after release candidate. 56 version1 = sub(r'(rc\d)', '', version1) 57 version2 = sub(r'(rc\d)', '', version2) 58 59 # Strip out trailing zeros. 60 version1 = sub(r'(\.0+)*$', '', version1) 61 version2 = sub(r'(\.0+)*$', '', version2) 62 63 # Convert to a list of numbers. 64 version1 = [int(val) for val in version1.split('.')] 65 version2 = [int(val) for val in version2.split('.')] 66 67 # Return the comparison. 68 return (version1 > version2) - (version1 < version2)
69 70 71 # Essential packages. 72 ##################### 73 74 # numpy. 75 try: 76 import numpy 77 if version_comparison(numpy.version.version, '1.6') == -1: 78 sys.stderr.write("Version %s of the 'numpy' dependency is not supported, numpy >= 1.6 is required.\n" % numpy.version.version) 79 sys.exit(1) 80 except ImportError: 81 sys.stderr.write("The dependency 'numpy' has not been installed.\n") 82 sys.exit(1) 83 84 # Command line option parser. 85 try: 86 import optparse 87 except ImportError: 88 sys.stderr.write("The dependency 'Optik' has not been installed.\n") 89 sys.exit(1) 90 91 # Minfx python package check. 92 try: 93 import minfx 94 min_version = '1.0.11' 95 if not minfx.__version__ == 'trunk' and version_comparison(minfx.__version__, min_version) == -1: 96 sys.stderr.write("Version %s of the 'minfx' dependency is too old, minfx >= %s is required.\n" % (minfx.__version__, min_version)) 97 sys.exit(1) 98 except ImportError: 99 sys.stderr.write("The dependency 'minfx' has not been installed (see https://sourceforge.net/projects/minfx/).\n") 100 sys.exit(1) 101 102 # Optional packages. 103 #################### 104 # Bmrblib python package check. 105 try: 106 import bmrblib 107 bmrblib_module = True 108 except ImportError: 109 bmrblib_module = False 110 111 # wx module. 112 try: 113 import wx 114 wx_module = True 115 except ImportError: 116 wx_module = False 117 message = sys.exc_info()[1] 118 wx_module_message = message.args[0] 119 120 # epydoc module. 121 try: 122 import epydoc 123 epydoc_module = True 124 except ImportError: 125 epydoc_module = False 126 127 # Readline module (avoiding the damned ^[[?1034h escape code on Linux systems). 128 try: 129 import os 130 if 'TERM' in os.environ and os.environ['TERM'] == 'xterm': 131 os.environ['TERM'] = 'linux' 132 import readline 133 readline_module = True 134 except ImportError: 135 readline_module = False 136 137 # matplotlib module. 138 try: 139 import matplotlib 140 matplotlib_module = True 141 if not "DISPLAY" in environ: 142 # Force matplotlib to not use any Xwindows backend. 143 matplotlib.use('Agg') 144 except ImportError: 145 matplotlib_module = False 146 147 # runpy module. 148 try: 149 import runpy 150 runpy_module = True 151 except ImportError: 152 runpy_module = False 153 154 # profile module (python development packages required). 155 try: 156 import profile 157 profile_module = True 158 except ImportError: 159 profile_module = False 160 161 # profile C module (python development packages required). 162 try: 163 import cProfile 164 cprofile_module = True 165 except ImportError: 166 cprofile_module = False 167 168 # BZ2 compression module. 169 try: 170 import bz2 171 bz2_module = True 172 except ImportError: 173 message = sys.exc_info()[1] 174 bz2_module = False 175 bz2_module_message = message.args[0] 176 177 # Gzip compression module. 178 try: 179 import gzip 180 gzip_module = True 181 except ImportError: 182 message = sys.exc_info()[1] 183 gzip_module = False 184 gzip_module_message = message.args[0] 185 186 # IO module. 187 try: 188 import io 189 io_module = True 190 except ImportError: 191 message = sys.exc_info()[1] 192 io_module = False 193 io_module_message = message.args[0] 194 195 # Scipy import. 196 try: 197 import scipy 198 scipy_module = True 199 except: 200 scipy_module = False 201 202 # VMD module imports. 203 try: 204 from Scientific.Visualization import VMD # This requires Numeric to be installed (at least in Scientific 2.7.8). 205 del VMD 206 vmd_module = True 207 except: 208 vmd_module = False 209 210 # mpi4py. 211 try: 212 import mpi4py 213 mpi4py_module = True 214 except ImportError: 215 message = sys.exc_info()[1] 216 mpi4py_module = False 217 218 # The error message. 219 mpi4py_message = """The dependency 'mpi4py' has not been installed. You should either: 220 221 1. Run without multiprocessor support i.e. remove the --multi mpi4py flag from the command line. 222 223 2. Install mpi4py. 224 225 3. Choose another multi processor method to give to the --multi command line flag.\n 226 """ 227 228 # PyMOL. 229 try: 230 import pymol 231 pymol_module = True 232 except ImportError: 233 message = sys.exc_info()[1] 234 pymol_module = False 235 236 # XML. 237 try: 238 import xml 239 xml_module = True 240 except ImportError: 241 message = sys.exc_info()[1] 242 xml_module = False 243 if xml_module: 244 # The XML version mess! 245 if hasattr(xml, '_MINIMUM_XMLPLUS_VERSION'): 246 xml_version = "%s.%s.%s" % xml._MINIMUM_XMLPLUS_VERSION 247 xml_type = 'internal' 248 elif hasattr(xml, '__version__'): 249 xml_version = xml.__version__ 250 xml_type = 'PyXML' 251 else: 252 xml_version = '' 253 xml_type = '' 254 255 # subprocess module. 256 try: 257 import subprocess 258 subprocess_module = True 259 except ImportError: 260 message = sys.exc_info()[1] 261 subprocess_module = False 262 subprocess_module_message = message.args[0] 263 264 # NMRPipe showApod 265 if subprocess_module: 266 try: 267 # Call function. 268 Temp = subprocess.Popen('showApod', stdout=subprocess.PIPE) 269 270 # Communicate with program, and get output and error output. 271 (output, errput) = Temp.communicate() 272 273 # Wait for finish and get return code. 274 return_value = Temp.wait() 275 276 # Split the output into lines. 277 line_split = output.splitlines() 278 279 # The first line, decoding Python 3 byte arrays. 280 line = line_split[0] 281 if hasattr(line, 'decode'): 282 line = line.decode() 283 284 # Now make test. 285 if line == 'showApod: Show Effect of Processing on Noise and Linewidth.': 286 showApod_software = True 287 else: 288 showApod_software = False 289 290 # If software not available. 291 except OSError: 292 showApod_software = False 293 294 # If subprocess module not available, then do not allow showApod. 295 else: 296 showApod_software = False 297 298 # ctypes module. 299 try: 300 import ctypes 301 ctypes_module = True 302 except ImportError: 303 message = sys.exc_info()[1] 304 ctypes_module = False 305 ctypes_module_message = message.args[0] 306 try: 307 from ctypes import Structure 308 ctypes_structure_module = True 309 except ImportError: 310 message = sys.exc_info()[1] 311 ctypes_structure_module = False 312 ctypes_structure_module_message = message.args[0] 313 314 315 316 317 # Compiled C modules. 318 ##################### 319 320 # Relaxation curve fitting. 321 try: 322 from target_functions import relax_fit 323 from target_functions.relax_fit import setup 324 del setup 325 C_module_exp_fn = True 326 except ImportError: 327 # The OS. 328 system = platform.system() 329 330 # Does the compiled file exist. 331 file = 'relax_fit.so' 332 if system == 'Windows' or system == 'Microsoft': 333 file = 'relax_fit.pyd' 334 if not access('target_functions' + sep + file, F_OK): 335 C_module_exp_fn_mesg = "ImportError: relaxation curve fitting is unavailable, the corresponding C modules have not been compiled." 336 337 # Show the full error. 338 else: 339 message = sys.exc_info()[1] 340 C_module_exp_fn_mesg = "ImportError: " + repr(message) + "\nRelaxation curve fitting is unavailable, try compiling the C modules." 341 342 # Set the flag. 343 C_module_exp_fn = False 344