def path_to_module(path: str):
    """
    Try to figure out the module a path would import into

    >>> path_to_module("foo/bar.py")
    "foo.bar"
    >>> path_to_module("foo/__init__.py")
    "foo"
    """
    if path[-3:] != '.py':
        raise ValueError("Not a python module path ", path)
    path_minus_py = path[:-3]
    path_w_dots = path_minus_py.replace("/", ".")
    # strip leading docs
    if path_w_dots[0] == '.':
        path_w_dots = path_w_dots[1:]
    # if there was an __init__ then strip that
    if path_w_dots[-9:] == ".__init__":
        path_w_dots = path_w_dots[:-9]
    return path_w_dots