@@ -792,9 +792,6 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
792792 fail_on_error : bool, default: False
793793 Whether invalid entries should result in an exception or a warning.
794794 """
795-
796- _error_details_fmt = 'line #%d\n \t "%s"\n \t in file "%s"'
797-
798795 rc_temp = {}
799796 with _open_file_or_url (fname ) as fd :
800797 try :
@@ -805,15 +802,15 @@ def _rc_params_in_file(fname, transform=lambda x: x, fail_on_error=False):
805802 continue
806803 tup = strippedline .split (':' , 1 )
807804 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 ' ) )
810807 continue
811808 key , val = tup
812809 key = key .strip ()
813810 val = val .strip ()
814811 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 ' ) )
817814 rc_temp [key ] = (val , line , line_no )
818815 except UnicodeDecodeError :
819816 _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):
833830 try :
834831 config [key ] = val # try to convert to proper type or skip
835832 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 )
839835 elif key in _deprecated_ignore_map :
840836 version , alt_key = _deprecated_ignore_map [key ]
841837 cbook .warn_deprecated (
842838 version , name = key , alternative = alt_key ,
843839 addendum = "Please update your matplotlibrc." )
844840 else :
845841 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)
849844You 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 ))
852849 return config
853850
854851
0 commit comments