Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions dvc/command/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def run(self):
deps=self.args.deps,
params=self.args.params,
fname=self.args.file,
cwd=self.args.cwd,
wdir=self.args.wdir,
no_exec=self.args.no_exec,
overwrite=overwrite,
Expand Down Expand Up @@ -138,9 +137,6 @@ def add_parser(subparsers, parent_parser):
run_parser.add_argument(
"-f", "--file", help="Specify name of the DVC-file it generates."
)
run_parser.add_argument(
"-c", "--cwd", help="Deprecated, use -w and -f instead."
)
run_parser.add_argument(
"-w",
"--wdir",
Expand Down
25 changes: 3 additions & 22 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,24 +506,9 @@ def is_cached(self):

@staticmethod
def create(repo, accompany_outs=False, **kwargs):

wdir = kwargs.get("wdir", None)
cwd = kwargs.get("cwd", None)
wdir = kwargs.get("wdir", None) or os.curdir
fname = kwargs.get("fname", None)

# Backward compatibility for `cwd` option
if wdir is None and cwd is not None:
if fname is not None and os.path.basename(fname) != fname:
raise StageFileBadNameError(
"DVC-file name '{fname}' may not contain subdirectories"
" if `-c|--cwd` (deprecated) is specified. Use `-w|--wdir`"
" along with `-f` to specify DVC-file path with working"
" directory.".format(fname=fname)
)
wdir = cwd
elif wdir is None:
wdir = os.curdir

stage = Stage(
repo=repo,
wdir=wdir,
Expand All @@ -548,19 +533,15 @@ def create(repo, accompany_outs=False, **kwargs):

# Autodetecting wdir for add, we need to create outs first to do that,
# so we start with wdir = . and remap out paths later.
if accompany_outs and kwargs.get("wdir") is None and cwd is None:
if accompany_outs and kwargs.get("wdir") 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:
path = os.path.join(wdir, fname)
else:
path = os.path.abspath(fname)
path = os.path.abspath(fname)

Stage._check_stage_path(repo, wdir, is_wdir=kwargs.get("wdir"))
Stage._check_stage_path(repo, os.path.dirname(path))
Expand Down
4 changes: 0 additions & 4 deletions tests/func/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test(self):
out_no_cache2 = "out_no_cache2"

fname = "dvc.dvc"
cwd = os.curdir
cmd = "cmd"
arg1 = "arg1"
arg2 = "arg2"
Expand All @@ -59,8 +58,6 @@ def test(self):
fname,
"--file",
fname,
"-c",
cwd,
cmd,
arg1,
arg2,
Expand All @@ -72,7 +69,6 @@ def test(self):
self.assertEqual(args.outs, [out1, out2])
self.assertEqual(args.outs_no_cache, [out_no_cache1, out_no_cache2])
self.assertEqual(args.file, fname)
self.assertEqual(args.cwd, cwd)
self.assertEqual(args.command, [cmd, arg1, arg2])


Expand Down
9 changes: 4 additions & 5 deletions tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ def test_import_non_cached(erepo_dir, tmp_dir, dvc, scm):
src = "non_cached_output"
dst = src + "_imported"

erepo_dir.dvc.run(
cmd="echo hello > {}".format(src),
outs_no_cache=[src],
cwd=fspath(erepo_dir),
)
with erepo_dir.chdir():
erepo_dir.dvc.run(
cmd="echo hello > {}".format(src), outs_no_cache=[src],
)

erepo_dir.scm_add([fspath(erepo_dir / src)], commit="add a non-cached out")

Expand Down
46 changes: 5 additions & 41 deletions tests/func/test_repro.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def test(self):
os.mkdir(os.path.join(self.dvc.root_dir, "dir1"))

self.dvc.run(
cwd="dir1",
outs=["../dir2"],
fname=os.path.join("dir1", "dir2.dvc"),
wdir="dir1",
outs=[os.path.join("..", "dir2")],
cmd="mkdir {path}".format(path=os.path.join("..", "dir2")),
)

Expand Down Expand Up @@ -153,7 +154,8 @@ def test_nested(self):
out_dir = relpath(nested_dir, dir1)

nested_stage = self.dvc.run(
cwd=dir1, # b
fname=os.path.join(dir1, "b.dvc"),
wdir=dir1,
outs=[out_dir], # ../a/nested
cmd="mkdir {path}".format(path=out_dir),
)
Expand Down Expand Up @@ -733,44 +735,6 @@ def test(self):
self.assertNotEqual(ret, 0)


class TestCmdReproChdirCwdBackwardCompatible(TestDvc):
def test(self):
dname = "dir"
os.mkdir(dname)
foo = os.path.join(dname, self.FOO)
bar = os.path.join(dname, self.BAR)
code = os.path.join(dname, self.CODE)
shutil.copyfile(self.FOO, foo)
shutil.copyfile(self.CODE, code)

ret = main(
[
"run",
"-f",
"Dvcfile",
"-c",
dname,
"-d",
self.FOO,
"-o",
self.BAR,
"python {} {} {}".format(self.CODE, self.FOO, self.BAR),
]
)
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(foo))
self.assertTrue(os.path.isfile(bar))
self.assertTrue(filecmp.cmp(foo, bar, shallow=False))

os.unlink(bar)

ret = main(["repro", "-c", dname])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(foo))
self.assertTrue(os.path.isfile(bar))
self.assertTrue(filecmp.cmp(foo, bar, shallow=False))


