import-url: lock by-default

Fixes #2238

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2019-07-22 20:24:00 +03:00
parent 993b1df8ef
commit 641edacef6
5 changed files with 35 additions and 7 deletions
+1 -1
View File
@@ -22,4 +22,4 @@ class DependencyBase(object):
IsNotFileOrDirError = DependencyIsNotFileOrDirError
def update(self):
raise NotImplementedError
pass
+1 -1
View File
@@ -3,7 +3,7 @@ from dvc.repo.scm_context import scm_context
@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
+1 -1
View File
@@ -334,7 +334,7 @@ class Stage(object):
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()
+5 -4
View File
@@ -837,7 +837,9 @@ class TestReproExternalBase(TestDvc):
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()
@@ -918,14 +920,12 @@ class TestReproExternalBase(TestDvc):
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)
@@ -1323,6 +1323,7 @@ class TestReproAlreadyCached(TestRepro):
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)
+27
View File
@@ -1,4 +1,6 @@
import os
import shutil
import filecmp
from dvc.repo import Repo
@@ -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)