Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,10 @@ def create(
else:
stage.unprotect_outs()

if os.path.exists(path) and any(out.persist for out in stage.outs):
logger.warning("Build cache is ignored when persisting outputs.")
ignore_build_cache = True

if validate_state:
if os.path.exists(path):
if not ignore_build_cache and stage.is_cached:
Expand Down
31 changes: 31 additions & 0 deletions tests/func/test_run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import uuid

import logging
import mock
import shutil
import filecmp
Expand Down Expand Up @@ -948,3 +949,33 @@ def test(self):

mock_run.assert_called_once()
mock_checkout.assert_not_called()


class TestPersistentOutput(TestDvc):
def test_ignore_build_cache(self):
warning = "Build cache is ignored when persisting outputs."

with open("immutable", "w") as fobj:
fobj.write("1")

cmd = [
"run",
"--overwrite-dvcfile",
"--deps",
"immutable",
"--outs-persist",
"greetings",
"echo hello>>greetings",
]

with self._caplog.at_level(logging.WARNING, logger="dvc"):
assert main(cmd) == 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we test that that warning is not printed during the first run now? 🙂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure 👍

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, @efiop (sorry for such back-and-forth, I should've test it correctly beforehand 😅)

assert warning not in self._caplog.text

assert main(cmd) == 0
assert warning in self._caplog.text

# Even if the "immutable" dependency didn't change
# it should run the command again, as it is "ignoring build cache"
with open("greetings", "r") as fobj:
assert "hello\nhello\n" == fobj.read()