Beispiel #1
0
def test_repro_when_cmd_changes(tmp_dir, dvc, run_copy):
    from dvc.dvcfile import PipelineFile

    tmp_dir.gen("foo", "foo")
    stage = run_copy("foo", "bar", name="copy-file")
    target = "copy-file"
    assert not dvc.reproduce(target)

    stage.cmd = "  ".join(stage.cmd.split())  # change cmd spacing by two
    PipelineFile(dvc, PIPELINE_FILE)._dump_pipeline_file(stage)

    assert dvc.status([target]) == {target: ["changed command"]}
    assert dvc.reproduce(target)[0] == stage
Beispiel #2
0
def test_repro_when_cmd_changes(tmp_dir, dvc, run_copy, mocker):
    from dvc.dvcfile import PipelineFile

    tmp_dir.gen("foo", "foo")
    stage = run_copy("foo", "bar", name="copy-file")
    target = "copy-file"
    assert not dvc.reproduce(target)

    from dvc.stage.run import cmd_run

    m = mocker.patch("dvc.stage.run.cmd_run", wraps=cmd_run)
    stage.cmd = "  ".join(stage.cmd.split())  # change cmd spacing by two
    PipelineFile(dvc, PIPELINE_FILE)._dump_pipeline_file(stage)

    assert dvc.status([target]) == {target: ["changed command"]}
    assert dvc.reproduce(target)[0] == stage
    m.assert_called_once_with(stage)
Beispiel #3
0
def migrate(dvc, path, name):
    from dvc.dvcfile import SingleStageFile, PipelineFile

    dvcfile = SingleStageFile(dvc, path)
    stage = dvcfile.stage
    stage.name = name

    # Change stage path to future stage path (dvc.yaml file location)
    stage.path = os.path.join(os.getcwd(), "dvc.yaml")
    p_file = PipelineFile(dvc, "dvc.yaml")

    # using internal APIs, there are checks on `dump()`.
    p_file._dump_pipeline_file(stage)
    p_file._dump_lockfile(stage)
    logger.info("'{}' has been added to 'dvc.yaml' and 'dvc.lock'.")

    os.rename(dvcfile.path, dvcfile.path + ".bak")
    logger.info("'{0}' has been renamed to '{0}.bak'.".format(dvcfile.path))
    logger.info("Delete it after carefully reviewing"
                " 'dvc.lock' and 'dvc.yaml' or use it to rollback.")