Skip to content

improve browser error messages #3310

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Fixed
- 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))
- 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

## [5.1.0] - 2021-06-28

Expand Down
28 changes: 18 additions & 10 deletions packages/python/plotly/plotly/io/_base_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,23 @@ def open_html_in_browser(html, using=None, new=0, autoraise=True):
if isinstance(html, six.string_types):
html = html.encode("utf8")

if isinstance(using, tuple):
try:
using = [i for i in webbrowser._browsers.keys() if i in using][0]
except IndexError:
raise ValueError(
"""
Unable to find the given browser.
Try one among the following 'chrome', 'chromium', 'firefox' or 'default' """
)
browser = None

if using is None:
browser = webbrowser.get(None)
else:
if not isinstance(using, tuple):
using = (using,)
for browser_key in using:
try:
browser = webbrowser.get(browser_key)
if browser is not None:
break
except webbrowser.Error:
pass

if browser is None:
raise ValueError("Can't locate a browser with key in " + str(using))

class OneShotRequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
Expand All @@ -694,7 +702,7 @@ def log_message(self, format, *args):
pass

server = HTTPServer(("127.0.0.1", 0), OneShotRequestHandler)
webbrowser.get(using).open(
browser.open(
"http://127.0.0.1:%s" % server.server_port, new=new, autoraise=autoraise
)

Expand Down
9 changes: 5 additions & 4 deletions packages/python/plotly/plotly/tests/test_io/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,13 @@ def test_notebook_connected_show(fig1, name, connected):

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

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

# check get args
mock_get.assert_called_once_with(renderer_obj.using)
mock_get.assert_any_call(using[0])

# check open args
mock_call_args = mock_browser.open.call_args
Expand Down