Ejemplo n.º 1
0
def test_run_overwrite_order(tmp_dir, dvc, run_copy):
    from dvc.dvcfile import PIPELINE_FILE

    tmp_dir.gen({"foo": "foo", "foo1": "foo1"})
    run_copy("foo", "bar", name="copy-foo-bar")
    run_copy("bar", "foobar", name="copy-bar-foobar")

    run_copy("foo1", "bar1", name="copy-foo-bar", force=True)

    data = parse_yaml_for_update((tmp_dir / PIPELINE_FILE).read_text(),
                                 PIPELINE_FILE)
    assert list(data["stages"].keys()) == ["copy-foo-bar", "copy-bar-foobar"]
Ejemplo n.º 2
0
def to_single_stage_file(stage: "Stage"):
    state = stage.dumpd()

    # When we load a stage we parse yaml with a fast parser, which strips
    # off all the comments and formatting. To retain those on update we do
    # a trick here:
    # - reparse the same yaml text with a slow but smart ruamel yaml parser
    # - apply changes to a returned structure
    # - serialize it
    text = stage._stage_text  # noqa, pylint: disable=protected-access
    if text is not None:
        saved_state = parse_yaml_for_update(text, stage.path)
        apply_diff(state, saved_state)
        state = saved_state
    return state
Ejemplo n.º 3
0
    def remove_stage(self, stage):
        if not self.exists():
            return

        with open(self.path) as f:
            d = parse_yaml_for_update(f.read(), self.path)
        self.validate(d, self.path)

        if stage.name not in d:
            return

        logger.debug("Removing '%s' from '%s'", stage.name, self.path)
        del d[stage.name]

        if d:
            dump_yaml(self.path, d)
        else:
            self.remove()
Ejemplo n.º 4
0
    def remove_stage(self, stage):
        self._lockfile.remove_stage(stage)
        if not self.exists():
            return

        with open(self.path, "r") as f:
            d = parse_yaml_for_update(f.read(), self.path)

        self.validate(d, self.path)
        if stage.name not in d.get("stages", {}):
            return

        logger.debug("Removing '%s' from '%s'", stage.name, self.path)
        del d["stages"][stage.name]

        if d["stages"]:
            dump_yaml(self.path, d)
        else:
            super().remove()
Ejemplo n.º 5
0
    def remove_stage(self, stage):
        if not self.exists():
            return

        with open(self.path, encoding="utf-8") as f:
            d = parse_yaml_for_update(f.read(), self.path)
        self.validate(d, self.path)

        version = LOCKFILE_VERSION.from_dict(d)
        data = d if version == LOCKFILE_VERSION.V1 else d.get("stages", {})
        if stage.name not in data:
            return

        logger.debug("Removing '%s' from '%s'", stage.name, self.path)
        del data[stage.name]

        if data:
            dump_yaml(self.path, d)
        else:
            self.remove()
Ejemplo n.º 6
0
    def __pretty_exc__(self, **kwargs: Any) -> None:
        """Prettify exception message."""
        from collections.abc import Mapping

        lines: List[object] = []
        data = parse_yaml_for_update(self.text, self.path)
        if isinstance(data, Mapping):
            lines.extend(self._prepare_context(data))

        cause = ""
        if lines:
            # we should not add a newline after the main message
            # if there are no other outputs
            lines.insert(0, "")
        else:
            # if we don't have any context to show, we'll fallback to what we
            # got from voluptuous and print them in the same line.
            cause = f": {self.exc}"

        lines.insert(0, _prepare_message(f"{self}{cause}."))
        for line in lines:
            ui.error_write(line, styled=True)
Ejemplo n.º 7
0
def read_lock_file(file=PIPELINE_LOCK):
    with open(file, encoding="utf-8") as f:
        data = parse_yaml_for_update(f.read(), file)
    assert isinstance(data, OrderedDict)
    return data