def relpath_to_modname(relpath):
    """Convert relative path to module name

    Within a project, a path to the source file is uniquely identified with a
    module name. Relative paths of the form 'foo/bar' are *not* converted to
    module names 'foo.bar', because (1) they identify directories, not regular
    files, and (2) already 'foo/bar/__init__.py' would claim that conversion.

    Args:
        relpath (str): Relative path from some location on sys.path

    Example:
        >>> relpath_to_modname('ballet/util/_util.py')
        'ballet.util._util'
    """
    # don't try to resolve!
    p = pathlib.Path(relpath)

    if p.name == '__init__.py':
        p = p.parent
    elif p.suffix == '.py':
        p = p.with_suffix('')
    else:
        msg = 'Cannot convert a non-python file to a modname'
        msg_detail = 'The relpath given is: {}'.format(relpath)
        logger.error(msg + '\n' + msg_detail)
        raise ValueError(msg)

    return '.'.join(p.parts)
def relpath_to_modname ( relpath ) : p = pathlib . Path ( relpath ) if p . name == '__init__.py' : p = p . parent elif p . suffix == '.py' : p = p . with_suffix ( '' ) else : msg = 'Cannot convert a non-python file to a modname' msg_detail = 'The relpath given is: {}' . format ( relpath ) logger . error ( msg + '\n' + msg_detail ) raise ValueError ( msg ) return '.' . join ( p . parts )
Convert relative path to module name

    Within a project, a path to the source file is uniquely identified with a
    module name. Relative paths of the form 'foo/bar' are *not* converted to
    module names 'foo.bar', because (1) they identify directories, not regular
    files, and (2) already 'foo/bar/__init__.py' would claim that conversion.

    Args:
        relpath (str): Relative path from some location on sys.path

    Example:
        >>> relpath_to_modname('ballet/util/_util.py')
        'ballet.util._util'