Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plots: image converter return absolute paths #7664

Merged
merged 1 commit into from May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions dvc/render/convert.py
@@ -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
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
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}"
Comment on lines -70 to 76
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this belong to integration tests? HTML content is not really used by vscode, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true, currently I implemented html checks to make sure everything works as expected. In further work we will need to split that. I am thinking how to do it without too much test duplication.

).read_bytes() == content
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/render/test_convert.py
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,
}