class TestCmdReproChdir(TestDvc):
def test(self):
dname = "dir"
Expand Down
66 changes: 10 additions & 56 deletions tests/func/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def test(self):
outs = [os.path.join(self.dvc.root_dir, "out")]
outs_no_cache = []
fname = "out.dvc"
cwd = os.curdir

self.dvc.add(self.FOO)
stage = self.dvc.run(
Expand All @@ -47,7 +46,6 @@ def test(self):
outs=outs,
outs_no_cache=outs_no_cache,
fname=fname,
cwd=cwd,
)

self.assertTrue(filecmp.cmp(self.FOO, "out", shallow=False))
Expand All @@ -66,19 +64,13 @@ def test(self):
outs=outs,
outs_no_cache=outs_no_cache,
fname="duplicate" + fname,
cwd=cwd,
)


class TestRunEmpty(TestDvc):
def test(self):
self.dvc.run(
cmd="",
deps=[],
outs=[],
outs_no_cache=[],
fname="empty.dvc",
cwd=os.curdir,
cmd="", deps=[], outs=[], outs_no_cache=[], fname="empty.dvc",
)


Expand All @@ -91,20 +83,6 @@ def test(self):
outs=[],
outs_no_cache=[],
fname="empty.dvc",
cwd=os.curdir,
)


class TestRunBadStageFilename(TestDvc):
def test(self):
with self.assertRaises(StageFileBadNameError):
self.dvc.run(
cmd="",
deps=[],
outs=[],
outs_no_cache=[],
fname=os.path.join(self.DATA_DIR, "empty.dvc"),
cwd=os.curdir,
)


Expand Down Expand Up @@ -194,7 +172,9 @@ def test_cwd(self):
self.dvc.run(cmd="", deps=[], outs=[self.DATA_DIR])

with self.assertRaises(StagePathAsOutputError):
self.dvc.run(cmd="", cwd=self.DATA_DIR, fname="inside-cwd.dvc")
self.dvc.run(
cmd="", fname=os.path.join(self.DATA_DIR, "inside-cwd.dvc")
)

def test_file_name(self):
self.dvc.run(cmd="", deps=[], outs=[self.DATA_DIR])
Expand All @@ -210,13 +190,13 @@ def test_file_name(self):
class TestRunBadCwd(TestDvc):
def test(self):
with self.assertRaises(StagePathOutsideError):
self.dvc.run(cmd="", cwd=self.mkdtemp())
self.dvc.run(cmd="", wdir=self.mkdtemp())

def test_same_prefix(self):
with self.assertRaises(StagePathOutsideError):
path = "{}-{}".format(self._root_dir, uuid.uuid4())
os.mkdir(path)
self.dvc.run(cmd="", cwd=path)
self.dvc.run(cmd="", wdir=path)


class TestRunBadWdir(TestDvc):
Expand Down Expand Up @@ -281,20 +261,11 @@ def test(self):
fobj.write(" sys.exit(1)\n")
fobj.write("open(sys.argv[1], 'w+').close()\n")

ret = main(
[
"run",
"--remove-outs",
"-d",
self.CODE,
"-o",
self.FOO,
"python",
self.CODE,
self.FOO,
]
self.dvc.run(
deps=[self.CODE],
outs=[self.FOO],
cmd="python {} {}".format(self.CODE, self.FOO),
)
self.assertEqual(ret, 0)


class TestRunUnprotectOutsCopy(TestDvc):
Expand Down Expand Up @@ -596,23 +567,6 @@ def test_fname_changes_path_and_wdir(self):
d = load_stage_file(stage.relpath)
self.assertEqual(d[Stage.PARAM_WDIR], "..")

def test_cwd_is_ignored(self):
dname = "dir"
os.mkdir(os.path.join(self._root_dir, dname))
foo = os.path.join(dname, self.FOO)
fname = os.path.join("stage" + Stage.STAGE_FILE_SUFFIX)
stage = self.dvc.run(
cmd="echo test > {}".format(foo),
outs=[foo],
cwd=dname,
wdir=".",
fname=fname,
)
self.assertEqual(stage.wdir, os.path.realpath(self._root_dir))
self.assertEqual(
stage.path, os.path.join(os.path.realpath(self._root_dir), fname)
)


def test_rerun_deterministic(tmp_dir, run_copy):
tmp_dir.gen("foo", "foo content")
Expand Down
5 changes: 0 additions & 5 deletions tests/unit/command/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def test_run(mocker, dvc):
"metrics-no-cache",
"--file",
"file",
"--cwd",
"cwd",
"--wdir",
"wdir",
"--no-exec",
Expand Down Expand Up @@ -57,7 +55,6 @@ def test_run(mocker, dvc):
outs_persist_no_cache=["outs-persist-no-cache"],
params=["file:param1,param2", "param3"],
fname="file",
cwd="cwd",
wdir="wdir",
no_exec=True,
overwrite=True,
Expand All @@ -84,7 +81,6 @@ def test_run_args_from_cli(mocker, dvc):
outs_persist_no_cache=[],
params=[],
fname=None,
cwd=None,
wdir=None,
no_exec=False,
overwrite=False,
Expand All @@ -111,7 +107,6 @@ def test_run_args_with_spaces(mocker, dvc):
outs_persist_no_cache=[],
params=[],
fname=None,
cwd=None,
wdir=None,
no_exec=False,
overwrite=False,
Expand Down