Skip to content

Commit ea71d45

Browse files
authored
Add windowing system to mne.sys_info (#14099)
1 parent 31fe8e9 commit ea71d45

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
On Linux, :func:`mne.sys_info` now includes the detected windowing system (Wayland or X11), by `Clemens Brunner`_.

mne/utils/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,16 @@ def _get_total_memory():
699699
return total_memory
700700

701701

702+
def _get_linux_windowing_system():
703+
"""Return the windowing system on Linux ("Wayland", "X11", or None)."""
704+
session_type = os.getenv("XDG_SESSION_TYPE", "").lower()
705+
if session_type == "wayland" or os.getenv("WAYLAND_DISPLAY"):
706+
return "Wayland"
707+
if session_type == "x11" or os.getenv("DISPLAY"):
708+
return "X11"
709+
return None
710+
711+
702712
def _get_cpu_brand():
703713
"""Return the CPU brand string."""
704714
if platform.system() == "Windows":
@@ -770,6 +780,10 @@ def sys_info(
770780
unicode = False
771781
ljust = 24 if dependencies == "developer" else 21
772782
platform_str = platform.platform()
783+
if platform.system() == "Linux":
784+
windowing_system = _get_linux_windowing_system()
785+
if windowing_system is not None:
786+
platform_str += f" ({windowing_system})"
773787

774788
out = partial(print, end="", file=fid)
775789
out("Platform".ljust(ljust) + platform_str + "\n")

mne/utils/tests/test_config.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,29 @@ def test_sys_info_basic():
122122
assert "Platform Linux" in out
123123

124124

125+
def test_sys_info_windowing_system(monkeypatch):
126+
"""Test that sys_info reports the windowing system on Linux."""
127+
monkeypatch.setattr(platform, "system", lambda: "Linux")
128+
for var in ("XDG_SESSION_TYPE", "WAYLAND_DISPLAY", "DISPLAY"):
129+
monkeypatch.delenv(var, raising=False)
130+
131+
out = ClosingStringIO()
132+
sys_info(fid=out, check_version=False)
133+
line = out.getvalue().splitlines()[0]
134+
assert line.startswith("Platform")
135+
assert "(" not in line
136+
137+
monkeypatch.setenv("XDG_SESSION_TYPE", "wayland")
138+
out = ClosingStringIO()
139+
sys_info(fid=out, check_version=False)
140+
assert "(Wayland)" in out.getvalue().splitlines()[0]
141+
142+
monkeypatch.setenv("XDG_SESSION_TYPE", "x11")
143+
out = ClosingStringIO()
144+
sys_info(fid=out, check_version=False)
145+
assert "(X11)" in out.getvalue().splitlines()[0]
146+
147+
125148
def test_sys_info_complete():
126149
"""Test that sys_info is sufficiently complete."""
127150
tomllib = pytest.importorskip("tomllib") # python 3.11+

0 commit comments

Comments
 (0)