Skip to content

Commit 6ed555b

Browse files
Merge pull request #3310 from plotly/chromium_followup
improve browser error messages
2 parents 2c2dd6a + 1e24ca0 commit 6ed555b

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
### Fixed
1212
- Fixed regression introduced in version 5.0.0 where pandas/numpy arrays with `dtype` of Object were being converted to `list` values when added to a Figure ([#3292](https://github.com/plotly/plotly.py/issues/3292), [#3293](https://github.com/plotly/plotly.py/pull/3293))
13+
- Better detection of Chrome and Chromium browsers in the Renderers framework, especially on Linux ([#3278](https://github.com/plotly/plotly.py/pull/3278)) with thanks to [@c-chaitanya](https://github.com/c-chaitanya) for the contribution
1314

1415
## [5.1.0] - 2021-06-28
1516

packages/python/plotly/plotly/io/_base_renderers.py

+18-10
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,23 @@ def open_html_in_browser(html, using=None, new=0, autoraise=True):
669669
if isinstance(html, six.string_types):
670670
html = html.encode("utf8")
671671

672-
if isinstance(using, tuple):
673-
try:
674-
using = [i for i in webbrowser._browsers.keys() if i in using][0]
675-
except IndexError:
676-
raise ValueError(
677-
"""
678-
Unable to find the given browser.
679-
Try one among the following 'chrome', 'chromium', 'firefox' or 'default' """
680-
)
672+
browser = None
673+
674+
if using is None:
675+
browser = webbrowser.get(None)
676+
else:
677+
if not isinstance(using, tuple):
678+
using = (using,)
679+
for browser_key in using:
680+
try:
681+
browser = webbrowser.get(browser_key)
682+
if browser is not None:
683+
break
684+
except webbrowser.Error:
685+
pass
686+
687+
if browser is None:
688+
raise ValueError("Can't locate a browser with key in " + str(using))
681689

682690
class OneShotRequestHandler(BaseHTTPRequestHandler):
683691
def do_GET(self):
@@ -694,7 +702,7 @@ def log_message(self, format, *args):
694702
pass
695703

696704
server = HTTPServer(("127.0.0.1", 0), OneShotRequestHandler)
697-
webbrowser.get(using).open(
705+
browser.open(
698706
"http://127.0.0.1:%s" % server.server_port, new=new, autoraise=autoraise
699707
)
700708

packages/python/plotly/plotly/tests/test_io/test_renderers.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,13 @@ def test_notebook_connected_show(fig1, name, connected):
221221

222222
# Browser
223223
# -------
224-
@pytest.mark.parametrize("renderer", ["browser", "chrome", "firefox"])
224+
@pytest.mark.parametrize("renderer", ["browser", "chrome", "chromium", "firefox"])
225225
def test_browser_renderer_show(fig1, renderer):
226226
pio.renderers.default = renderer
227227
renderer_obj = pio.renderers[renderer]
228-
# scan through webbrowser._browsers.keys() and assign the browser name registered with os
229-
renderer_obj.using = [i for i in webbrowser._browsers.keys() if renderer in i][0]
228+
using = renderer_obj.using
229+
if not isinstance(renderer_obj.using, tuple):
230+
using = (using,)
230231

231232
# Setup mocks
232233
mock_get = MagicMock(name="test get")
@@ -251,7 +252,7 @@ def open_url(url, new=0, autoraise=True):
251252
pio.show(fig1)
252253

253254
# check get args
254-
mock_get.assert_called_once_with(renderer_obj.using)
255+
mock_get.assert_any_call(using[0])
255256

256257
# check open args
257258
mock_call_args = mock_browser.open.call_args

0 commit comments

Comments
 (0)