def get_version_string(module_str):
    """Returns the version string found in the top-level module.

    ``module_str`` should be a valid Python module name. __version__ will be
    extracted from the top-level module and returned.

    For example, if ``module_str`` is 'foo.bar.baz', ``foo.__version__`` will
    be returned. If ``__version__`` doesn't exist, a
    ``MissingVersionInfoError`` is raised.
    """
    top_level_name = module_str.split('.')[0]

    try:
        top_level_module = importlib.import_module(top_level_name)
    except ImportError:
        raise ImportError("Unable to import module '%s'" % top_level_name)

    try:
        version_string = top_level_module.__version__
    except AttributeError:
        raise MissingVersionInfoError("Module '%s' does not have the "
                "__version__ attribute." % top_level_name)

    return version_string
dataset/ETHPy150Open biocore/pyqi/pyqi/util.py/get_version_string/original