Skip to content

Commit

Permalink
Add patch for bokeh _log_console problem
Browse files Browse the repository at this point in the history
  • Loading branch information
johannesloibl committed Nov 28, 2023
1 parent 1db3bf9 commit 6fb9cce
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/pharaoh/assetlib/patches/_bokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def init_module():
:raises RuntimeError: If msedgedriver.exe is not found in the library root folder.
"""
from bokeh.io import webdriver
from bokeh.io import export, webdriver

def create_edge_webdriver():
from selenium.webdriver.edge.options import Options
Expand Down Expand Up @@ -64,6 +64,25 @@ def _try_create_chromium_webdriver(*args, **kwargs):

webdriver._try_create_chromium_webdriver = _try_create_chromium_webdriver

def _log_console(driver) -> None:
levels = {"WARNING", "ERROR", "SEVERE"}
try:
logs = driver.get_log("browser")
except Exception:
return
# loibljoh: Don't know why yet, but the Github runners for ubuntu and Python 3.9 and 3.10 return an integer
if isinstance(logs, int):
export.log.warning(f"Browser log was an integer: {logs}")
return

messages = [log.get("message") for log in logs if log.get("level") in levels]
if len(messages) > 0:
export.log.warning("There were browser warnings and/or errors that may have affected your export")
for message in messages:
export.log.warning(message)

export._log_console = _log_console

# memorize the unpatched functions
vanilla_bokeh_io_show = bokeh_io.show
vanilla_bokeh_save = bokeh_io_saving.save
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_asset_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ def test_parallel_asset_generation(new_proj):
workers=2,
)
fails = [ex for _, ex in results if ex is not None]
print(fails)
assert len(fails) == 2
assert any("failing.py" in str(ex) for ex in fails)
assert any("failing.ipynb" in str(ex) for ex in fails)
for fail in fails:
print(fail)
assert len(fails) == 2

files = sorted(new_proj.asset_build_dir.glob("*"))
assert len(sorted(new_proj.asset_build_dir.glob("*.assetinfo"))) == 18
Expand Down

0 comments on commit 6fb9cce

Please sign in to comment.