Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4874e4e

Browse files
committed
Add a helpful note when raising KeyError from dviread.PsFonts
So if you follow the troubleshooting instructions and rerun with --verbose-helpful you get a hint about the usual reason for #6516.
1 parent 93fad55 commit 4874e4e

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

lib/matplotlib/dviread.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import numpy as np
3434
import struct
3535
import sys
36+
import textwrap
3637
import os
3738

3839
if six.PY3:
@@ -798,16 +799,33 @@ class PsfontsMap(object):
798799
while the pdf-related files perhaps only avoid the "Base 14" pdf
799800
fonts. But the user may have configured these files differently.
800801
"""
801-
__slots__ = ('_font',)
802+
__slots__ = ('_font', '_filename')
802803

803804
def __init__(self, filename):
804805
self._font = {}
806+
self._filename = filename
807+
if six.PY3 and isinstance(filename, bytes):
808+
self._filename = filename.decode('ascii', errors='replace')
805809
with open(filename, 'rt') as file:
806810
self._parse(file)
807811

808812
def __getitem__(self, texname):
809813
assert(isinstance(texname, bytes))
810-
result = self._font[texname]
814+
try:
815+
result = self._font[texname]
816+
except KeyError:
817+
matplotlib.verbose.report(textwrap.fill
818+
('A PostScript file for the font whose TeX name is "%s" '
819+
'could not be found in the file "%s". The dviread module '
820+
'can only handle fonts that have an associated PostScript '
821+
'font file. '
822+
'This problem can often be solved by installing '
823+
'a suitable PostScript font package in your (TeX) '
824+
'package manager.' % (texname.decode('ascii'),
825+
self._filename),
826+
break_on_hyphens=False, break_long_words=False),
827+
'helpful')
828+
raise
811829
fn, enc = result.filename, result.encoding
812830
if fn is not None and not fn.startswith(b'/'):
813831
fn = find_tex_file(fn)

0 commit comments

Comments
 (0)