Merge pull request #2478 from pared/2443

stage: prevent writing default wdir into stage file
This commit is contained in:
Ruslan Kuprieiev
2019-09-09 18:23:36 +03:00
committed by GitHub
3 changed files with 10 additions and 12 deletions
+5 -1
View File
@@ -629,12 +629,16 @@ class Stage(object):
def dumpd(self):
rel_wdir = relpath(self.wdir, os.path.dirname(self.path))
wdir = pathlib.PurePath(rel_wdir).as_posix()
wdir = wdir if wdir != "." else None
return {
key: value
for key, value in {
Stage.PARAM_MD5: self.md5,
Stage.PARAM_CMD: self.cmd,
Stage.PARAM_WDIR: pathlib.PurePath(rel_wdir).as_posix(),
Stage.PARAM_WDIR: wdir,
Stage.PARAM_LOCKED: self.locked,
Stage.PARAM_DEPS: [d.dumpd() for d in self.deps],
Stage.PARAM_OUTS: [o.dumpd() for o in self.outs],
+3 -3
View File
@@ -560,18 +560,18 @@ class TestCmdRunCliMetrics(TestDvc):
class TestCmdRunWorkingDirectory(TestDvc):
def test_default_wdir_is_written(self):
def test_default_wdir_is_not_written(self):
stage = self.dvc.run(
cmd="echo test > {}".format(self.FOO), outs=[self.FOO], wdir="."
)
d = load_stage_file(stage.relpath)
self.assertEqual(d[Stage.PARAM_WDIR], ".")
self.assertNotIn(Stage.PARAM_WDIR, d.keys())
stage = self.dvc.run(
cmd="echo test > {}".format(self.BAR), outs=[self.BAR]
)
d = load_stage_file(stage.relpath)
self.assertEqual(d[Stage.PARAM_WDIR], ".")
self.assertNotIn(Stage.PARAM_WDIR, d.keys())
def test_fname_changes_path_and_wdir(self):
dname = "dir"
+2 -8
View File
@@ -102,16 +102,10 @@ class TestDefaultWorkingDirectory(TestDvc):
)
d = stage.dumpd()
self.assertEqual(d[stage.PARAM_WDIR], ".")
self.assertNotIn(Stage.PARAM_WDIR, d.keys())
d = load_stage_file(stage.relpath)
self.assertEqual(d[stage.PARAM_WDIR], ".")
del d[stage.PARAM_WDIR]
dump_stage_file(stage.relpath, d)
d = load_stage_file(stage.relpath)
self.assertIsNone(d.get(stage.PARAM_WDIR))
self.assertNotIn(Stage.PARAM_WDIR, d.keys())
with self.dvc.state:
stage = Stage.load(self.dvc, stage.relpath)