Skip to content

Commit

Permalink
fix mypy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dberenbaum committed May 13, 2023
1 parent 0bad0e4 commit 393fcf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/dvc_render/markdown.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from typing import TYPE_CHECKING, List, Optional, Union
from typing import TYPE_CHECKING, List, Optional

from .exceptions import MissingPlaceholderError

Expand Down Expand Up @@ -48,7 +48,7 @@ def render_markdown(
renderers: List["Renderer"],
output_file: Optional["StrPath"] = None,
template_path: Optional["StrPath"] = None,
) -> Union["StrPath", "str"]:
) -> "StrPath":
"User renderers to fill an Markdown template and write to path."
output_path = None
if output_file:
Expand All @@ -65,7 +65,7 @@ def render_markdown(
for renderer in renderers:
document.with_element(renderer.generate_markdown(report_path=output_path))

if output_file:
if output_file and output_path:
output_path.write_text(document.embed(), encoding="utf8")

return output_file
Expand Down
7 changes: 5 additions & 2 deletions src/dvc_render/vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ def generate_markdown(self, report_path=None) -> str:

data = list_dict_to_dict_list(self.datapoints)
if data:
output_file = io.BytesIO()
if report_path:
report_folder = Path(report_path).parent
output_file = report_folder / self.name
output_file = output_file.with_suffix(".png")
output_file.parent.mkdir(exist_ok=True, parents=True)
else:
output_file = io.BytesIO() # type: ignore

x = self.properties.get("x")
y = self.properties.get("y")
Expand All @@ -127,7 +128,9 @@ def generate_markdown(self, report_path=None) -> str:
if report_path:
return f"\n![{self.name}]({output_file.relative_to(report_folder)})"

base64_str = base64.b64encode(output_file.getvalue()).decode()
base64_str = base64.b64encode(
output_file.getvalue()
).decode() # type: ignore
src = f"data:image/png;base64,{base64_str}"

return f"\n![{self.name}]({src})"
Expand Down

0 comments on commit 393fcf8

Please sign in to comment.