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

Source Code for Module dep_check

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