Skip to content

Commit

Permalink
import-url: lock by-default
Browse files Browse the repository at this point in the history
Fixes iterative#2238

Signed-off-by: Ruslan Kuprieiev <[email protected]>
  • Loading branch information
efiop committed Jul 22, 2019
1 parent 993b1df commit 641edac
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dvc/dependency/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ class DependencyBase(object):
IsNotFileOrDirError = DependencyIsNotFileOrDirError

def update(self):
raise NotImplementedError
pass
2 changes: 1 addition & 1 deletion dvc/repo/imp_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


@scm_context
def imp_url(self, url, out=None, fname=None, erepo=None, locked=False):
def imp_url(self, url, out=None, fname=None, erepo=None, locked=True):
from dvc.stage import Stage

out = out or pathlib.PurePath(url).name
Expand Down
2 changes: 1 addition & 1 deletion dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def reproduce(self, interactive=False, **kwargs):
return self

def update(self):
if not self.is_repo_import:
if not self.is_repo_import and not self.is_import:
raise StageUpdateError(self.relpath)

self.deps[0].update()
Expand Down
9 changes: 5 additions & 4 deletions tests/func/test_repro.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,9 @@ def check_already_cached(self, stage):
with patch_download as mock_download:
with patch_checkout as mock_checkout:
with patch_run as mock_run:
stage.locked = False
stage.run()
stage.locked = True

mock_run.assert_not_called()
mock_download.assert_not_called()
Expand Down Expand Up @@ -918,14 +920,12 @@ def test(self, mock_prompt):

self.assertNotEqual(self.dvc.status(), {})

stages = self.dvc.reproduce(import_stage.path)
self.assertEqual(len(stages), 1)
self.dvc.update(import_stage.path)
self.assertTrue(os.path.exists("import"))
self.assertTrue(filecmp.cmp("import", self.BAR, shallow=False))
self.assertEqual(self.dvc.status(import_stage.path), {})

stages = self.dvc.reproduce(import_remote_stage.path)
self.assertEqual(len(stages), 1)
self.dvc.update(import_remote_stage.path)
self.assertEqual(self.dvc.status(import_remote_stage.path), {})

stages = self.dvc.reproduce(cmd_stage.path)
Expand Down Expand Up @@ -1323,6 +1323,7 @@ def test_force_import(self):

with patch_download as mock_download:
with patch_checkout as mock_checkout:
assert main(["unlock", "bar.dvc"]) == 0
ret = main(["repro", "--force", "bar.dvc"])
self.assertEqual(ret, 0)
self.assertEqual(mock_download.call_count, 1)
Expand Down
27 changes: 27 additions & 0 deletions tests/func/test_update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import shutil
import filecmp

from dvc.repo import Repo

Expand Down Expand Up @@ -40,3 +42,28 @@ def test_update_import(dvc_repo, erepo):
assert os.path.isfile(dst)
with open(dst, "r+") as fobj:
assert fobj.read() == "updated"


def test_update_import_url(repo_dir, dvc_repo):
src = "file"
dst = src + "_imported"

shutil.copyfile(repo_dir.FOO, src)

stage = dvc_repo.imp_url(src, dst)

assert os.path.exists(dst)
assert os.path.isfile(dst)
assert filecmp.cmp(src, dst, shallow=False)

# update data
os.unlink(src)
shutil.copyfile(repo_dir.BAR, src)

assert dvc_repo.status(stage.path) == {}
dvc_repo.update(stage.path)
assert dvc_repo.status(stage.path) == {}

assert os.path.exists(dst)
assert os.path.isfile(dst)
assert filecmp.cmp(src, dst, shallow=False)

0 comments on commit 641edac

Please sign in to comment.