From 5b49b24f25afdea1ec751ba0be523bddde91ede1 Mon Sep 17 00:00:00 2001 From: Koen van Walstijn <38299796+kbvw@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:58:00 +0200 Subject: [PATCH] Make notebooks work with `bokeh>=3` and remove `bokeh<3` pin (#3061) * Register `h.Vector` serialization function with Bokeh in notebooks * Unpin `bokeh<3` in documentation requirements and remove from main requirements * Unpin `numpy<2` in documentation requirements * Move serializer registration to `__init__.py` --- docs/docs_requirements.txt | 5 ++--- nrn_requirements.txt | 2 -- share/lib/python/neuron/__init__.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/docs_requirements.txt b/docs/docs_requirements.txt index 6571d22ac2..cd4982ca08 100644 --- a/docs/docs_requirements.txt +++ b/docs/docs_requirements.txt @@ -5,12 +5,11 @@ jupyter nbconvert myst_parser matplotlib -# bokeh 3 seems to break docs notebooks -bokeh<3 +bokeh # do not check import of next line ipython plotnine -numpy<2 +numpy plotly nbsphinx jinja2 diff --git a/nrn_requirements.txt b/nrn_requirements.txt index f049602b4e..1de5573095 100644 --- a/nrn_requirements.txt +++ b/nrn_requirements.txt @@ -3,8 +3,6 @@ setuptools_scm setuptools<=70.3.0 scikit-build matplotlib -# bokeh 3 seems to break docs notebooks -bokeh<3 ipython cython packaging diff --git a/share/lib/python/neuron/__init__.py b/share/lib/python/neuron/__init__.py index f84021c4da..7ea748288c 100644 --- a/share/lib/python/neuron/__init__.py +++ b/share/lib/python/neuron/__init__.py @@ -1835,3 +1835,13 @@ def _mview_html_tree(hlist, inside_mechanisms_in_use=0): if _get_ipython() is not None: html_formatter = _get_ipython().display_formatter.formatters["text/html"] html_formatter.for_type(hoc.HocObject, _hocobj_html) + +# in case Bokeh is installed, register a serialization function for hoc.Vector +try: + from bokeh.core.serialization import Serializer + + Serializer.register( + h.Vector, lambda obj, serializer: [serializer.encode(item) for item in obj] + ) +except ImportError: + pass