def get_module_version(cls):
"""
Return the string version of the imported module, without any prefix/suffix.
This method handles the common case where a module (or one of its parents)
defines a __version__ string. For other cases, subclasses should override
this method and return the version string.
"""
if cls.module:
module = cls.module
while True:
if isinstance(getattr(module, '__version__', None), str):
return module.__version__
if hasattr(module, '__package__'):
try:
module = importlib.import_module(module.__package__)
except ImportError:
return None
else:
return None
评论列表
文章目录