File tree Expand file tree Collapse file tree 4 files changed +14
-7
lines changed
Filter options
Expand file tree Collapse file tree 4 files changed +14
-7
lines changed
Original file line number Diff line number Diff line change @@ -842,6 +842,12 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
842
842
transform = lambda line : line [1 :] if line .startswith ("#" ) else line ,
843
843
fail_on_error = True )
844
844
dict .update (rcParamsDefault , rcsetup ._hardcoded_defaults )
845
+ # Normally, the default matplotlibrc file contains *no* entry for backend (the
846
+ # corresponding line starts with ##, not #; we fill on _auto_backend_sentinel
847
+ # in that case. However, packagers can set a different default backend
848
+ # (resulting in a normal `#backend: foo` line) in which case we should *not*
849
+ # fill in _auto_backend_sentinel.
850
+ dict .setdefault (rcParamsDefault , "backend" , rcsetup ._auto_backend_sentinel )
845
851
rcParams = RcParams () # The global instance.
846
852
dict .update (rcParams , dict .items (rcParamsDefault ))
847
853
dict .update (rcParams , _rc_params_in_file (matplotlib_fname ()))
Original file line number Diff line number Diff line change 78
78
## PS PDF SVG Template
79
79
## You can also deploy your own backend outside of Matplotlib by referring to
80
80
## the module name (which must be in the PYTHONPATH) as 'module://my_backend'.
81
- #backend: Agg
81
+ ## backend: Agg
82
82
83
83
## The port to use for the web server in the WebAgg backend.
84
84
#webagg.port: 8988
Original file line number Diff line number Diff line change @@ -1411,14 +1411,13 @@ def _convert_validator_spec(key, conv):
1411
1411
"_internal.classic_mode" : validate_bool
1412
1412
}
1413
1413
_hardcoded_defaults = { # Defaults not inferred from matplotlibrc.template...
1414
- # ... because it can"t be:
1415
- "backend" : _auto_backend_sentinel ,
1416
1414
# ... because they are private:
1417
1415
"_internal.classic_mode" : False ,
1418
1416
# ... because they are deprecated:
1419
1417
"animation.avconv_path" : "avconv" ,
1420
1418
"animation.avconv_args" : [],
1421
1419
"animation.html_args" : [],
1420
+ # backend is handled separately when constructing rcParamsDefault.
1422
1421
}
1423
1422
_validators = {k : _convert_validator_spec (k , conv )
1424
1423
for k , conv in _validators .items ()}
Original file line number Diff line number Diff line change @@ -194,16 +194,18 @@ def build_extensions(self):
194
194
195
195
196
196
def update_matplotlibrc (path ):
197
- # Update the matplotlibrc file if packagers want to change the default
198
- # backend.
197
+ # If packagers want to change the default backend, insert a `#backend: ...`
198
+ # line. Otherwise, use the default `##backend: Agg` which has no effect
199
+ # even after decommenting, which allows _auto_backend_sentinel to be filled
200
+ # in at import time.
199
201
template_lines = path .read_text ().splitlines (True )
200
202
backend_line_idx , = [ # Also asserts that there is a single such line.
201
203
idx for idx , line in enumerate (template_lines )
202
- if line . startswith ( "#backend:" ) ]
204
+ if "#backend:" in line ]
203
205
template_lines [backend_line_idx ] = (
204
206
"#backend: {}" .format (setupext .options ["backend" ])
205
207
if setupext .options ["backend" ]
206
- else "#backend:" )
208
+ else "## backend: Agg " )
207
209
path .write_text ("" .join (template_lines ))
208
210
209
211
You can’t perform that action at this time.
0 commit comments