def split_modpath(modpath, check=True):
if six.PY2:<EOL><INDENT>if modpath.endswith('<STR_LIT>'):<EOL><INDENT>modpath = modpath[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>modpath_ = abspath(expanduser(modpath))<EOL>if check:<EOL><INDENT>if not exists(modpath_):<EOL><INDENT>if not exists(modpath):<EOL><INDENT>raise ValueError('<STR_LIT>'.format(modpath))<EOL><DEDENT>raise ValueError('<STR_LIT>'.format(modpath))<EOL><DEDENT>if isdir(modpath_) and not exists(join(modpath, '<STR_LIT>')):<EOL><INDENT>raise ValueError('<STR_LIT>'.format(modpath))<EOL><DEDENT><DEDENT>full_dpath, fname_ext = split(modpath_)<EOL>_relmod_parts = [fname_ext]<EOL>dpath = full_dpath<EOL>while exists(join(dpath, '<STR_LIT>')):<EOL><INDENT>dpath, dname = split(dpath)<EOL>_relmod_parts.append(dname)<EOL><DEDENT>relmod_parts = _relmod_parts[::-<NUM_LIT:1>]<EOL>rel_modpath = os.path.sep.join(relmod_parts)<EOL>return dpath, rel_modpath<EOL>
Splits the modpath into the dir that must be in PYTHONPATH for the module
to be imported and the modulepath relative to this directory.

Args:
    modpath (str): module filepath
    check (bool): if False, does not raise an error if modpath is a
        directory and does not contain an `__init__.py` file.

Returns:
    tuple: (directory, rel_modpath)

Raises:
    ValueError: if modpath does not exist or is not a package

Example:
    >>> from xdoctest import static_analysis
    >>> modpath = static_analysis.__file__.replace('.pyc', '.py')
    >>> modpath = abspath(modpath)
    >>> dpath, rel_modpath = split_modpath(modpath)
    >>> recon = join(dpath, rel_modpath)
    >>> assert recon == modpath
    >>> assert rel_modpath == join('xdoctest', 'static_analysis.py')