code: def _collect_with_deps(
      stages: StageList, graph: "DiGraph"
  ) -> StageSet:
      from dvc.exceptions import StageNotFoundError
      from dvc.repo.graph import collect_pipeline
  
      res: StageSet = set()
      for stage in stages:
          pl = list(collect_pipeline(stage, graph=graph))
          if not pl:
              raise StageNotFoundError(
                  f"Stage {stage} is not found in the project. "
                  "Check that there are no symlinks in the parents "
                  "leading up to it within the project."
              )
          res.update(pl)
      return res
  
imports: import fnmatch
  import typing
  from contextlib import suppress
  from functools import wraps
  from typing import Iterable, List, NamedTuple, Optional, Set, Tuple, Union
  from dvc.exceptions import NoOutputOrStageError, OutputDuplicationError, OutputNotFoundError
  from dvc.log import logger
  from dvc.repo import lock_repo
  from dvc.ui import ui
  from dvc.utils import as_posix, parse_target
label_desc: Use image node_id 1 for calling a global function with example usage: _collect_with_deps(stages, graph) and returns: res