Use io.BytesIO rather than writing to a temp file

This commit is contained in:
Grant Sanderson 2022-12-19 16:03:16 -08:00
parent 8d05431b7b
commit 71c9144952

View file

@ -5,6 +5,7 @@ from xml.etree import ElementTree as ET
import numpy as np
import svgelements as se
import io
from manimlib.constants import RIGHT
from manimlib.logger import log
@ -118,13 +119,13 @@ class SVGMobject(VMobject):
file_path = self.get_file_path()
element_tree = ET.parse(file_path)
new_tree = self.modify_xml_tree(element_tree)
# Create a temporary svg file to dump modified svg to be parsed
root, ext = os.path.splitext(file_path)
modified_file_path = root + "_" + ext
new_tree.write(modified_file_path)
svg = se.SVG.parse(modified_file_path)
os.remove(modified_file_path)
# New svg based on tree contents
data_stream = io.BytesIO()
new_tree.write(data_stream)
data_stream.seek(0)
svg = se.SVG.parse(data_stream)
data_stream.close()
mobjects = self.get_mobjects_from(svg)
self.add(*mobjects)