From 4cab1673186ed4b3c0bc2ead0713399304df6a81 Mon Sep 17 00:00:00 2001 From: Alberto Mengali Date: Tue, 6 Aug 2024 16:07:58 +0200 Subject: [PATCH 1/6] make PLOTLY_VERSION a ScopedValue --- Project.toml | 2 ++ src/PlutoPlotly.jl | 1 + src/basics.jl | 10 +++++++--- test/Project.toml | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index c69284b..f1c35c1 100644 --- a/Project.toml +++ b/Project.toml @@ -16,6 +16,7 @@ Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5" Reexport = "189a3867-3050-52da-a836-e630ba90ab69" +ScopedValues = "7e506255-f358-4e82-b7e4-beb19740aa63" Scratch = "6c6a2e73-6563-6170-7368-637461726353" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" @@ -41,6 +42,7 @@ Pkg = "1.9" PlotlyBase = "0.8" PlotlyKaleido = "2" Reexport = "1" +ScopedValues = "1.2.1" Scratch = "1" TOML = "1" Unitful = "1" diff --git a/src/PlutoPlotly.jl b/src/PlutoPlotly.jl index abdd424..c84856b 100644 --- a/src/PlutoPlotly.jl +++ b/src/PlutoPlotly.jl @@ -12,6 +12,7 @@ using LaTeXStrings using Markdown using Downloads: download using Artifacts +using ScopedValues # This is similar to `@reexport` but does not exports undefined names and can # also avoid exporting the module name function re_export(m::Module; skip_modname = false) diff --git a/src/basics.jl b/src/basics.jl index 9955a57..eb06a9f 100644 --- a/src/basics.jl +++ b/src/basics.jl @@ -1,5 +1,6 @@ const ARTIFACT_VERSION = VersionNumber(read(joinpath(artifact"plotly-esm-min", "VERSION"), String)) -const PLOTLY_VERSION = Ref(ARTIFACT_VERSION) +const DEFAULT_PLOTLY_VERSION = Ref(ARTIFACT_VERSION) +const PLOTLY_VERSION = ScopedValue{Union{Nothing, String, VersionNumber}}(nothing) const DEFAULT_TEMPLATE = Ref(PlotlyBase.templates[PlotlyBase.templates.default]) const JS = HypertextLiteral.JavaScript @@ -57,10 +58,13 @@ end function change_plotly_version(v) ver = VersionNumber(v) maybe_add_plotly_local(ver) - PLOTLY_VERSION[] = ver + DEFAULT_PLOTLY_VERSION[] = ver end -get_plotly_version() = PLOTLY_VERSION[] +function get_plotly_version() + v = @something PLOTLY_VERSION[] DEFAULT_PLOTLY_VERSION[] + return VersionNumber(v) +end ## Prepend Cell Selector ## """ diff --git a/test/Project.toml b/test/Project.toml index 9b9963a..129c5fb 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -4,6 +4,7 @@ DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Kaleido_jll = "f7e6163d-2fa5-5f23-b69c-1db539e41963" PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c" Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781" +ScopedValues = "7e506255-f358-4e82-b7e4-beb19740aa63" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" From eb8df3c2a4ec6b7c3e6b72e658863476e7e3745a Mon Sep 17 00:00:00 2001 From: Alberto Mengali Date: Tue, 6 Aug 2024 16:08:08 +0200 Subject: [PATCH 2/6] use version getter inside show --- src/show.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/show.jl b/src/show.jl index 50c7fec..f3de169 100644 --- a/src/show.jl +++ b/src/show.jl @@ -1,4 +1,4 @@ -function _show(pp::PlutoPlot; script_id = "pluto-plotly-div", ver = PLOTLY_VERSION[]) +function _show(pp::PlutoPlot; script_id = "pluto-plotly-div", ver = get_plotly_version()) @htl """