import pathlib
import inspect


def get_module_basename(path):
    """
    Get the module name of the module defined in source ``path``.
    """
    path = pathlib.Path(path)
    module_name = inspect.getmodulename(str(path))
    # This is either garbage or a package
    if module_name is None:
        module_name = path.name
    return module_name