summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonald Oussoren <ronaldoussoren@mac.com>2023-12-21 13:43:38 (GMT)
committerGitHub <noreply@github.com>2023-12-21 13:43:38 (GMT)
commitca8b1d09585c032416c5d4905f707550eecf327f (patch)
tree2a39e9a18fd852bd47c024ca4a742239554ef471
parent723f4d66982e4d2c54f8e874d6084ab7b2ff5833 (diff)
downloadcpython-ca8b1d09585c032416c5d4905f707550eecf327f.zip
cpython-ca8b1d09585c032416c5d4905f707550eecf327f.tar.gz
cpython-ca8b1d09585c032416c5d4905f707550eecf327f.tar.bz2
gh-87277: Don't look for X11 browsers on macOS in webbrowser (#24480)
The installation of XQuartz on macOS will unconditionally set the $DISPLAY variable. The X11 server will be launched when a program tries to access the display. This results in launching the X11 server when using the webbrowser module, even though X11 browsers won't be used in practice.
-rw-r--r--Lib/test/test_webbrowser.py11
-rwxr-xr-xLib/webbrowser.py7
-rw-r--r--Misc/NEWS.d/next/macOS/2023-12-21-09-41-42.gh-issue-87277.IF6EZZ.rst3
3 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/test_webbrowser.py b/Lib/test/test_webbrowser.py
index 2d695bc..ca481c5 100644
--- a/Lib/test/test_webbrowser.py
+++ b/Lib/test/test_webbrowser.py
@@ -272,6 +272,17 @@ class BrowserRegistrationTest(unittest.TestCase):
self._check_registration(preferred=True)
+ @unittest.skipUnless(sys.platform == "darwin", "macOS specific test")
+ def test_no_xdg_settings_on_macOS(self):
+ # On macOS webbrowser should not use xdg-settings to
+ # look for X11 based browsers (for those users with
+ # XQuartz installed)
+ with mock.patch("subprocess.check_output") as ck_o:
+ webbrowser.register_standard_browsers()
+
+ ck_o.assert_not_called()
+
+
class ImportTest(unittest.TestCase):
def test_register(self):
webbrowser = import_helper.import_fresh_module('webbrowser')
diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index 8b06287..6f9c6a6 100755
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -495,7 +495,12 @@ def register_standard_browsers():
register("microsoft-edge", None, Edge("MicrosoftEdge.exe"))
else:
# Prefer X browsers if present
- if os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY"):
+ #
+ # NOTE: Do not check for X11 browser on macOS,
+ # XQuartz installation sets a DISPLAY environment variable and will
+ # autostart when someone tries to access the display. Mac users in
+ # general don't need an X11 browser.
+ if sys.platform != "darwin" and (os.environ.get("DISPLAY") or os.environ.get("WAYLAND_DISPLAY")):
try:
cmd = "xdg-settings get default-web-browser".split()
raw_result = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
diff --git a/Misc/NEWS.d/next/macOS/2023-12-21-09-41-42.gh-issue-87277.IF6EZZ.rst b/Misc/NEWS.d/next/macOS/2023-12-21-09-41-42.gh-issue-87277.IF6EZZ.rst
new file mode 100644
index 0000000..4ae55c0
--- /dev/null
+++ b/Misc/NEWS.d/next/macOS/2023-12-21-09-41-42.gh-issue-87277.IF6EZZ.rst
@@ -0,0 +1,3 @@
+webbrowser: Don't look for X11 browsers on macOS. Those are generally not
+used and probing for them can result in starting XQuartz even if it isn't
+used otherwise.