Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3209a77

Browse files
committed
Yet another iteration on the version checking in backend_wx
svn path=/trunk/matplotlib/; revision=7256
1 parent c8bbe29 commit 3209a77

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

lib/matplotlib/backends/backend_wx.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,31 @@
116116
raise ImportError(missingwx)
117117

118118
# Some early versions of wxversion lack AlreadyImportedError.
119-
if hasattr(wxversion, 'AlreadyImportedError'):
120-
try:
121-
wxversion.ensureMinimal('2.8')
122-
except wxversion.AlreadyImportedError:
123-
pass
124-
else:
125-
warnings.warn(
126-
"Update your wxversion.py to one including AlreadyImportedError")
127-
try:
128-
wxversion.ensureMinimal('2.8')
129-
except wxversion.VersionError:
130-
pass
119+
# It was added around 2.8.4?
120+
try:
121+
_wx_ensure_failed = wxversion.AlreadyImportedError
122+
except AttributeError:
123+
_wx_ensure_failed = wxversion.VersionError
124+
125+
try:
126+
wxversion.ensureMinimal('2.8')
127+
except _wx_ensure_failed:
128+
pass
129+
# We don't really want to pass in case of VersionError, but when
130+
# AlreadyImportedError is not available, we have to.
131131

132132
try:
133133
import wx
134134
backend_version = wx.VERSION_STRING
135135
except ImportError:
136136
raise ImportError(missingwx)
137137

138-
# Extra version check in case wxversion is broken:
138+
# Extra version check in case wxversion lacks AlreadyImportedError;
139+
# then VersionError might have been raised and ignored when
140+
# there really *is* a problem with the version.
139141
major, minor = [int(n) for n in backend_version.split('.')[:2]]
140142
if major < 2 or (major < 3 and minor < 8):
143+
print " wxPython version %s was imported." % backend_version
141144
raise ImportError(missingwx)
142145

143146

0 commit comments

Comments
 (0)