Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 906cae4

Browse filesBrowse files
authored
Merge pull request #19855 from anntzer/defaultbackend
Correct handle default backend.
2 parents 4085fc7 + 0b078ad commit 906cae4
Copy full SHA for 906cae4

File tree

Expand file treeCollapse file tree

4 files changed

+14
-7
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+14
-7
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,12 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
842842
transform=lambda line: line[1:] if line.startswith("#") else line,
843843
fail_on_error=True)
844844
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)
845851
rcParams = RcParams() # The global instance.
846852
dict.update(rcParams, dict.items(rcParamsDefault))
847853
dict.update(rcParams, _rc_params_in_file(matplotlib_fname()))

‎lib/matplotlib/mpl-data/matplotlibrc

Copy file name to clipboardExpand all lines: lib/matplotlib/mpl-data/matplotlibrc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
## PS PDF SVG Template
7979
## You can also deploy your own backend outside of Matplotlib by referring to
8080
## the module name (which must be in the PYTHONPATH) as 'module://my_backend'.
81-
#backend: Agg
81+
##backend: Agg
8282

8383
## The port to use for the web server in the WebAgg backend.
8484
#webagg.port: 8988

‎lib/matplotlib/rcsetup.py

Copy file name to clipboardExpand all lines: lib/matplotlib/rcsetup.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,14 +1411,13 @@ def _convert_validator_spec(key, conv):
14111411
"_internal.classic_mode": validate_bool
14121412
}
14131413
_hardcoded_defaults = { # Defaults not inferred from matplotlibrc.template...
1414-
# ... because it can"t be:
1415-
"backend": _auto_backend_sentinel,
14161414
# ... because they are private:
14171415
"_internal.classic_mode": False,
14181416
# ... because they are deprecated:
14191417
"animation.avconv_path": "avconv",
14201418
"animation.avconv_args": [],
14211419
"animation.html_args": [],
1420+
# backend is handled separately when constructing rcParamsDefault.
14221421
}
14231422
_validators = {k: _convert_validator_spec(k, conv)
14241423
for k, conv in _validators.items()}

‎setup.py

Copy file name to clipboardExpand all lines: setup.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,18 @@ def build_extensions(self):
194194

195195

196196
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.
199201
template_lines = path.read_text().splitlines(True)
200202
backend_line_idx, = [ # Also asserts that there is a single such line.
201203
idx for idx, line in enumerate(template_lines)
202-
if line.startswith("#backend:")]
204+
if "#backend:" in line]
203205
template_lines[backend_line_idx] = (
204206
"#backend: {}".format(setupext.options["backend"])
205207
if setupext.options["backend"]
206-
else "#backend:")
208+
else "##backend: Agg")
207209
path.write_text("".join(template_lines))
208210

209211

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.