11"""A directive to generate an embedded svg image using Graphviz/Sketchviz
22backend parsers
33"""
4+
5+ import hashlib
46import os
5- from tempfile import NamedTemporaryFile
67import subprocess
7- import hashlib
8+ from tempfile import NamedTemporaryFile
89
9- from docutils import nodes
1010from ablog .commands import find_confdir , read_conf
11+ from docutils import nodes
1112from docutils .parsers .rst import Directive
1213from jinja2 import BaseLoader , Environment
1314from sphinx .application import Sphinx
@@ -55,10 +56,8 @@ def run(self):
5556 temp_name = None
5657 h = hashlib .new ("sha256" )
5758 with NamedTemporaryFile (
58- mode = "w" ,
59- encoding = "utf-8" ,
60- delete = False ,
61- delete_on_close = False ) as fd :
59+ mode = "w" , encoding = "utf-8" , delete = False , delete_on_close = False
60+ ) as fd :
6261 for content in self .content :
6362 line = f"{ content } \n "
6463 h .update (line .encode ())
@@ -68,8 +67,7 @@ def run(self):
6867 filename = h .digest ().hex ()
6968 filename = f"{ filename } { FILENAME_EXT } "
7069 save_path = os .path .join (save_path , filename )
71- subprocess .run (
72- ["sketchviz" , temp_name , save_path ], check = True )
70+ subprocess .run (["sketchviz" , temp_name , save_path ], check = True )
7371 os .remove (temp_name )
7472 logger .info ("Sketchviz: Created SVG image: {save_path}" )
7573
0 commit comments