from typing import Optional


def PathFromLabel(label: str) -> Optional[str]:
  """Create a workspace relative path from a bazel label.

  Args:
  	A bazel label, e.g. "//foo:bar.cc".

  Returns:
  	A workspace-relative path, e.g. "foo/bar.cc". If the label does not resolve
  	to a path, returns None.
  """
  # First, filter only labels from within the current workspace.
  if not label.startswith("//"):
    return
  # Then, strip the leading '//' prefix.
  label = label[2:]
  # Strip the ':' prefix from top-level targets.
  if label.startswith(":"):
    return label[1:]
  # Finally, substitute the ':' target seperator with a '/' path separator.
  chars = list(label)
  chars[label.rfind(":")] = "/"
  return "".join(chars)