def safe_path(path):
  """Return a path that is safe to write to by making intermediate dirs.

  Args:
    path: Path to ensure is safe

  Returns:
    The original path, converted to Text if it was a PurePath
  """
  if isinstance(path, pathlib.PurePath):
    path = str(path)
  directory = os.path.dirname(path)
  tf.io.gfile.makedirs(directory)
  return path
Return a path that is safe to write to by making intermediate dirs.

  Args:
    path: Path to ensure is safe

  Returns:
    The original path, converted to Text if it was a PurePath
  
language/serene/util.py