From 9fce8ddac2adba71c5986f8778214e91b239e5f8 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Mon, 15 Jan 2024 12:02:02 +0100 Subject: [PATCH] Use the same plotlyjs version number for all imports (#480) * Use the same plotlyjs version number for all imports * add tests for _js_path and _js_version --- .github/workflows/artifacts.yml | 5 +---- .gitignore | 4 ++-- deps/generate_artifacts.jl | 4 +++- deps/plotly_cdn_version.jl | 2 ++ src/PlotlyJS.jl | 3 ++- src/display.jl | 2 +- test/runtests.jl | 5 +++++ 7 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 deps/plotly_cdn_version.jl diff --git a/.github/workflows/artifacts.yml b/.github/workflows/artifacts.yml index 40ac8504..a247ccae 100644 --- a/.github/workflows/artifacts.yml +++ b/.github/workflows/artifacts.yml @@ -13,9 +13,6 @@ jobs: gen-artifacts: # The type of runner that the job will run on runs-on: ubuntu-latest - # The plotly version. Bumping this environment variable should do the trick - env: - PLOTLY_VER: 2.3.0 # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -33,7 +30,7 @@ jobs: - name: "Get artifact" run: | cd $GITHUB_WORKSPACE - julia -e 'include(joinpath(pwd(),"deps","generate_artifacts.jl")); generate_artifacts("'"$PLOTLY_VER"'","'"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"'")' + julia -e 'include(joinpath(pwd(),"deps","generate_artifacts.jl")); generate_artifacts("'"$GITHUB_SERVER_URL/$GITHUB_REPOSITORY"'")' - name: "Commit updated Artifacts.toml" run: | diff --git a/.gitignore b/.gitignore index 0cdd2010..aea62021 100644 --- a/.gitignore +++ b/.gitignore @@ -6,8 +6,8 @@ tags/ tags site/ .ipynb_checkpoints/ -assets/plotly-latest.min.js -deps/plotly-latest.min.js +assets/plotly-*.min.js +deps/plotly-*.min.js deps/plotschema.json deps/schema.html deps/*.csv diff --git a/deps/generate_artifacts.jl b/deps/generate_artifacts.jl index 3f6bdb93..e456a597 100644 --- a/deps/generate_artifacts.jl +++ b/deps/generate_artifacts.jl @@ -2,7 +2,9 @@ using Pkg.Artifacts using Downloads -function generate_artifacts(ver="latest", repo="https://github.com/JuliaPlots/PlotlyJS.jl") +ver = include("./plotly_cdn_version.jl") + +function generate_artifacts(repo="https://github.com/JuliaPlots/PlotlyJS.jl") artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml") # if Artifacts.toml does not exist we also do not have to remove it diff --git a/deps/plotly_cdn_version.jl b/deps/plotly_cdn_version.jl new file mode 100644 index 00000000..497ceca7 --- /dev/null +++ b/deps/plotly_cdn_version.jl @@ -0,0 +1,2 @@ +# run the artifacts.yml Github Action after changing this file +"2.3.0" diff --git a/src/PlotlyJS.jl b/src/PlotlyJS.jl index 6e25e6c9..36a221b0 100644 --- a/src/PlotlyJS.jl +++ b/src/PlotlyJS.jl @@ -26,7 +26,8 @@ export plot, dataset, list_datasets, make_subplots, savefig, mgrid # globals for this package const _pkg_root = dirname(dirname(@__FILE__)) const _js_path = joinpath(artifact"plotly-artifacts", "plotly.min.js") -const _js_cdn_path = "https://cdn.plot.ly/plotly-latest.min.js" +const _js_version = include(joinpath(_pkg_root, "deps", "plotly_cdn_version.jl")) +const _js_cdn_path = "https://cdn.plot.ly/plotly-$(_js_version).min.js" const _mathjax_cdn_path = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_SVG" diff --git a/src/display.jl b/src/display.jl index ba1c50ad..98f1a0bc 100644 --- a/src/display.jl +++ b/src/display.jl @@ -31,7 +31,7 @@ function SyncPlot( # setup scope deps = [ - "Plotly" => joinpath(artifact"plotly-artifacts", "plotly.min.js"), + "Plotly" => _js_path, joinpath(@__DIR__, "..", "assets", "plotly_webio.bundle.js") ] scope = Scope(imports=deps) diff --git a/test/runtests.jl b/test/runtests.jl index 5bc6a437..189372b3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,4 +10,9 @@ const M = PlotlyJS # include("blink.jl") include("kaleido.jl") +# these are public API +@test isfile(PlotlyJS._js_path) +@test !isempty(PlotlyJS._js_version) +@test !startswith(PlotlyJS._js_version, "v") + end