def make_relative_path(source, dest, dest_is_directory=True):
source = os.path.dirname(source)<EOL>if not dest_is_directory:<EOL><INDENT>dest_filename = os.path.basename(dest)<EOL>dest = os.path.dirname(dest)<EOL><DEDENT>dest = os.path.normpath(os.path.abspath(dest))<EOL>source = os.path.normpath(os.path.abspath(source))<EOL>dest_parts = dest.strip(os.path.sep).split(os.path.sep)<EOL>source_parts = source.strip(os.path.sep).split(os.path.sep)<EOL>while dest_parts and source_parts and dest_parts[<NUM_LIT:0>] == source_parts[<NUM_LIT:0>]:<EOL><INDENT>dest_parts.pop(<NUM_LIT:0>)<EOL>source_parts.pop(<NUM_LIT:0>)<EOL><DEDENT>full_parts = ['<STR_LIT:..>']*len(source_parts) + dest_parts<EOL>if not dest_is_directory:<EOL><INDENT>full_parts.append(dest_filename)<EOL><DEDENT>if not full_parts:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return os.path.sep.join(full_parts)<EOL>
Make a filename relative, where the filename is dest, and it is
being referred to from the filename source.

    >>> make_relative_path('/usr/share/something/a-file.pth',
    ...                    '/usr/share/another-place/src/Directory')
    '../another-place/src/Directory'
    >>> make_relative_path('/usr/share/something/a-file.pth',
    ...                    '/home/user/src/Directory')
    '../../../home/user/src/Directory'
    >>> make_relative_path('/usr/share/a-file.pth', '/usr/share/')
    './'