diff --git a/dvc/command/run.py b/dvc/command/run.py index fdac98bcaa..99c746b5be 100644 --- a/dvc/command/run.py +++ b/dvc/command/run.py @@ -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, @@ -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", diff --git a/dvc/stage.py b/dvc/stage.py index 5f0d0b34c0..c008cd3e80 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -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, @@ -548,7 +533,7 @@ 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): @@ -556,11 +541,7 @@ def create(repo, accompany_outs=False, **kwargs): 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)) diff --git a/tests/func/test_cli.py b/tests/func/test_cli.py index d7a4d0f45d..bb80a1781b 100644 --- a/tests/func/test_cli.py +++ b/tests/func/test_cli.py @@ -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" @@ -59,8 +58,6 @@ def test(self): fname, "--file", fname, - "-c", - cwd, cmd, arg1, arg2, @@ -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]) diff --git a/tests/func/test_import.py b/tests/func/test_import.py index 65ca99b56d..11324cb911 100644 --- a/tests/func/test_import.py +++ b/tests/func/test_import.py @@ -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") diff --git a/tests/func/test_repro.py b/tests/func/test_repro.py index 17acb24330..af5a30435b 100644 --- a/tests/func/test_repro.py +++ b/tests/func/test_repro.py @@ -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")), ) @@ -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), ) @@ -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" diff --git a/tests/func/test_run.py b/tests/func/test_run.py index 0f97672a67..8fcd7603ed 100644 --- a/tests/func/test_run.py +++ b/tests/func/test_run.py @@ -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( @@ -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)) @@ -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", ) @@ -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, ) @@ -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]) @@ -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): @@ -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): @@ -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") diff --git a/tests/unit/command/test_run.py b/tests/unit/command/test_run.py index 2b6dcfe659..a9b7e60a4f 100644 --- a/tests/unit/command/test_run.py +++ b/tests/unit/command/test_run.py @@ -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,