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

FIX: pyplot auto-backend detection case-sensitivity fixup#29721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletionslib/matplotlib/pyplot.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2715,12 +2715,15 @@ def polar(*args, **kwargs) -> list[Line2D]:
# If rcParams['backend_fallback'] is true, and an interactive backend is
# requested, ignore rcParams['backend'] and force selection of a backend that
# is compatible with the current running interactive framework.
if (rcParams["backend_fallback"]
and rcParams._get_backend_or_none() in ( # type: ignore[attr-defined]
set(backend_registry.list_builtin(BackendFilter.INTERACTIVE)) -
{'webagg', 'nbagg'})
and cbook._get_running_interactive_framework()):
rcParams._set("backend", rcsetup._auto_backend_sentinel)
if rcParams["backend_fallback"]:
requested_backend = rcParams._get_backend_or_none() # type: ignore[attr-defined]
requested_backend = None if requested_backend is None else requested_backend.lower()
available_backends = backend_registry.list_builtin(BackendFilter.INTERACTIVE)
if (
requested_backend in (set(available_backends) - {'webagg', 'nbagg'})
and cbook._get_running_interactive_framework()
):
rcParams._set("backend", rcsetup._auto_backend_sentinel)

# fmt: on

Expand Down
25 changes: 24 additions & 1 deletionlib/matplotlib/tests/test_rcparams.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -521,10 +521,11 @@ def test_rcparams_reset_after_fail():


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


@pytest.mark.skipif(sys.platform != "linux", reason="Linux only")
def test_backend_fallback_headless_auto_backend(tmp_path):
# specify a headless mpl environment, but request a graphical (tk) backend
env = {**os.environ,
"DISPLAY": "", "WAYLAND_DISPLAY": "",
"MPLBACKEND": "TkAgg", "MPLCONFIGDIR": str(tmp_path)}

# allow fallback to an available interactive backend explicitly in configuration
rc_path = tmp_path / "matplotlibrc"
rc_path.write_text("backend_fallback: true")

# plotting should succeed, by falling back to use the generic agg backend
backend = subprocess_run_for_testing(
[sys.executable, "-c",
"import matplotlib.pyplot;"
"matplotlib.pyplot.plot(42);"
"print(matplotlib.get_backend());"
],
env=env, text=True, check=True, capture_output=True).stdout
assert backend.strip().lower() == "agg"


@pytest.mark.skipif(
sys.platform == "linux" and not _c_internal_utils.xdisplay_is_valid(),
reason="headless")
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp