def find_matching_symlink(path, source):
def to_abs(target):<EOL><INDENT>if os.path.isabs(target):<EOL><INDENT>return target<EOL><DEDENT>else:<EOL><INDENT>return os.path.normpath(os.path.join(path, target))<EOL><DEDENT><DEDENT>abs_source = to_abs(source)<EOL>for name in os.listdir(path):<EOL><INDENT>linkpath = os.path.join(path, name)<EOL>if os.path.islink:<EOL><INDENT>source_ = os.readlink(linkpath)<EOL>if to_abs(source_) == abs_source:<EOL><INDENT>return name<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>
Find a symlink under `path` that points at `source`.

    If source is relative, it is considered relative to `path`.

    Returns:
        str: Name of symlink found, or None.