def get_module_name(distribution):
    """Determines the module name to import from the given distribution.

    If an entry point named ``scan`` is found in the group ``morepath``,
    it's value is used. If not, the project_name is used.

    See :func:`morepath.autoscan` for details and an example.
    """
    if hasattr(distribution, "get_entry_map"):
        entry_points = distribution.get_entry_map("morepath")
    else:
        entry_points = None

    if entry_points and "scan" in entry_points:
        return entry_points["scan"].module_name
    # use normal setuptools project name.
    # setuptools has the nasty habit to turn _ in package names
    # into -. We turn them back again.
    return distribution.project_name.replace("-", "_")