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

Source Code for Module dep_check

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2008-2015 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, environ, 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 version_comparison(numpy.version.version, '1.6') == -1: 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 if not "DISPLAY" in environ: 137 # Force matplotlib to not use any Xwindows backend. 138 matplotlib.use('Agg') 139 except ImportError: 140 matplotlib_module = False 141 142 # runpy module. 143 try: 144 import runpy 145 runpy_module = True 146 except ImportError: 147 runpy_module = False 148 149 # profile module (python development packages required). 150 try: 151 import profile 152 profile_module = True 153 except ImportError: 154 profile_module = False 155 156 # profile C module (python development packages required). 157 try: 158 import cProfile 159 cprofile_module = True 160 except ImportError: 161 cprofile_module = False 162 163 # BZ2 compression module. 164 try: 165 import bz2 166 bz2_module = True 167 except ImportError: 168 message = sys.exc_info()[1] 169 bz2_module = False 170 bz2_module_message = message.args[0] 171 172 # Gzip compression module. 173 try: 174 import gzip 175 gzip_module = True 176 except ImportError: 177 message = sys.exc_info()[1] 178 gzip_module = False 179 gzip_module_message = message.args[0] 180 181 # IO module. 182 try: 183 import io 184 io_module = True 185 except ImportError: 186 message = sys.exc_info()[1] 187 io_module = False 188 io_module_message = message.args[0] 189 190 # Scipy import. 191 try: 192 import scipy 193 scipy_module = True 194 except: 195 scipy_module = False 196 197 # VMD module imports. 198 try: 199 from Scientific.Visualization import VMD # This requires Numeric to be installed (at least in Scientific 2.7.8). 200 del VMD 201 vmd_module = True 202 except: 203 vmd_module = False 204 205 # mpi4py. 206 try: 207 import mpi4py 208 mpi4py_module = True 209 except ImportError: 210 message = sys.exc_info()[1] 211 mpi4py_module = False 212 213 # The error message. 214 mpi4py_message = """The dependency 'mpi4py' has not been installed. You should either: 215 216 1. Run without multiprocessor support i.e. remove the --multi mpi4py flag from the command line. 217 218 2. Install mpi4py. 219 220 3. Choose another multi processor method to give to the --multi command line flag.\n 221 """ 222 223 # PyMOL. 224 try: 225 import pymol 226 pymol_module = True 227 except ImportError: 228 message = sys.exc_info()[1] 229 pymol_module = False 230 231 # XML. 232 try: 233 import xml 234 xml_module = True 235 except ImportError: 236 message = sys.exc_info()[1] 237 xml_module = False 238 if xml_module: 239 # The XML version mess! 240 if hasattr(xml, '_MINIMUM_XMLPLUS_VERSION'): 241 xml_version = "%s.%s.%s" % xml._MINIMUM_XMLPLUS_VERSION 242 xml_type = 'internal' 243 elif hasattr(xml, '__version__'): 244 xml_version = xml.__version__ 245 xml_type = 'PyXML' 246 else: 247 xml_version = '' 248 xml_type = '' 249 250 # subprocess module. 251 try: 252 import subprocess 253 subprocess_module = True 254 except ImportError: 255 message = sys.exc_info()[1] 256 subprocess_module = False 257 subprocess_module_message = message.args[0] 258 259 # NMRPipe showApod 260 if subprocess_module: 261 try: 262 # Call function. 263 Temp = subprocess.Popen('showApod', stdout=subprocess.PIPE) 264 265 # Communicate with program, and get output and error output. 266 (output, errput) = Temp.communicate() 267 268 # Wait for finish and get return code. 269 return_value = Temp.wait() 270 271 # Split the output into lines. 272 line_split = output.splitlines() 273 274 # The first line, decoding Python 3 byte arrays. 275 line = line_split[0] 276 if hasattr(line, 'decode'): 277 line = line.decode() 278 279 # Now make test. 280 if line == 'showApod: Show Effect of Processing on Noise and Linewidth.': 281 showApod_software = True 282 else: 283 showApod_software = False 284 285 # If software not available. 286 except OSError: 287 showApod_software = False 288 289 # If subprocess module not available, then do not allow showApod. 290 else: 291 showApod_software = False 292 293 # ctypes module. 294 try: 295 import ctypes 296 ctypes_module = True 297 except ImportError: 298 message = sys.exc_info()[1] 299 ctypes_module = False 300 ctypes_module_message = message.args[0] 301 try: 302 from ctypes import Structure 303 ctypes_structure_module = True 304 except ImportError: 305 message = sys.exc_info()[1] 306 ctypes_structure_module = False 307 ctypes_structure_module_message = message.args[0] 308 309 310 311 312 # Compiled C modules. 313 ##################### 314 315 # Relaxation curve fitting. 316 try: 317 from target_functions import relax_fit 318 from target_functions.relax_fit import setup 319 del setup 320 C_module_exp_fn = True 321 except ImportError: 322 # The OS. 323 system = platform.system() 324 325 # Does the compiled file exist. 326 file = 'relax_fit.so' 327 if system == 'Windows' or system == 'Microsoft': 328 file = 'relax_fit.pyd' 329 if not access('target_functions' + sep + file, F_OK): 330 C_module_exp_fn_mesg = "ImportError: relaxation curve fitting is unavailable, the corresponding C modules have not been compiled." 331 332 # Show the full error. 333 else: 334 message = sys.exc_info()[1] 335 C_module_exp_fn_mesg = "ImportError: " + repr(message) + "\nRelaxation curve fitting is unavailable, try compiling the C modules." 336 337 # Set the flag. 338 C_module_exp_fn = False 339