def relative_to(path, target):
    """Return the relative path of the input to the target path.

    For example:
        path = /a/b/d/c/Y
        target = /a/b/c/X
    Then this function will return:
        '../../c/X'

    Args:
        path (pathlib.Path):
        target (pathlib.Path):

    Returns:
        str: the path of 'path' relative to 'target'.
    """
    #   we step back through 'path' until the parent directory matches a
    #   parent directory of 'target'. We then construct the return by
    #   adding N (../) paths for the N steps back and then appending the
    #   path in 'target' that was not matched in the comparison.
    for n, p in enumerate(path.parents):
        try:
            q = target.relative_to(p)
        except ValueError:
            continue
        return "../" * n + str(q)
    return str(target)