@@ -792,9 +792,6 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
792
792
fail_on_error : bool, default: False
793
793
Whether invalid entries should result in an exception or a warning.
794
794
"""
795
-
796
- _error_details_fmt = 'line #%d\n \t "%s"\n \t in file "%s"'
797
-
798
795
rc_temp = {}
799
796
with _open_file_or_url (fname ) as fd :
800
797
try :
@@ -805,15 +802,15 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
805
802
continue
806
803
tup = strippedline .split (':' , 1 )
807
804
if len (tup ) != 2 :
808
- error_details = _error_details_fmt % ( line_no , line , fname )
809
- _log . warning ( 'Illegal %s' , error_details )
805
+ _log . warning ( 'Missing colon in file %r , line %d (%r)' ,
806
+ fname , line_no , line . rstrip ( ' \n ' ) )
810
807
continue
811
808
key , val = tup
812
809
key = key .strip ()
813
810
val = val .strip ()
814
811
if key in rc_temp :
815
- _log .warning ('Duplicate key in file %r line #%d. ' ,
816
- fname , line_no )
812
+ _log .warning ('Duplicate key in file %r, line %d (%r) ' ,
813
+ fname , line_no , line . rstrip ( ' \n ' ) )
817
814
rc_temp [key ] = (val , line , line_no )
818
815
except UnicodeDecodeError :
819
816
_log .warning ('Cannot decode configuration file %s with encoding '
@@ -833,22 +830,22 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
833
830
try :
834
831
config [key ] = val # try to convert to proper type or skip
835
832
except Exception as msg :
836
- error_details = _error_details_fmt % (line_no , line , fname )
837
- _log .warning ('Bad val %r on %s\n \t %s' ,
838
- val , error_details , msg )
833
+ _log .warning ('Bad value in file %r, line %d (%r): %s' ,
834
+ fname , line_no , line .rstrip ('\n ' ), msg )
839
835
elif key in _deprecated_ignore_map :
840
836
version , alt_key = _deprecated_ignore_map [key ]
841
837
cbook .warn_deprecated (
842
838
version , name = key , alternative = alt_key ,
843
839
addendum = "Please update your matplotlibrc." )
844
840
else :
845
841
version = 'master' if '.post' in __version__ else f'v{ __version__ } '
846
- print (f"""
847
- Bad key "{ key } " on line { line_no } in
848
- { fname } .
842
+ _log .warning ("""
843
+ Bad key %(key)s in file %(fname)s, line %(line_no)s (%(line)r)
849
844
You probably need to get an updated matplotlibrc file from
850
- https://github.com/matplotlib/matplotlib/blob/{ version } /matplotlibrc.template
851
- or from the matplotlib source distribution""" , file = sys .stderr )
845
+ https://github.com/matplotlib/matplotlib/blob/%(version)s/matplotlibrc.template
846
+ or from the matplotlib source distribution""" ,
847
+ dict (key = key , fname = fname , line_no = line_no ,
848
+ line = line .rstrip ('\n ' ), version = version ))
852
849
return config
853
850
854
851
0 commit comments