1
2
3
4
5
6
7
8
9 """Helper to verify presence of external libraries and modules
10 """
11
12 __docformat__ = 'restructuredtext'
13
14 from mvpa.misc import warning
15
16 if __debug__:
17 from mvpa.misc import debug
18
20 """Check if version of shogun is high enough (or custom known) to
21 be enabled in the testsuite"""
22 import shogun.Classifier as __sc
23 ver = __sc.Version_get_version_revision()
24 if (ver in custom_versions) or (ver >= bottom_version) :
25 return True
26 else:
27 raise ImportError, 'Version %s is smaller than needed %s' % \
28 (ver, bottom_version)
29
30
31
32 _KNOWN = {'libsvm':'import mvpa.clfs.libsvm._svm as __; x=__.convert2SVMNode',
33 'shogun':'import shogun as __',
34 'shogun.lightsvm': 'import shogun.Classifier as __; x=__.SVMLight',
35 'shogun.svrlight': 'from shogun.Regression import SVRLight as __',
36 'rpy': "import rpy",
37 'lars': "import rpy; rpy.r.library('lars')",
38 'pylab': "import pylab as __",
39 'sg_fixedcachesize': "__check_shogun(3043)",
40 }
41
42 _VERIFIED = {}
43
44 _caught_exceptions = [ImportError, AttributeError]
45 """Exceptions which are silently caught while running tests for externals"""
46 try:
47 import rpy
48 _caught_exceptions += [rpy.RException]
49 except:
50 pass
51
53 """
54 Test whether a known dependency is installed on the system.
55
56 This method allows us to test for individual dependencies without
57 testing all known dependencies. It also ensures that we only test
58 for a dependency once.
59
60 :Parameters:
61 dep : string
62 The dependency key to test.
63 force : boolean
64 Whether to force the test even if it has already been
65 performed.
66
67 """
68 if _VERIFIED.has_key(dep) and not force:
69
70 return _VERIFIED[dep]
71 elif not _KNOWN.has_key(dep):
72 warning("%s is not a known dependency key." % (dep))
73 return False
74 else:
75
76
77 _VERIFIED[dep] = False
78
79 if __debug__:
80 debug('EXT', "Checking for the presence of %s" % dep)
81
82 try:
83 exec _KNOWN[dep]
84 _VERIFIED[dep] = True
85 except tuple(_caught_exceptions):
86 pass
87
88 if __debug__:
89 debug('EXT', "Presence of %s is%s verified" %
90 (dep, {True:'', False:' NOT'}[_VERIFIED[dep]]))
91
92 return _VERIFIED[dep]
93
94
96 """
97 Test for all known dependencies.
98
99 :Parameters:
100 force : boolean
101 Whether to force the test even if it has already been
102 performed.
103
104 """
105
106 for dep in _KNOWN:
107 if not exists(dep, force):
108 warning("Known dependency %s is not present, thus not available." \
109 % dep)
110
111 if __debug__:
112 debug('EXT', 'The following optional externals are present: %s' \
113 % [ k for k in _VERIFIED.keys() if _VERIFIED[k]])
114