From 1d56fa62503808ab1dc414c4855d92f40473cfd0 Mon Sep 17 00:00:00 2001 From: sdc50 Date: Wed, 27 Mar 2024 12:12:12 -0600 Subject: [PATCH] bokehjsdir() has been deprecated in favor of bokehjs_path() (#1022) (#1025) * bokehjsdir() has been deprecated in favor of bokehjs_path() * Apply suggestions from code review * Added unit test for bokejs_path() import --------- Co-authored-by: Gronka Co-authored-by: tbg --- .../unit_tests/test_tethys_portal/test_settings.py | 9 +++++++++ tethys_portal/settings.py | 13 ++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests/test_tethys_portal/test_settings.py b/tests/unit_tests/test_tethys_portal/test_settings.py index a6ea5fb7a..046a863ac 100644 --- a/tests/unit_tests/test_tethys_portal/test_settings.py +++ b/tests/unit_tests/test_tethys_portal/test_settings.py @@ -260,3 +260,12 @@ def test_bokeh_django_staticfiles_finder(self, _): self.assertIn( "bokeh_django.static.BokehExtensionFinder", settings.STATICFILES_FINDERS ) + + @mock.patch("tethys_portal.optional_dependencies.optional_import") + def test_bokehjsdir_compatibility(self, mock_oi): + mock_bokeh_settings = mock.MagicMock() + mock_oi.return_value = mock_bokeh_settings + mock_bokeh_settings.bokehjs_path.side_effect = AttributeError() + reload(settings) + mock_bokeh_settings.bokehjs_path.assert_called_once() + mock_bokeh_settings.bokehjsdir.assert_called_once() diff --git a/tethys_portal/settings.py b/tethys_portal/settings.py index af3b78e47..ef7d94f93 100644 --- a/tethys_portal/settings.py +++ b/tethys_portal/settings.py @@ -37,9 +37,7 @@ from tethys_portal.optional_dependencies import optional_import, has_module # optional imports -bokeh_settings, bokehjsdir = optional_import( - ("settings", "bokehjsdir"), from_module="bokeh.settings" -) +bokeh_settings = optional_import("settings", from_module="bokeh.settings") bokeh_django = optional_import("bokeh_django") log = logging.getLogger(__name__) @@ -407,8 +405,13 @@ STATICFILES_DIRS = [ BASE_DIR / "static", ] -if has_module(bokehjsdir): - STATICFILES_DIRS.append(bokehjsdir()) +if has_module(bokeh_settings): + try: + bokeh_js_dir = bokeh_settings.bokehjs_path() + except AttributeError: + # support bokeh versions < 3.4 + bokeh_js_dir = bokeh_settings.bokehjsdir() + STATICFILES_DIRS.append(bokeh_js_dir) STATICFILES_USE_NPM = TETHYS_PORTAL_CONFIG.pop("STATICFILES_USE_NPM", False) if STATICFILES_USE_NPM: