imp_url: make default stage fname accompany import target (#3312)

This commit is contained in:
Paweł Redzyński
2020-02-14 17:05:08 +02:00
committed by GitHub
parent a317e59df1
commit 5b737a0a0b
4 changed files with 25 additions and 6 deletions
+3 -1
View File
@@ -123,7 +123,9 @@ def _create_stages(repo, targets, fname, pbar=None):
disable=True if len(targets) < LARGE_DIR_SIZE else None,
unit="file",
):
stage = Stage.create(repo, outs=[out], add=True, fname=fname)
stage = Stage.create(
repo, outs=[out], accompany_outs=True, fname=fname
)
if not stage:
if pbar is not None:
+7 -1
View File
@@ -11,7 +11,13 @@ def imp_url(self, url, out=None, fname=None, erepo=None, locked=True):
out = resolve_output(url, out)
stage = Stage.create(
self, cmd=None, deps=[url], outs=[out], fname=fname, erepo=erepo
self,
cmd=None,
deps=[url],
outs=[out],
fname=fname,
erepo=erepo,
accompany_outs=True,
)
if stage is None:
+3 -4
View File
@@ -502,12 +502,11 @@ class Stage(object):
return True
@staticmethod
def create(repo, **kwargs):
def create(repo, accompany_outs=False, **kwargs):
wdir = kwargs.get("wdir", None)
cwd = kwargs.get("cwd", None)
fname = kwargs.get("fname", None)
add = kwargs.get("add", False)
# Backward compatibility for `cwd` option
if wdir is None and cwd is not None:
@@ -539,12 +538,12 @@ class Stage(object):
stage._check_duplicated_arguments()
if not fname:
fname = Stage._stage_fname(stage.outs, add)
fname = Stage._stage_fname(stage.outs, accompany_outs)
stage._check_dvc_filename(fname)
# Autodetecting wdir for add, we need to create outs first to do that,
# so we start with wdir = . and remap out paths later.
if add and kwargs.get("wdir") is None and cwd is None:
if accompany_outs and kwargs.get("wdir") is None and cwd is None:
wdir = os.path.dirname(fname)
for out in chain(stage.outs, stage.deps):
+12
View File
@@ -92,3 +92,15 @@ def test_import_url_to_dir(dname, tmp_dir, dvc):
assert stage.outs[0].path_info == dst
assert os.path.isdir(dname)
assert dst.read_text() == "file content"
def test_import_stage_accompanies_target(tmp_dir, dvc, erepo_dir):
with erepo_dir.chdir():
erepo_dir.dvc_gen("file1", "file1 content", commit="commit file")
tmp_dir.gen({"dir": {}})
erepo = {"url": fspath(erepo_dir)}
dvc.imp_url("file1", out=os.path.join("dir", "imported_file"), erepo=erepo)
assert (tmp_dir / "dir" / "imported_file").exists()
assert (tmp_dir / "dir" / "imported_file.dvc").exists()