def _find_longest_parent_path(path_set, path):
  """Finds the longest "parent-path" of 'path' in 'path_set'.

  This function takes and returns "path-like" strings which are strings
  made of strings separated by os.sep. No file access is performed here, so
  these strings need not correspond to actual files in some file-system..
  This function returns the longest ancestor path
  For example, for path_set=["/foo/bar", "/foo", "/bar/foo"] and
  path="/foo/bar/sub_dir", returns "/foo/bar".

  Args:
    path_set: set of path-like strings -- e.g. a list of strings separated by
      os.sep. No actual disk-access is performed here, so these need not
      correspond to actual files.
    path: a path-like string.

  Returns:
    The element in path_set which is the longest parent directory of 'path'.
  """
  # This could likely be more efficiently implemented with a trie
  # data-structure, but we don't want to add an extra dependency for that.
  while path not in path_set:
    if not path:
      return None
    path = os.path.dirname(path)
  return path
Finds the longest "parent-path" of 'path' in 'path_set'.

  This function takes and returns "path-like" strings which are strings
  made of strings separated by os.sep. No file access is performed here, so
  these strings need not correspond to actual files in some file-system..
  This function returns the longest ancestor path
  For example, for path_set=["/foo/bar", "/foo", "/bar/foo"] and
  path="/foo/bar/sub_dir", returns "/foo/bar".

  Args:
    path_set: set of path-like strings -- e.g. a list of strings separated by
      os.sep. No actual disk-access is performed here, so these need not
      correspond to actual files.
    path: a path-like string.

  Returns:
    The element in path_set which is the longest parent directory of 'path'.