@@ -49,14 +49,22 @@ def resolve_name(name):
4949 If the module or named object is not found.
5050 """
5151
52- parts = name .split ('.' )
53- cursor = len (parts ) - 1
52+ # Note: On python 2 these must be str objects and not unicode
53+ parts = [str (part ) for part in name .split ('.' )]
54+
55+ if len (parts ) == 1 :
56+ # No dots in the name--just a straight up module import
57+ cursor = 1
58+ attr_name = str ('' ) # Must not be unicode on Python 2
59+ else :
60+ cursor = len (parts ) - 1
61+ attr_name = parts [- 1 ]
62+
5463 module_name = parts [:cursor ]
55- attr_name = parts [- 1 ]
5664
5765 while cursor > 0 :
5866 try :
59- ret = __import__ ('.' .join (module_name ), fromlist = [attr_name ])
67+ ret = __import__ (str ( '.' .join (module_name ) ), fromlist = [attr_name ])
6068 break
6169 except ImportError :
6270 if cursor == 0 :
@@ -87,8 +95,10 @@ def minversion(module, version, inclusive=True, version_path='__version__'):
8795 Parameters
8896 ----------
8997
90- module : module
91- An imported module of which to check the version.
98+ module : module or `str`
99+ An imported module of which to check the version, or the name of
100+ that module (in which case an import of that module is attempted--
101+ if this fails `False` is returned).
92102
93103 version : `str`
94104 The version as a string that this module must have at a minimum (e.g.
@@ -111,6 +121,19 @@ def minversion(module, version, inclusive=True, version_path='__version__'):
111121 True
112122 """
113123
124+ if isinstance (module , types .ModuleType ):
125+ module_name = module .__name__
126+ elif isinstance (module , six .string_types ):
127+ module_name = module
128+ try :
129+ module = resolve_name (module_name )
130+ except ImportError :
131+ return False
132+ else :
133+ raise ValueError ('module argument must be an actual imported '
134+ 'module, or the import name of the module; '
135+ 'got {0!r}' .format (module ))
136+
114137 if '.' not in version_path :
115138 have_version = getattr (module , version_path )
116139 else :
0 commit comments