Skip to content

Commit a309e8d

Browse files
committed
fix(hansbug): remove named temporary file when rendering images
1 parent 49c17d9 commit a309e8d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

treevalue/entry/cli/graph.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ def _save_source_code(g: Digraph, path: str):
6060
file.write(g.source)
6161

6262

63+
# Do not reopen an opened file in windows, it may cause PermissionDenied
64+
# See: https://stackoverflow.com/a/23212515/6995899
6365
def _save_image(g: Digraph, path: str, fmt: str):
64-
with tempfile.NamedTemporaryFile() as tmpfile:
65-
svg_file = g.render(tmpfile.name, format=fmt)
66+
with tempfile.TemporaryDirectory() as tmpdir:
67+
svg_file = g.render(f'{tmpdir}.gv', format=fmt)
6668
shutil.copy(svg_file, path)
6769

6870

0 commit comments

Comments
 (0)