Skip to content

Commit

Permalink
Make clear_extensions API public (bokeh#14029)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv authored Aug 19, 2024
1 parent 42435cd commit f5d54ea
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/bokeh/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ def ref(self) -> Ref:

# Public methods ----------------------------------------------------------

@classmethod
def clear_extensions(cls) -> None:
""" Clear any currently defined custom extensions.
Serialization calls will result in any currently defined custom
extensions being included with the generated Document, whether or not
there are utlized. This method can be used to clear out all existing
custom extension definitions.
"""
_default_resolver.clear_extensions()

@classmethod
@without_property_validation
def parameters(cls: type[Model]) -> list[Parameter]:
Expand Down Expand Up @@ -587,10 +599,6 @@ def _attach_document(self, doc: Document) -> None:
self.document = doc
self._update_event_callbacks()

@classmethod
def _clear_extensions(cls) -> None:
_default_resolver.clear_extensions()

def _detach_document(self) -> None:
''' Detach a model from a Bokeh |Document|.
Expand Down
2 changes: 1 addition & 1 deletion src/bokeh/sphinxext/bokeh_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def process_args_or_content(self):
raise SphinxError(f"bokeh-plot:: error reading {path!r} for {self.env.docname!r}: {e!r}")

def process_source(self, source, path, js_filename):
Model._clear_extensions()
Model.clear_extensions()

root, docstring = _evaluate_source(source, path, self.env)

Expand Down
37 changes: 37 additions & 0 deletions tests/unit/bokeh/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,43 @@ def test_args_pass_through():
with pytest.raises(ValueError, match=r"positional arguments are not allowed"):
SomeModel(1, b="a")

class Test_clear_extensions:
def test_ext_with___css__(self):
assert not any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

class Custom(Model):
__css__ = "stuff"

assert any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

Model.clear_extensions()

assert not any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

def test_ext_with___implementation__(self):
assert not any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

class Custom(Model):
__implementation__ = "stuff"

assert any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

Model.clear_extensions()

assert not any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

def test_ext_with___javascript__(self):
assert not any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

class Custom(Model):
__javascript__ = "stuff"

assert any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

Model.clear_extensions()

assert not any(x.endswith(".Custom") for x in Model.model_class_reverse_map)

#-----------------------------------------------------------------------------
# Dev API
#-----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/bokeh/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
DEFAULT_LOG_JS_RAW = 'Bokeh.set_log_level("info");'

def teardown_module() -> None:
Model._clear_extensions()
Model.clear_extensions()

# -----------------------------------------------------------------------------
# General API
Expand Down

0 comments on commit f5d54ea

Please sign in to comment.