docstr: Collect list of stages from the provided target.
  
  Args:
      target: if not provided, all of the stages in the graph are
          returned.
          Target can be:
          - a foreach group name or a stage name in the `dvc.yaml` file.
          - a generated stage name from a foreach group.
          - a path to `dvc.yaml` or `.dvc` file.
          - in case of a stage to a dvc.yaml file in a different
            directory than current working directory, it can be a path
            to dvc.yaml file, followed by a colon `:`, followed by stage
            name (eg: `../dvc.yaml:build`).
          - in case of `recursive`, it can be a path to a directory.
          - in case of `glob`, it can be a wildcard pattern to match
            stages. Example: `build*` for stages in `dvc.yaml` file, or
            `../dvc.yaml:build*` for stages in dvc.yaml in a different
            directory.
            Note that, glob only applies for the stage name, not to the
            file, so `**/dvc.yaml:build*` is not possible.
      with_deps: if true, the stages including their dependencies are
          returned.
      recursive: if true and if `target` is a directory, all of the
          stages inside that directory is returned.
      graph: graph to use. Defaults to `repo.graph`.
      glob: Use `target` as a pattern to match stages in a file.
docstr_tok: ["Collect","list","of","stages","from","the","provided","target",".","Args",":","target",":","if","not","provided",",","all","of","the","stages","in","the","graph","are","returned",".","Target","can","be",":","-","a","foreach","group","name","or","a","stage","name","in","the","`","dvc.yaml","`","file",".","-","a","generated","stage","name","from","a","foreach","group",".","-","a","path","to","`","dvc.yaml","`","or","`",".dvc","`","file",".","-","in","case","of","a","stage","to","a","dvc.yaml","file","in","a","different","directory","than","current","working","directory",",","it","can","be","a","path","to","dvc.yaml","file",",","followed","by","a","colon","`",":","`",",","followed","by","stage","name","(","eg",":","`","..","\/dvc.yaml",":","build","`",")",".","-","in","case","of","`","recursive","`",",","it","can","be","a","path","to","a","directory",".","-","in","case","of","`","glob","`",",","it","can","be","a","wildcard","pattern","to","match","stages",".","Example",":","`","build","*","`","for","stages","in","`","dvc.yaml","`","file",",","or","`","..","\/dvc.yaml",":","build","*","`","for","stages","in","dvc.yaml","in","a","different","directory",".","Note","that",",","glob","only","applies","for","the","stage","name",",","not","to","the","file",",","so","`","*","*","\/dvc.yaml",":","build","*","`","is","not","possible",".","with_deps",":","if","true",",","the","stages","including","their","dependencies","are","returned",".","recursive",":","if","true","and","if","`","target","`","is","a","directory",",","all","of","the","stages","inside","that","directory","is","returned",".","graph",":","graph","to","use",".","Defaults","to","`","repo.graph","`",".","glob",":","Use","`","target","`","as","a","pattern","to","match","stages","in","a","file","."]
code: def collect(
      self,
      target: Optional[str] = None,
      with_deps: bool = False,
      recursive: bool = False,
      graph: Optional["DiGraph"] = None,
      glob: bool = False,
  ) -> StageIter:
      """Collect list of stages from the provided target.
  
      Args:
          target: if not provided, all of the stages in the graph are
              returned.
              Target can be:
              - a foreach group name or a stage name in the `dvc.yaml` file.
              - a generated stage name from a foreach group.
              - a path to `dvc.yaml` or `.dvc` file.
              - in case of a stage to a dvc.yaml file in a different
                directory than current working directory, it can be a path
                to dvc.yaml file, followed by a colon `:`, followed by stage
                name (eg: `../dvc.yaml:build`).
              - in case of `recursive`, it can be a path to a directory.
              - in case of `glob`, it can be a wildcard pattern to match
                stages. Example: `build*` for stages in `dvc.yaml` file, or
                `../dvc.yaml:build*` for stages in dvc.yaml in a different
                directory.
                Note that, glob only applies for the stage name, not to the
                file, so `**/dvc.yaml:build*` is not possible.
          with_deps: if true, the stages including their dependencies are
              returned.
          recursive: if true and if `target` is a directory, all of the
              stages inside that directory is returned.
          graph: graph to use. Defaults to `repo.graph`.
          glob: Use `target` as a pattern to match stages in a file.
      """
      if not target:
          return list(graph) if graph else self.repo.index.stages
  
      if recursive and self.fs.isdir(target):
          from dvc.repo.graph import collect_inside_path
  
          path = self.fs.abspath(target)
          return collect_inside_path(
              path, graph or self.repo.index.graph
          )
  
      stages = self.from_target(target, glob=glob)
      if not with_deps:
          return stages
  
      return _collect_with_deps(stages, graph or self.repo.index.graph)
  
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 14 for calling the StageLoad obj's underlying member method code with example usage: obj.collect(target, with_deps, recursive, graph, glob) and returns: _collect_with_deps, unknown, collect_inside_path, stages