Skip to content

Commit b07d604

Browse files
committed
Use TemporaryDirectory instead of NamedTemporaryFile
1 parent c784919 commit b07d604

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,20 +970,21 @@ def print_figure_impl(fh):
970970

971971
# give ttconv a subsetted font
972972
# along with updated glyph_ids
973-
with tempfile.NamedTemporaryFile(
974-
suffix=".ttf"
975-
) as tmp:
973+
with TemporaryDirectory() as tmpdir:
974+
tmpfile = os.path.join(tmpdir, "tmp.ttf")
976975
font = FT2Font(fontdata)
977976
glyph_ids = [
978977
font.get_char_index(c) for c in chars
979978
]
980-
tmp.write(fontdata.getvalue())
981-
tmp.flush()
979+
980+
with open(tmpfile, 'wb') as tmp:
981+
tmp.write(fontdata.getvalue())
982+
tmp.flush()
982983

983984
# TODO: allow convert_ttf_to_ps
984985
# to input file objects (BytesIO)
985986
convert_ttf_to_ps(
986-
os.fsencode(tmp.name),
987+
os.fsencode(tmpfile),
987988
fh,
988989
fonttype,
989990
glyph_ids,

0 commit comments

Comments
 (0)