Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commita56911e

Browse files
authored
Merge pull request#29754 from meeseeksmachine/auto-backport-of-pr-29721-on-v3.10.x
Backport PR#29721 on branch v3.10.x (FIX: pyplot auto-backend detection case-sensitivity fixup)
2 parents005677f +5090b26 commita56911e

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

‎lib/matplotlib/pyplot.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,12 +2715,15 @@ def polar(*args, **kwargs) -> list[Line2D]:
27152715
# If rcParams['backend_fallback'] is true, and an interactive backend is
27162716
# requested, ignore rcParams['backend'] and force selection of a backend that
27172717
# is compatible with the current running interactive framework.
2718-
if (rcParams["backend_fallback"]
2719-
andrcParams._get_backend_or_none()in (# type: ignore[attr-defined]
2720-
set(backend_registry.list_builtin(BackendFilter.INTERACTIVE))-
2721-
{'webagg','nbagg'})
2722-
andcbook._get_running_interactive_framework()):
2723-
rcParams._set("backend",rcsetup._auto_backend_sentinel)
2718+
ifrcParams["backend_fallback"]:
2719+
requested_backend=rcParams._get_backend_or_none()# type: ignore[attr-defined]
2720+
requested_backend=Noneifrequested_backendisNoneelserequested_backend.lower()
2721+
available_backends=backend_registry.list_builtin(BackendFilter.INTERACTIVE)
2722+
if (
2723+
requested_backendin (set(available_backends)- {'webagg','nbagg'})
2724+
andcbook._get_running_interactive_framework()
2725+
):
2726+
rcParams._set("backend",rcsetup._auto_backend_sentinel)
27242727

27252728
# fmt: on
27262729

‎lib/matplotlib/tests/test_rcparams.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,10 +521,11 @@ def test_rcparams_reset_after_fail():
521521

522522

523523
@pytest.mark.skipif(sys.platform!="linux",reason="Linux only")
524-
deftest_backend_fallback_headless(tmp_path):
524+
deftest_backend_fallback_headless_invalid_backend(tmp_path):
525525
env= {**os.environ,
526526
"DISPLAY":"","WAYLAND_DISPLAY":"",
527527
"MPLBACKEND":"","MPLCONFIGDIR":str(tmp_path)}
528+
# plotting should fail with the tkagg backend selected in a headless environment
528529
withpytest.raises(subprocess.CalledProcessError):
529530
subprocess_run_for_testing(
530531
[sys.executable,"-c",
@@ -536,6 +537,28 @@ def test_backend_fallback_headless(tmp_path):
536537
env=env,check=True,stderr=subprocess.DEVNULL)
537538

538539

540+
@pytest.mark.skipif(sys.platform!="linux",reason="Linux only")
541+
deftest_backend_fallback_headless_auto_backend(tmp_path):
542+
# specify a headless mpl environment, but request a graphical (tk) backend
543+
env= {**os.environ,
544+
"DISPLAY":"","WAYLAND_DISPLAY":"",
545+
"MPLBACKEND":"TkAgg","MPLCONFIGDIR":str(tmp_path)}
546+
547+
# allow fallback to an available interactive backend explicitly in configuration
548+
rc_path=tmp_path/"matplotlibrc"
549+
rc_path.write_text("backend_fallback: true")
550+
551+
# plotting should succeed, by falling back to use the generic agg backend
552+
backend=subprocess_run_for_testing(
553+
[sys.executable,"-c",
554+
"import matplotlib.pyplot;"
555+
"matplotlib.pyplot.plot(42);"
556+
"print(matplotlib.get_backend());"
557+
],
558+
env=env,text=True,check=True,capture_output=True).stdout
559+
assertbackend.strip().lower()=="agg"
560+
561+
539562
@pytest.mark.skipif(
540563
sys.platform=="linux"andnot_c_internal_utils.xdisplay_is_valid(),
541564
reason="headless")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp