check.py 6.8 KB
Newer Older
Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
1
2
3
#!/usr/bin/env python
# coding=utf-8
"""
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
.. .......................................................................... ..
..          ARIA -- Ambiguous Restraints for Iterative Assignment             ..
..                                                                            ..
..                A software for automated NOE assignment                     ..
..                                                                            ..
..                               Version 2.3                                  ..
..                                                                            ..
..                                                                            ..
.. Copyright (C) Benjamin Bardiaux                                            ..
..               Structural Bioinformatics, Institut Pasteur, Paris           ..
..                                                                            ..
.. All rights reserved.                                                       ..
..                                                                            ..
.. NO WARRANTY. This software package is provided 'as is' without warranty of ..
.. any kind, expressed or implied, including, but not limited to the implied  ..
.. warranties of merchantability and fitness for a particular purpose or      ..
.. a warranty of non-infringement.                                            ..
..                                                                            ..
.. Distribution of substantively modified versions of this module is          ..
.. prohibited without the explicit permission of the copyright holders.       ..
..                                                                            ..
.. $Author: bardiaux $                                                        ..
.. $Revision: 1.1.1.1 $                                                       ..
.. $Date: 2010/03/23 15:27:24 $                                               ..
.. .......................................................................... ..
Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
29
30
31
32
33
34
35
36
37
38
39
40
"""


import sys
from string import join
from distutils.version import LooseVersion

NUMPY_MIN_VERSION = LooseVersion('1.1')
PYLAB_NUMPY_MIN_VERSION = LooseVersion('1.1')
SCIPY_NUMPY_MIN_VERSION = LooseVersion('2.7.2')
CCPN_MIN_VERSION = LooseVersion('2.2')

Fabrice Allain's avatar
Fabrice Allain committed
41

Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
def check_python():

    print 'Python version   ',
    
    version = float(sys.version[:3])
    
    if version < 2.4:
        print 'Python version 2.4 or higher required.'
        print 'Current version is', sys.version[:5]
    else:
        print 'ok.'

def check_numeric():

    print 'Numpy module   ', 

    msg = ""
    failed = 0
    
    try:
       import numpy
       version = LooseVersion(numpy.__version__)

       if version >= NUMPY_MIN_VERSION:
           msg =  'ok (numpy)'
           print msg
           return 'numpy'
       
       else:
           msg += 'version > %s required for Numpy' % str(NUMPY_MIN_VERSION)
           
    except:        
        msg += 'could not import Numpy module.'

    print msg
    return None

def check_numeric_slice():

    # BARDIAUX
    msg_NUMERIC = "\nThe version of Numeric (%s) is known to be incompatible with ARIA.\nConsider reverting to a more stable version (like 23.8).\n"
    msg_NUMPY   = "\nThe version of numpy (%s) is known to be incompatible with ARIA.\nConsider reverting to a more stable version.\n"
    
    msg = {'numpy'   : msg_NUMPY,
           'numeric' : msg_NUMERIC}
    
    numerix = 'numpy'
    
    try:
        from numpy import ones
        from numpy import __version__ as NUMERIC_VERSION        
    except:
	print "No numpy found."
    
    if not len(ones(10)[2:]):
        print msg[numerix] % NUMERIC_VERSION

## def check_numeric_slice():

##     msg = "\nWARNING: This version of Numeric (%s) is known to be incompatible with ARIA.\nConsider reverting to a more stable version (like 23.8).\n"
    
##     from Numeric import ones, __version__ as NUMERIC_VERSION
##     if not ones(10)[2:]:
##         print msg % NUMERIC_VERSION
    
    
def check_tix():

    print 'Tkinter and Tix modules...'

    failed_modules = []

    try:
        import Tkinter
        print 'Tkinter imported (Tk version %.3f)' % Tkinter.TkVersion
    except:
        failed_modules.append('Tkinter')
        
    try:
        import _tkinter
    except:
        failed_modules.append('_tkinter')
        
    try:
        import Tix
        Tix.Tk()
        print 'Tix imported.'
    except:
        failed_modules.append('Tix')

    if len(failed_modules):
        print 'could not import module(s) ' + join(failed_modules, '/')

def check_scientific():

    print 'ScientificPython module   ', 
    result = 0
    try:
        import Scientific.IO.PDB
        print 'ok.'
        result = 1
    except:
        print 'could not import ScientificPython module.'

    return result

def check_pylab():

    print 'Matplotlib (optional):', 
    result = 0
    try:
        import matplotlib.pylab
        print 'ok.'
        result = 1
    except:
        print 'could not import Matplotlib module.'

    return result

def check_ccpn():

    print '\nCCPN distribution:',

    missing = []

    try:
        import ccpnmr
        #from memops.general.Constants import currentModelVersion
        from ccpnmr.analysis.Version import version
        ccpn_version = LooseVersion(str(version))
        if ccpn_version < CCPN_MIN_VERSION:
            print ' failed.'
            print 'CCPN Analysis version >= 2.2 required (current version %s).' % ccpn_version
            return 
        else:
            print 'ok.'
    except:
        missing.append('ccpnmr')
        print
        
    try:
        import ccpnmr.format
        print 'CCPN Format converter: ok.'
    except:
        missing.append('ccpnmr.format')

    try:
        import ccpnmr.analysis
        print 'CCPN Anaysis: ok.'
    except:
        missing.append('ccpnmr.analysis')
    
    if missing:
        print 'Could not import the following modules:',
        print ', '.join(missing)
        print 'This does not matter, as long as you do not intend to use the CCPN data model. Otherwise, please make sure that the environment variables CCPNMR_TOP_DIR and PYTHONPATH are set correctly.'


if __name__ == '__main__':

    print 'Checking Python environment...\n'

    check_python()
    numeric = check_numeric()
    check_numeric_slice()
    #scientific = check_scientific()
    scientific = 1
    check_tix()
    check_ccpn()
    pylab = check_pylab()
    

    # some infos
    if not scientific or not pylab:
        if numeric == 'numpy':
            print "\nNOTE:"
            if not scientific:
                print 'Using ScientificPython with Numpy requires version >= %s of ScientificPython' % str(SCIPY_NUMPY_MIN_VERSION)
            if not pylab:
                print 'Using Matplotlib with Numpy requires version >= %s of Matplotlib' % str(PYLAB_NUMPY_MIN_VERSION)