mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-11 07:18:28 +01:00
run: remove deprecated --cwd (#3623)
It has been deprecated for a long time now and it significantly complicates the code, hiding multiple bugs.
This commit is contained in:
@@ -43,7 +43,6 @@ class CmdRun(CmdBase):
|
||||
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,
|
||||
@@ -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",
|
||||
|
||||
+3
-22
@@ -506,24 +506,9 @@ class Stage(object):
|
||||
|
||||
@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,
|
||||
@@ -548,7 +533,7 @@ class Stage(object):
|
||||
|
||||
# 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):
|
||||
@@ -556,11 +541,7 @@ class Stage(object):
|
||||
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))
|
||||
|
||||
@@ -35,7 +35,6 @@ class TestRun(TestDvc):
|
||||
out_no_cache2 = "out_no_cache2"
|
||||
|
||||
fname = "dvc.dvc"
|
||||
cwd = os.curdir
|
||||
cmd = "cmd"
|
||||
arg1 = "arg1"
|
||||
arg2 = "arg2"
|
||||
@@ -59,8 +58,6 @@ class TestRun(TestDvc):
|
||||
fname,
|
||||
"--file",
|
||||
fname,
|
||||
"-c",
|
||||
cwd,
|
||||
cmd,
|
||||
arg1,
|
||||
arg2,
|
||||
@@ -72,7 +69,6 @@ class TestRun(TestDvc):
|
||||
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])
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -118,8 +118,9 @@ class TestReproWorkingDirectoryAsOutput(TestDvc):
|
||||
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")),
|
||||
)
|
||||
|
||||
@@ -153,7 +154,8 @@ class TestReproWorkingDirectoryAsOutput(TestDvc):
|
||||
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),
|
||||
)
|
||||
@@ -733,44 +735,6 @@ class TestCmdRepro(TestReproChangedData):
|
||||
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"
|
||||
|
||||
+10
-56
@@ -38,7 +38,6 @@ class TestRun(TestDvc):
|
||||
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(
|
||||
@@ -47,7 +46,6 @@ class TestRun(TestDvc):
|
||||
outs=outs,
|
||||
outs_no_cache=outs_no_cache,
|
||||
fname=fname,
|
||||
cwd=cwd,
|
||||
)
|
||||
|
||||
self.assertTrue(filecmp.cmp(self.FOO, "out", shallow=False))
|
||||
@@ -66,19 +64,13 @@ class TestRun(TestDvc):
|
||||
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",
|
||||
)
|
||||
|
||||
|
||||
@@ -91,20 +83,6 @@ class TestRunMissingDep(TestDvc):
|
||||
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,
|
||||
)
|
||||
|
||||
|
||||
@@ -194,7 +172,9 @@ class TestRunStageInsideOutput(TestDvc):
|
||||
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])
|
||||
@@ -210,13 +190,13 @@ class TestRunStageInsideOutput(TestDvc):
|
||||
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):
|
||||
@@ -281,20 +261,11 @@ class TestRunRemoveOuts(TestDvc):
|
||||
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):
|
||||
@@ -596,23 +567,6 @@ class TestCmdRunWorkingDirectory(TestDvc):
|
||||
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")
|
||||
|
||||
@@ -18,8 +18,6 @@ def test_run(mocker, dvc):
|
||||
"metrics-no-cache",
|
||||
"--file",
|
||||
"file",
|
||||
"--cwd",
|
||||
"cwd",
|
||||
"--wdir",
|
||||
"wdir",
|
||||
"--no-exec",
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user