mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 07:18:27 +01:00
+14
-5
@@ -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
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user