code: def check_stage_exists(
      repo: "Repo", stage: Union["Stage", "PipelineStage"], path: str
  ):
      from dvc.dvcfile import load_file
      from dvc.stage import PipelineStage
      from dvc.stage.exceptions import (
          DuplicateStageName,
          StageFileAlreadyExistsError,
      )
  
      dvcfile = load_file(repo, path)
      if not dvcfile.exists():
          return
  
      hint = "Use '--force' to overwrite."
      if not isinstance(stage, PipelineStage):
          raise StageFileAlreadyExistsError(
              f"'{stage.relpath}' already exists. {hint}"
          )
      if stage.name and stage.name in dvcfile.stages:
          raise DuplicateStageName(
              f"Stage '{stage.name}' already exists in '{stage.relpath}'. {hint}"
          )
  
imports: import os
  import pathlib
  from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union
  from funcy import concat, first, lsplit, rpartial
  from dvc.annotations import ANNOTATION_FIELDS
  from dvc.exceptions import InvalidArgumentError
  from dvc_data.hashfile.meta import Meta
  from .exceptions import MissingDataSource, StageExternalOutputsError, StagePathNotDirectoryError, StagePathNotFoundError, StagePathOutsideError
label_desc: Use image node_id 15 for calling a global function with example usage: check_stage_exists(repo, stage, path) without return types