diff --git a/dvc/command/plots.py b/dvc/command/plots.py index 04e5b2918..27ffd16f2 100644 --- a/dvc/command/plots.py +++ b/dvc/command/plots.py @@ -65,12 +65,11 @@ class CmdPlots(CmdBase): html = PAGE_HTML.format(divs="\n".join(divs)) path = self.args.out or "plots.html" + path = os.path.join(os.getcwd(), path) with open(path, "w") as fobj: fobj.write(html) - logger.info( - "file://{}".format(os.path.join(self.repo.root_dir, path)) - ) + logger.info(f"file://{path}") except DvcException: logger.exception("") diff --git a/tests/func/metrics/plots/test_show.py b/tests/func/metrics/plots/test_show.py index d80910ace..1fe909eb0 100644 --- a/tests/func/metrics/plots/test_show.py +++ b/tests/func/metrics/plots/test_show.py @@ -6,6 +6,7 @@ from collections import OrderedDict import pytest +from dvc.main import main from dvc.repo import Repo from dvc.repo.plots.data import ( JSONPlotData, @@ -693,3 +694,20 @@ def test_show_no_repo(tmp_dir): dvc = Repo(uninitialized=True) dvc.plots.show(["metric.json"]) + + +def test_show_from_subdir(tmp_dir, dvc, caplog): + subdir = tmp_dir / "subdir" + + subdir.mkdir() + metric = [ + {"first_val": 100, "val": 2}, + {"first_val": 200, "val": 3}, + ] + _write_json(subdir, metric, "metric.json") + + with subdir.chdir(), caplog.at_level(logging.INFO, "dvc"): + assert main(["plots", "show", "metric.json"]) == 0 + + assert f"file://{str(subdir)}" in caplog.text + assert (subdir / "plots.html").exists()