mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 23:10:42 +01:00
add --no-exec mode to import url (#4075)
* add --no-exec mode to import url fix #3513 * Update tests/func/test_import_url.py * Update tests/func/test_import_url.py Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
co-authored by
Ruslan Kuprieiev
parent
a2f1367a9a
commit
74930c01ec
+10
-1
@@ -12,7 +12,10 @@ class CmdImportUrl(CmdBase):
|
||||
def run(self):
|
||||
try:
|
||||
self.repo.imp_url(
|
||||
self.args.url, out=self.args.out, fname=self.args.file
|
||||
self.args.url,
|
||||
out=self.args.out,
|
||||
fname=self.args.file,
|
||||
no_exec=self.args.no_exec,
|
||||
)
|
||||
except DvcException:
|
||||
logger.exception(
|
||||
@@ -66,4 +69,10 @@ def add_parser(subparsers, parent_parser):
|
||||
metavar="<filename>",
|
||||
choices=completion.Optional.DIR,
|
||||
)
|
||||
import_parser.add_argument(
|
||||
"--no-exec",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Only create stage file without actually download it.",
|
||||
)
|
||||
import_parser.set_defaults(func=CmdImportUrl)
|
||||
|
||||
+7
-2
@@ -10,7 +10,9 @@ from . import locked
|
||||
|
||||
@locked
|
||||
@scm_context
|
||||
def imp_url(self, url, out=None, fname=None, erepo=None, frozen=True):
|
||||
def imp_url(
|
||||
self, url, out=None, fname=None, erepo=None, frozen=True, no_exec=False
|
||||
):
|
||||
from dvc.dvcfile import Dvcfile
|
||||
from dvc.stage import Stage, create_stage
|
||||
|
||||
@@ -46,7 +48,10 @@ def imp_url(self, url, out=None, fname=None, erepo=None, frozen=True):
|
||||
except OutputDuplicationError as exc:
|
||||
raise OutputDuplicationError(exc.output, set(exc.stages) - {stage})
|
||||
|
||||
stage.run()
|
||||
if no_exec:
|
||||
stage.ignore_outs()
|
||||
else:
|
||||
stage.run()
|
||||
|
||||
stage.frozen = frozen
|
||||
|
||||
|
||||
@@ -103,3 +103,12 @@ def test_import_stage_accompanies_target(tmp_dir, dvc, erepo_dir):
|
||||
def test_import_url_nonexistent(dvc, erepo_dir):
|
||||
with pytest.raises(DependencyDoesNotExistError):
|
||||
dvc.imp_url(os.fspath(erepo_dir / "non-existent"))
|
||||
|
||||
|
||||
def test_import_url_with_no_exec(tmp_dir, dvc, erepo_dir):
|
||||
tmp_dir.gen({"data_dir": {"file": "file content"}})
|
||||
src = os.path.join("data_dir", "file")
|
||||
|
||||
dvc.imp_url(src, ".", no_exec=True)
|
||||
dst = tmp_dir / "file"
|
||||
assert not dst.exists()
|
||||
|
||||
@@ -14,7 +14,7 @@ def test_import_url(mocker):
|
||||
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with("src", out="out", fname="file")
|
||||
m.assert_called_once_with("src", out="out", fname="file", no_exec=False)
|
||||
|
||||
|
||||
def test_failed_import_url(mocker, caplog):
|
||||
@@ -31,3 +31,16 @@ def test_failed_import_url(mocker, caplog):
|
||||
"adding it with `dvc add`."
|
||||
)
|
||||
assert expected_error in caplog.text
|
||||
|
||||
|
||||
def test_import_url_no_exec(mocker):
|
||||
cli_args = parse_args(
|
||||
["import-url", "--no-exec", "src", "out", "--file", "file"]
|
||||
)
|
||||
|
||||
cmd = cli_args.func(cli_args)
|
||||
m = mocker.patch.object(cmd.repo, "imp_url", autospec=True)
|
||||
|
||||
assert cmd.run() == 0
|
||||
|
||||
m.assert_called_once_with("src", out="out", fname="file", no_exec=True)
|
||||
|
||||
Reference in New Issue
Block a user