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