r"""
    Returns path to module

    Args:
        modname (str or module): module name or actual module

    Returns:
        str: module_dir

    CommandLine:
        python -m utool.util_path --test-get_modpath

    Setup:
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> utool_dir = dirname(dirname(ut.__file__))

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> utool_dir = dirname(dirname(ut.__file__))
        >>> modname = 'utool.util_path'
        >>> module_dir = get_modpath(modname)
        >>> result = ut.truepath_relative(module_dir, utool_dir)
        >>> result = ut.ensure_unixslash(result)
        >>> print(result)
        utool/util_path.py

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> utool_dir = dirname(dirname(ut.__file__))
        >>> modname = 'utool._internal'
        >>> module_dir = get_modpath(modname, prefer_pkg=True)
        >>> result = ut.ensure_unixslash(module_dir)
        >>> print(result)
        >>> assert result.endswith('utool/_internal')

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> utool_dir = dirname(dirname(ut.__file__))
        >>> modname = 'utool'
        >>> module_dir = get_modpath(modname)
        >>> result = ut.truepath_relative(module_dir, utool_dir)
        >>> result = ut.ensure_unixslash(result)
        >>> print(result)
        utool/__init__.py

def get_modpath(modname, prefer_pkg=False, prefer_main=False):
    r"""
    Returns path to module

    Args:
        modname (str or module): module name or actual module

    Returns:
        str: module_dir

    CommandLine:
        python -m utool.util_path --test-get_modpath

    Setup:
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> utool_dir = dirname(dirname(ut.__file__))

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> utool_dir = dirname(dirname(ut.__file__))
        >>> modname = 'utool.util_path'
        >>> module_dir = get_modpath(modname)
        >>> result = ut.truepath_relative(module_dir, utool_dir)
        >>> result = ut.ensure_unixslash(result)
        >>> print(result)
        utool/util_path.py

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> utool_dir = dirname(dirname(ut.__file__))
        >>> modname = 'utool._internal'
        >>> module_dir = get_modpath(modname, prefer_pkg=True)
        >>> result = ut.ensure_unixslash(module_dir)
        >>> print(result)
        >>> assert result.endswith('utool/_internal')

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_path import *  # NOQA
        >>> import utool as ut
        >>> utool_dir = dirname(dirname(ut.__file__))
        >>> modname = 'utool'
        >>> module_dir = get_modpath(modname)
        >>> result = ut.truepath_relative(module_dir, utool_dir)
        >>> result = ut.ensure_unixslash(result)
        >>> print(result)
        utool/__init__.py
    """
    import importlib
    if isinstance(modname, six.string_types):
        module = importlib.import_module(modname)
    else:
        module = modname  # Hack
    modpath = module.__file__.replace('.pyc', '.py')
    initname = '__init__.py'
    mainname = '__main__.py'
    if prefer_pkg:
        if modpath.endswith(initname) or modpath.endswith(mainname):
            modpath = dirname(modpath)
            # modpath = modpath[:-len(initname)]
    if prefer_main:
        if modpath.endswith(initname):
            main_modpath = modpath[:-len(initname)] + mainname
            if exists(main_modpath):
                modpath = main_modpath
    #modname = modname.replace('.__init__', '').strip()
    #module_dir = get_module_dir(module)
    return modpath