def collect_granular( self, target: str = None, with_deps: bool = False, recursive: bool = False, graph: "DiGraph" = None, accept_group: bool = False, ) -> List[StageInfo]: """Collects a list of (stage, filter_info) from the given target. Priority is in the order of following in case of ambiguity: - .dvc file or .yaml file - dir if recursive and directory exists - stage_name - output file Args: target: if not provided, all of the stages without any filters are returned. If `target` is a path to a dvc-tracked output, a (stage, output_path_info) is returned. Otherwise, the details above for `target` in `collect()` applies. (see `collect()` for other arguments) """ if not target: return [StageInfo(stage) for stage in self.repo.stages] stages, file, _ = _collect_specific_target(self, target, with_deps, recursive, accept_group) if not stages: if not (recursive and self.tree.isdir(target)): try: (out, ) = self.repo.find_outs_by_path(target, strict=False) filter_info = PathInfo(os.path.abspath(target)) return [StageInfo(out.stage, filter_info)] except OutputNotFoundError: pass try: stages = self.collect( target, with_deps, recursive, graph, accept_group=accept_group, ) except StageFileDoesNotExistError as exc: # collect() might try to use `target` as a stage name # and throw error that dvc.yaml does not exist, whereas it # should say that both stage name and file does not exist. if file and is_valid_filename(file): raise raise NoOutputOrStageError(target, exc.file) from exc except StageNotFound as exc: raise NoOutputOrStageError(target, exc.file) from exc return [StageInfo(stage) for stage in stages]
def collect_granular(self, target=None, with_deps=False, recursive=False, graph=None): """ Priority is in the order of following in case of ambiguity: - .dvc file or .yaml file - dir if recursive and directory exists - stage_name - output file """ if not target: return [(stage, None) for stage in self.stages] file, name = parse_target(target) stages = [] # Optimization: do not collect the graph for a specific target if not file: # parsing is ambiguous when it does not have a colon # or if it's not a dvcfile, as it can be a stage name # in `dvc.yaml` or, an output in a stage. logger.debug("Checking if stage '%s' is in '%s'", target, PIPELINE_FILE) if not (recursive and os.path.isdir(target)): stage = self._collect_from_default_dvcfile(target) if stage: stages = (self._collect_pipeline(stage) if with_deps else [stage]) elif not with_deps and is_valid_filename(file): stages = self.get_stages(file, name) if not stages: if not (recursive and os.path.isdir(target)): try: (out, ) = self.find_outs_by_path(target, strict=False) filter_info = PathInfo(os.path.abspath(target)) return [(out.stage, filter_info)] except OutputNotFoundError: pass try: stages = self.collect(target, with_deps, recursive, graph) except StageFileDoesNotExistError as exc: # collect() might try to use `target` as a stage name # and throw error that dvc.yaml does not exist, whereas it # should say that both stage name and file does not exist. if file and is_valid_filename(file): raise raise NoOutputOrStageError(target, exc.file) from exc except StageNotFound as exc: raise NoOutputOrStageError(target, exc.file) from exc return [(stage, None) for stage in stages]