import: add --no-exec param (#4817)

To be consistent with the same --no-exec param in import-url.

Fixes #4567.
This commit is contained in:
Kevin Lloyd Bernal
2020-10-31 20:03:33 +02:00
committed by GitHub
parent 92752e0392
commit 58bed0e9ba
4 changed files with 58 additions and 3 deletions
+7
View File
@@ -17,6 +17,7 @@ class CmdImport(CmdBase):
out=self.args.out,
fname=self.args.file,
rev=self.args.rev,
no_exec=self.args.no_exec,
)
except DvcException:
logger.exception(
@@ -65,4 +66,10 @@ def add_parser(subparsers, parent_parser):
help="Specify name of the DVC-file this command will generate.",
metavar="<filename>",
)
import_parser.add_argument(
"--no-exec",
action="store_true",
default=False,
help="Only create DVC-file without actually downloading it.",
)
import_parser.set_defaults(func=CmdImport)
+4 -2
View File
@@ -1,6 +1,8 @@
def imp(self, url, path, out=None, fname=None, rev=None):
def imp(self, url, path, out=None, fname=None, rev=None, no_exec=False):
erepo = {"url": url}
if rev is not None:
erepo["rev"] = rev
return self.imp_url(path, out=out, fname=fname, erepo=erepo, frozen=True)
return self.imp_url(
path, out=out, fname=fname, erepo=erepo, frozen=True, no_exec=no_exec
)
+10
View File
@@ -465,3 +465,13 @@ def test_try_import_complete_repo(tmp_dir, dvc, erepo_dir):
with pytest.raises(IsADVCRepoError) as exc_info:
dvc.imp(os.fspath(erepo_dir), os.curdir, out="out")
assert expected_message == str(exc_info.value)
def test_import_with_no_exec(tmp_dir, dvc, erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen("foo", "foo content", commit="create foo")
dvc.imp(os.fspath(erepo_dir), "foo", out="foo_imported", no_exec=True)
dst = tmp_dir / "foo_imported"
assert not dst.exists()
+37 -1
View File
@@ -24,5 +24,41 @@ def test_import(mocker):
assert cmd.run() == 0
m.assert_called_once_with(
"repo_url", path="src", out="out", fname="file", rev="version"
"repo_url",
path="src",
out="out",
fname="file",
rev="version",
no_exec=False,
)
def test_import_no_exec(mocker):
cli_args = parse_args(
[
"import",
"repo_url",
"src",
"--out",
"out",
"--file",
"file",
"--rev",
"version",
"--no-exec",
]
)
cmd = cli_args.func(cli_args)
m = mocker.patch.object(cmd.repo, "imp", autospec=True)
assert cmd.run() == 0
m.assert_called_once_with(
"repo_url",
path="src",
out="out",
fname="file",
rev="version",
no_exec=True,
)