@@ -783,8 +783,6 @@ def _rc_params_in_file(fname, fail_on_error=False):
783
783
Unlike `rc_params_from_file`, the configuration class only contains the
784
784
parameters specified in the file (i.e. default values are not filled in).
785
785
"""
786
- _error_details_fmt = 'line #%d\n \t "%s"\n \t in file "%s"'
787
-
788
786
rc_temp = {}
789
787
with _open_file_or_url (fname ) as fd :
790
788
try :
@@ -794,15 +792,15 @@ def _rc_params_in_file(fname, fail_on_error=False):
794
792
continue
795
793
tup = strippedline .split (':' , 1 )
796
794
if len (tup ) != 2 :
797
- error_details = _error_details_fmt % ( line_no , line , fname )
798
- _log . warning ( 'Illegal %s' , error_details )
795
+ _log . warning ( 'Missing colon in file %r , line %d (%r)' ,
796
+ fname , line_no , line . rstrip ( ' \n ' ) )
799
797
continue
800
798
key , val = tup
801
799
key = key .strip ()
802
800
val = val .strip ()
803
801
if key in rc_temp :
804
- _log .warning ('Duplicate key in file %r line #%d. ' ,
805
- fname , line_no )
802
+ _log .warning ('Duplicate key in file %r, line %d (%r) ' ,
803
+ fname , line_no , line . rstrip ( ' \n ' ) )
806
804
rc_temp [key ] = (val , line , line_no )
807
805
except UnicodeDecodeError :
808
806
_log .warning ('Cannot decode configuration file %s with encoding '
@@ -822,22 +820,22 @@ def _rc_params_in_file(fname, fail_on_error=False):
822
820
try :
823
821
config [key ] = val # try to convert to proper type or skip
824
822
except Exception as msg :
825
- error_details = _error_details_fmt % (line_no , line , fname )
826
- _log .warning ('Bad val %r on %s\n \t %s' ,
827
- val , error_details , msg )
823
+ _log .warning ('Bad value in file %r, line %d (%r): %s' ,
824
+ fname , line_no , line .rstrip ('\n ' ), msg )
828
825
elif key in _deprecated_ignore_map :
829
826
version , alt_key = _deprecated_ignore_map [key ]
830
827
cbook .warn_deprecated (
831
828
version , name = key , alternative = alt_key ,
832
829
addendum = "Please update your matplotlibrc." )
833
830
else :
834
831
version = 'master' if '.post' in __version__ else f'v{ __version__ } '
835
- print (f"""
836
- Bad key "{ key } " on line { line_no } in
837
- { fname } .
832
+ _log .warning ("""
833
+ Bad key %(key)s in file %(fname)s, line %(line_no)s (%(line)r)
838
834
You probably need to get an updated matplotlibrc file from
839
- https://github.com/matplotlib/matplotlib/blob/{ version } /matplotlibrc.template
840
- or from the matplotlib source distribution""" , file = sys .stderr )
835
+ https://github.com/matplotlib/matplotlib/blob/%(version)s/matplotlibrc.template
836
+ or from the matplotlib source distribution""" ,
837
+ dict (key = key , fname = fname , line_no = line_no ,
838
+ line = line .rstrip ('\n ' ), version = version ))
841
839
return config
842
840
843
841
0 commit comments