@@ -911,27 +911,25 @@ def _rc_params_in_file(fname, fail_on_error=False):
911
911
Unlike `rc_params_from_file`, the configuration class only contains the
912
912
parameters specified in the file (i.e. default values are not filled in).
913
913
"""
914
- cnt = 0
915
914
rc_temp = {}
916
915
with _open_file_or_url (fname ) as fd :
917
916
try :
918
- for line in fd :
919
- cnt += 1
917
+ for line_no , line in enumerate (fd , 1 ):
920
918
strippedline = line .split ('#' , 1 )[0 ].strip ()
921
919
if not strippedline :
922
920
continue
923
921
tup = strippedline .split (':' , 1 )
924
922
if len (tup ) != 2 :
925
- error_details = _error_details_fmt % (cnt , line , fname )
923
+ error_details = _error_details_fmt % (line_no , line , fname )
926
924
_log .warning ('Illegal %s' , error_details )
927
925
continue
928
926
key , val = tup
929
927
key = key .strip ()
930
928
val = val .strip ()
931
929
if key in rc_temp :
932
930
_log .warning ('Duplicate key in file %r line #%d.' ,
933
- fname , cnt )
934
- rc_temp [key ] = (val , line , cnt )
931
+ fname , line_no )
932
+ rc_temp [key ] = (val , line , line_no )
935
933
except UnicodeDecodeError :
936
934
_log .warning ('Cannot decode configuration file %s with encoding '
937
935
'%s, check LANG and LC_* variables.' ,
@@ -942,15 +940,15 @@ def _rc_params_in_file(fname, fail_on_error=False):
942
940
943
941
config = RcParams ()
944
942
945
- for key , (val , line , cnt ) in rc_temp .items ():
943
+ for key , (val , line , line_no ) in rc_temp .items ():
946
944
if key in defaultParams :
947
945
if fail_on_error :
948
946
config [key ] = val # try to convert to proper type or raise
949
947
else :
950
948
try :
951
949
config [key ] = val # try to convert to proper type or skip
952
950
except Exception as msg :
953
- error_details = _error_details_fmt % (cnt , line , fname )
951
+ error_details = _error_details_fmt % (line_no , line , fname )
954
952
_log .warning ('Bad val %r on %s\n \t %s' ,
955
953
val , error_details , msg )
956
954
elif key in _deprecated_ignore_map :
@@ -959,14 +957,13 @@ def _rc_params_in_file(fname, fail_on_error=False):
959
957
version , name = key , alternative = alt_key ,
960
958
addendum = "Please update your matplotlibrc." )
961
959
else :
962
- print ("""
963
- Bad key "%s" on line %d in
964
- %s.
960
+ version = 'master' if '.post' in __version__ else f'v{ __version__ } '
961
+ print (f"""
962
+ Bad key "{ key } " on line { line_no } in
963
+ { fname } .
965
964
You probably need to get an updated matplotlibrc file from
966
- http://github.com/matplotlib/matplotlib/blob/master/matplotlibrc.template
967
- or from the matplotlib source distribution""" % (key , cnt , fname ),
968
- file = sys .stderr )
969
-
965
+ https://github.com/matplotlib/matplotlib/blob/{ version } /matplotlibrc.template
966
+ or from the matplotlib source distribution""" , file = sys .stderr )
970
967
return config
971
968
972
969
0 commit comments