def find_parents(root, path, names):
if not root:<EOL><INDENT>return []<EOL><DEDENT>if not os.path.commonprefix((root, path)):<EOL><INDENT>log.warning("<STR_LIT>", path, root)<EOL>return []<EOL><DEDENT>dirs = [root] + os.path.relpath(os.path.dirname(path), root).split(os.path.sep)<EOL>while dirs:<EOL><INDENT>search_dir = os.path.join(*dirs)<EOL>existing = list(filter(os.path.exists, [os.path.join(search_dir, n) for n in names]))<EOL>if existing:<EOL><INDENT>return existing<EOL><DEDENT>dirs.pop()<EOL><DEDENT>return []<EOL>
Find files matching the given names relative to the given path.

    Args:
        path (str): The file path to start searching up from.
        names (List[str]): The file/directory names to look for.
        root (str): The directory at which to stop recursing upwards.

    Note:
        The path MUST be within the root.