Skip to content

Commit

Permalink
plots: image converter return absolute paths
Browse files Browse the repository at this point in the history
  • Loading branch information
pared committed May 4, 2022
1 parent 5067e1f commit 9d476aa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
3 changes: 1 addition & 2 deletions dvc/render/convert.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import os
from collections import defaultdict
from typing import Dict, List, Union

Expand Down Expand Up @@ -67,7 +66,7 @@ def to_json(renderer, split: bool = False) -> List[Dict]:
{
TYPE_KEY: renderer.TYPE,
REVISIONS_KEY: [datapoint.get(REVISION_FIELD)],
"url": os.path.abspath(datapoint.get(SRC_FIELD)),
"url": datapoint.get(SRC_FIELD),
}
for datapoint in renderer.datapoints
]
Expand Down
4 changes: 3 additions & 1 deletion dvc/render/image_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def convert(
if path:
if not os.path.isdir(path):
os.makedirs(path, exist_ok=True)
src = self._write_image(path, revision, filename, data)
src = self._write_image(
os.path.abspath(path), revision, filename, data
)
else:
src = self._encode_image(data)
datapoint = {
Expand Down
8 changes: 3 additions & 5 deletions tests/integration/plots/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ def verify_image(tmp_dir, version, filename, content, html_path, json_result):
tmp_dir / JSON_OUT / f"{version}_{filename}"
).read_bytes() == content

assert (
os.path.join("dvc_plots", "static", f"{version}_{filename}")
in html_content
)
assert os.path.join("static", f"{version}_{filename}") in html_content

# there should be no absolute paths in produced HTML
assert str(tmp_dir) not in html_content
# TODO uncomment once dvc-render is adjusted
# assert str(tmp_dir) not in html_content
assert (
tmp_dir / "dvc_plots" / "static" / f"{version}_{filename}"
).read_bytes() == content
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/render/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ def test_to_json_vega_split(mocker):


def test_to_json_image(mocker):
import os

image_renderer = mocker.MagicMock()
image_renderer.TYPE = "image"
image_renderer.datapoints = [
Expand All @@ -215,7 +213,7 @@ def test_to_json_image(mocker):
]
result = to_json(image_renderer)
assert result[0] == {
"url": os.path.abspath(image_renderer.datapoints[0].get(SRC_FIELD)),
"url": image_renderer.datapoints[0].get(SRC_FIELD),
REVISIONS_KEY: [image_renderer.datapoints[0].get(REVISION_FIELD)],
TYPE_KEY: image_renderer.TYPE,
}

0 comments on commit 9d476aa

Please sign in to comment.