Merge pull request #2427 from Suor/add

dvc: use wdir = "." on add
This commit is contained in:
Ruslan Kuprieiev
2019-08-24 07:17:41 +03:00
committed by GitHub
2 changed files with 25 additions and 14 deletions
+14 -5
View File
@@ -9,6 +9,7 @@ import subprocess
import logging
import signal
import threading
from itertools import chain
from dvc.utils import relpath
from dvc.utils.compat import pathlib
@@ -438,6 +439,7 @@ class Stage(object):
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:
@@ -449,8 +451,8 @@ class Stage(object):
" directory.".format(fname=fname)
)
wdir = cwd
else:
wdir = os.curdir if wdir is None else wdir
elif wdir is None:
wdir = os.curdir
stage = Stage(
repo=repo,
@@ -468,11 +470,18 @@ class Stage(object):
stage._check_duplicated_arguments()
if not fname:
fname = Stage._stage_fname(
stage.outs, add=kwargs.get("add", False)
)
fname = Stage._stage_fname(stage.outs, add)
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:
wdir = os.path.dirname(fname)
for out in chain(stage.outs, stage.deps):
if out.is_in_repo:
out.def_path = relpath(out.path_info, wdir)
wdir = os.path.abspath(wdir)
if cwd is not None:
+11 -9
View File
@@ -169,15 +169,17 @@ class TestAddModifiedDir(TestDvc):
self.assertTrue(stages[0] is not None)
class TestAddFileInDir(TestDvc):
def test(self):
stages = self.dvc.add(self.DATA_SUB)
self.assertEqual(len(stages), 1)
stage = stages[0]
self.assertNotEqual(stage, None)
self.assertEqual(len(stage.deps), 0)
self.assertEqual(len(stage.outs), 1)
self.assertEqual(stage.relpath, self.DATA_SUB + ".dvc")
def test_add_file_in_dir(repo_dir, dvc_repo):
stage, = dvc_repo.add(repo_dir.DATA_SUB)
assert stage is not None
assert len(stage.deps) == 0
assert len(stage.outs) == 1
assert stage.relpath == repo_dir.DATA_SUB + ".dvc"
# Current dir should not be taken into account
assert stage.wdir == os.path.dirname(stage.path)
assert stage.outs[0].def_path == "data_sub"
class TestAddExternalLocalFile(TestDvc):