r"""
    Retrieve the module name from a module object.

    :param module_obj: Module object
    :type  module_obj: object

    :rtype: string

    :raises:
     * RuntimeError (Argument \`module_obj\` is not valid)

     * RuntimeError (Module object \`*[module_name]*\` could not be found in
       loaded modules)

    For example:

        >>> import pexdoc.pinspect
        >>> pexdoc.pinspect.get_module_name(sys.modules['pexdoc.pinspect'])
        'pexdoc.pinspect'

def get_module_name(module_obj):
    r"""
    Retrieve the module name from a module object.

    :param module_obj: Module object
    :type  module_obj: object

    :rtype: string

    :raises:
     * RuntimeError (Argument \`module_obj\` is not valid)

     * RuntimeError (Module object \`*[module_name]*\` could not be found in
       loaded modules)

    For example:

        >>> import pexdoc.pinspect
        >>> pexdoc.pinspect.get_module_name(sys.modules['pexdoc.pinspect'])
        'pexdoc.pinspect'
    """
    if not is_object_module(module_obj):
        raise RuntimeError("Argument `module_obj` is not valid")
    name = module_obj.__name__
    msg = "Module object `{name}` could not be found in loaded modules"
    if name not in sys.modules:
        raise RuntimeError(msg.format(name=name))
    return name