@@ -878,9 +878,14 @@ def rc_params(fail_on_error=False):
878
878
return rc_params_from_file (fname , fail_on_error )
879
879
880
880
881
- def rc_params_from_file (fname , fail_on_error = False ):
882
- """Return a :class:`matplotlib.RcParams` instance from the
883
- contents of the given filename.
881
+ _error_details_fmt = 'line #%d\n \t "%s"\n \t in file "%s"'
882
+
883
+
884
+ def rc_params_in_file (fname , fail_on_error = False ):
885
+ """Return :class:`matplotlib.RcParams` from the contents of the given file.
886
+
887
+ Unlike `rc_params_from_file`, the configuration class only contains the
888
+ parameters specified in the file (i.e. default values are not filled in).
884
889
"""
885
890
cnt = 0
886
891
rc_temp = {}
@@ -891,8 +896,8 @@ def rc_params_from_file(fname, fail_on_error=False):
891
896
if not strippedline : continue
892
897
tup = strippedline .split (':' , 1 )
893
898
if len (tup ) != 2 :
894
- warnings . warn ( 'Illegal line #%d \n \t %s \n \t in file "%s"' % \
895
- ( cnt , line , fname ) )
899
+ error_details = _error_details_fmt % ( cnt , line , fname )
900
+ warnings . warn ( 'Illegal %s' % error_details )
896
901
continue
897
902
key , val = tup
898
903
key = key .strip ()
@@ -902,34 +907,35 @@ def rc_params_from_file(fname, fail_on_error=False):
902
907
(fname , cnt ))
903
908
rc_temp [key ] = (val , line , cnt )
904
909
905
- ret = RcParams ([(key , default ) for key , (default , _ ) in \
906
- six .iteritems (defaultParams )])
910
+ config = RcParams ()
907
911
908
912
for key in ('verbose.level' , 'verbose.fileo' ):
909
913
if key in rc_temp :
910
914
val , line , cnt = rc_temp .pop (key )
911
915
if fail_on_error :
912
- ret [key ] = val # try to convert to proper type or raise
916
+ config [key ] = val # try to convert to proper type or raise
913
917
else :
914
- try : ret [key ] = val # try to convert to proper type or skip
918
+ try :
919
+ config [key ] = val # try to convert to proper type or skip
915
920
except Exception as msg :
916
- warnings .warn ('Bad val "%s" on line #%d\n \t "%s"\n \t in file \
917
- "%s"\n \t %s' % (val , cnt , line , fname , msg ))
918
-
919
- verbose .set_level (ret ['verbose.level' ])
920
- verbose .set_fileo (ret ['verbose.fileo' ])
921
+ error_details = _error_details_fmt % (cnt , line , fname )
922
+ warnings .warn ('Bad val "%s" on %s\n \t %s' %
923
+ (val , error_details , msg ))
921
924
922
925
for key , (val , line , cnt ) in six .iteritems (rc_temp ):
923
926
if key in defaultParams :
924
927
if fail_on_error :
925
- ret [key ] = val # try to convert to proper type or raise
928
+ config [key ] = val # try to convert to proper type or raise
926
929
else :
927
- try : ret [key ] = val # try to convert to proper type or skip
930
+ try :
931
+ config [key ] = val # try to convert to proper type or skip
928
932
except Exception as msg :
929
- warnings .warn ('Bad val "%s" on line #%d\n \t "%s"\n \t in file \
930
- "%s"\n \t %s' % (val , cnt , line , fname , msg ))
933
+ error_details = _error_details_fmt % (cnt , line , fname )
934
+ warnings .warn ('Bad val "%s" on %s\n \t %s' %
935
+ (val , error_details , msg ))
931
936
elif key in _deprecated_ignore_map :
932
- warnings .warn ('%s is deprecated. Update your matplotlibrc to use %s instead.' % (key , _deprecated_ignore_map [key ]))
937
+ warnings .warn ('%s is deprecated. Update your matplotlibrc to use '
938
+ '%s instead.' % (key , _deprecated_ignore_map [key ]))
933
939
934
940
else :
935
941
print ("""
@@ -939,21 +945,45 @@ def rc_params_from_file(fname, fail_on_error=False):
939
945
http://matplotlib.sf.net/_static/matplotlibrc or from the matplotlib source
940
946
distribution""" % (key , cnt , fname ), file = sys .stderr )
941
947
942
- if ret ['datapath' ] is None :
943
- ret ['datapath' ] = get_data_path ()
948
+ return config
949
+
950
+
951
+
952
+
953
+ def rc_params_from_file (fname , fail_on_error = False ):
954
+ """Return :class:`matplotlib.RcParams` from the contents of the given file.
955
+
956
+ Parameters
957
+ ----------
958
+ fname : str
959
+ Name of file parsed for matplotlib settings.
960
+ fail_on_error : bool
961
+ If True, raise an error when the parser fails to convert a parameter.
962
+ """
963
+
964
+ config = RcParams ([(key , default )
965
+ for key , (default , _ ) in six .iteritems (defaultParams )])
966
+
967
+ config .update (rc_params_in_file (fname , fail_on_error ))
968
+
969
+ verbose .set_level (config ['verbose.level' ])
970
+ verbose .set_fileo (config ['verbose.fileo' ])
971
+
972
+ if config ['datapath' ] is None :
973
+ config ['datapath' ] = get_data_path ()
944
974
945
- if not ret ['text.latex.preamble' ] == ['' ]:
975
+ if not config ['text.latex.preamble' ] == ['' ]:
946
976
verbose .report ("""
947
977
*****************************************************************
948
978
You have the following UNSUPPORTED LaTeX preamble customizations:
949
979
%s
950
980
Please do not ask for support with these customizations active.
951
981
*****************************************************************
952
- """ % '\n ' .join (ret ['text.latex.preamble' ]), 'helpful' )
982
+ """ % '\n ' .join (config ['text.latex.preamble' ]), 'helpful' )
953
983
954
984
verbose .report ('loaded rc file %s' % fname )
955
985
956
- return ret
986
+ return config
957
987
958
988
959
989
# this is the instance used by the matplotlib classes
0 commit comments