def relative_to(<EOL>source_path: Union[str, pathlib.Path], target_path: Union[str, pathlib.Path]<EOL>) -> pathlib.Path:
source_path = pathlib.Path(source_path).absolute()<EOL>if source_path.is_file():<EOL><INDENT>source_path = source_path.parent<EOL><DEDENT>target_path = pathlib.Path(target_path).absolute()<EOL>common_prefix = find_common_prefix([source_path, target_path])<EOL>if not common_prefix:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>source_path = source_path.relative_to(common_prefix)<EOL>target_path = target_path.relative_to(common_prefix)<EOL>result = pathlib.Path(*["<STR_LIT:..>"] * len(source_path.parts))<EOL>return result / target_path<EOL>
Generates relative path from ``source_path`` to ``target_path``.

Handles the case of paths without a common prefix.

::

    >>> import pathlib
    >>> source = pathlib.Path('foo/bar/baz')
    >>> target = pathlib.Path('foo/quux/biz')

::

    >>> target.relative_to(source)
    Traceback (most recent call last):
      ...
    ValueError: 'foo/quux/biz' does not start with 'foo/bar/baz'

::

    >>> import uqbar.io
    >>> str(uqbar.io.relative_to(source, target))
    '../../quux/biz'

:param source_path: the source path
:param target_path: the target path