Skip to content

Commit 3403046

Browse files
author
Dave Berenbaum
authored
dvcyaml: write to cwd instead of git root (#729)
* dvcyaml: write to cwd instead of git root * revert changes to lightning tests * refactor dvcyaml
1 parent 0df9dc5 commit 3403046

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

src/dvclive/live.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
resume: bool = False,
6464
report: Optional[str] = None,
6565
save_dvc_exp: bool = True,
66-
dvcyaml: Union[str, bool] = True,
66+
dvcyaml: Union[str, bool] = "dvc.yaml",
6767
cache_images: bool = False,
6868
exp_name: Optional[str] = None,
6969
exp_message: Optional[str] = None,
@@ -191,13 +191,7 @@ def _init_dvc_file(self) -> str:
191191
if os.path.basename(self._dvcyaml) == "dvc.yaml":
192192
return self._dvcyaml
193193
raise InvalidDvcyamlError
194-
if self._dvc_repo is not None:
195-
return os.path.join(self._dvc_repo.root_dir, "dvc.yaml")
196-
logger.warning(
197-
"Can't infer dvcyaml path without a DVC repo. "
198-
"`dvc.yaml` file will not be written."
199-
)
200-
return ""
194+
return "dvc.yaml"
201195

202196
def _init_dvc_pipeline(self):
203197
if os.getenv(env.DVC_EXP_BASELINE_REV, None):
@@ -543,8 +537,7 @@ def make_report(self):
543537

544538
@catch_and_warn(DvcException, logger)
545539
def make_dvcyaml(self):
546-
if self.dvc_file:
547-
make_dvcyaml(self)
540+
make_dvcyaml(self)
548541

549542
@catch_and_warn(DvcException, logger)
550543
def post_to_studio(self, event):

tests/test_dvc.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_exp_save_on_end(tmp_dir, save, mocked_dvc_repo):
3434
assert live._exp_name is not None
3535
mocked_dvc_repo.experiments.save.assert_called_with(
3636
name=live._exp_name,
37-
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
37+
include_untracked=[live.dir, "dvc.yaml"],
3838
force=True,
3939
message=None,
4040
)
@@ -79,7 +79,7 @@ def test_exp_save_run_on_dvc_repro(tmp_dir, mocker):
7979

8080
dvc_repo.experiments.save.assert_called_with(
8181
name=live._exp_name,
82-
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
82+
include_untracked=[live.dir, "dvc.yaml"],
8383
force=True,
8484
message=None,
8585
)
@@ -102,7 +102,7 @@ def test_exp_save_with_dvc_files(tmp_dir, mocker):
102102

103103
dvc_repo.experiments.save.assert_called_with(
104104
name=live._exp_name,
105-
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
105+
include_untracked=[live.dir, "dvc.yaml"],
106106
force=True,
107107
message=None,
108108
)
@@ -175,7 +175,7 @@ def test_exp_save_message(tmp_dir, mocked_dvc_repo):
175175
live.end()
176176
mocked_dvc_repo.experiments.save.assert_called_with(
177177
name=live._exp_name,
178-
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
178+
include_untracked=[live.dir, "dvc.yaml"],
179179
force=True,
180180
message="Custom message",
181181
)
@@ -186,7 +186,7 @@ def test_exp_save_name(tmp_dir, mocked_dvc_repo):
186186
live.end()
187187
mocked_dvc_repo.experiments.save.assert_called_with(
188188
name="custom-name",
189-
include_untracked=[live.dir, str(tmp_dir / "dvc.yaml")],
189+
include_untracked=[live.dir, "dvc.yaml"],
190190
force=True,
191191
message=None,
192192
)

tests/test_log_artifact.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_log_artifact_with_save_dvc_exp(tmp_dir, mocker, mocked_dvc_repo):
5858
live.log_artifact("data")
5959
mocked_dvc_repo.experiments.save.assert_called_with(
6060
name=live._exp_name,
61-
include_untracked=[live.dir, "data", ".gitignore", str(tmp_dir / "dvc.yaml")],
61+
include_untracked=[live.dir, "data", ".gitignore", "dvc.yaml"],
6262
force=True,
6363
message=None,
6464
)

tests/test_make_dvcyaml.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,33 @@ def test_make_dvcyaml(tmp_dir, mocked_dvc_repo, dvcyaml):
440440

441441

442442
def test_make_dvcyaml_no_repo(tmp_dir, mocker):
443-
logger = mocker.patch("dvclive.live.logger")
444443
dvclive = Live("logs")
445444
dvclive.make_dvcyaml()
446445

447-
assert not os.path.exists("dvc.yaml")
448-
assert not dvclive.dvc_file
449-
logger.warning.assert_any_call(
450-
"Can't infer dvcyaml path without a DVC repo. "
451-
"`dvc.yaml` file will not be written."
452-
)
446+
assert os.path.exists("dvc.yaml")
453447

454448

455449
def test_make_dvcyaml_invalid(tmp_dir, mocker):
456450
with pytest.raises(InvalidDvcyamlError):
457451
Live("logs", dvcyaml="invalid")
452+
453+
454+
def test_make_dvcyaml_on_end(tmp_dir, mocker):
455+
dvclive = Live("logs")
456+
dvclive.end()
457+
458+
assert os.path.exists("dvc.yaml")
459+
460+
461+
def test_make_dvcyaml_false(tmp_dir, mocker):
462+
dvclive = Live("logs", dvcyaml=False)
463+
dvclive.end()
464+
465+
assert not os.path.exists("dvc.yaml")
466+
467+
468+
def test_make_dvcyaml_none(tmp_dir, mocker):
469+
dvclive = Live("logs", dvcyaml=None)
470+
dvclive.end()
471+
472+
assert not os.path.exists("dvc.yaml")

0 commit comments

Comments
 (0)