From 33f1a9e478120864001c46ad28312aba5675f061 Mon Sep 17 00:00:00 2001 From: Josh Day Date: Fri, 2 Dec 2022 11:01:18 -0500 Subject: [PATCH] rework artifacts and add schema --- .gitignore | 3 ++- Project.toml | 3 ++- deps/Project.toml | 1 + deps/artifact_bundle.jl | 59 +++++++++++++++++++---------------------- src/PlotlyLight.jl | 5 ++-- 5 files changed, 36 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 31105ec..d7aef90 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ Manifest.toml *.log *.tar *.tar.gz -artifacts/ +deps/plotly_artifacts* +notebooks/ diff --git a/Project.toml b/Project.toml index 5738a27..bda857b 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ authors = ["joshday "] version = "0.5.2" [deps] +ArtifactUtils = "8b73e784-e7d8-4ea5-973d-377fed4e3bce" Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" Cobweb = "ec354790-cf28-43e8-bb59-b484409b7bad" DefaultApplication = "3f0dd361-4fe0-5fc6-8523-80b14ec94d85" @@ -15,10 +16,10 @@ StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4" [compat] Cobweb = "0.1, 0.2" -StructTypes = "1" DefaultApplication = "1" EasyConfig = "0.1.10" JSON3 = "1.8" +StructTypes = "1" julia = "^1.6" [extras] diff --git a/deps/Project.toml b/deps/Project.toml index bf93310..88e0fbe 100644 --- a/deps/Project.toml +++ b/deps/Project.toml @@ -4,5 +4,6 @@ Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" PlotlyLight = "ca7969ec-10b3-423e-8d99-40f33abb42bf" Tar = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" diff --git a/deps/artifact_bundle.jl b/deps/artifact_bundle.jl index b2ef0f2..418e151 100644 --- a/deps/artifact_bundle.jl +++ b/deps/artifact_bundle.jl @@ -1,56 +1,53 @@ using Pkg Pkg.activate(@__DIR__) -using Downloads, Tar, ArtifactUtils, Artifacts, Dates, Pkg +using Downloads, Tar, ArtifactUtils, Artifacts, Dates, JSON3 #-----------------------------------------------------------------------------# Start from scratch -for file in readdir(@__DIR__) - if endswith(file, ".tar") || endswith(file, ".gz") - rm(joinpath(@__DIR__, file), force=true) - end -end +rm("plotlylight_artifacts.tar.gz", force=true) +dir = mkpath(joinpath(@__DIR__, "plotly_artifacts")) #-----------------------------------------------------------------------------# Templates # Need to install plotly.py in order to get themes because they are generated in python -# run(`conda create -n conda_jl python conda`) -# ENV["CONDA_JL_HOME"] = "/opt/homebrew/Caskroom/miniconda/base/envs/conda_jl" -# Pkg.build("Conda") -# using Conda -# Conda.add("plotly") - -dir = "/opt/homebrew/Caskroom/miniconda/base/envs/conda_jl/pkgs" -templates = joinpath(dir, filter(x -> startswith(x, "plotly"), readdir(dir))[1], "site-packages/plotly/package_data/templates") - - -run(`gzip $(Tar.create(templates, joinpath(@__DIR__, "templates.tar")))`) - +run(`conda env remove -n _plotly_artifacts`) # start from scratch +run(`conda create -n _plotly_artifacts -y`) # create env +run(`conda install -y plotly -n _plotly_artifacts`) + +# get path of `_plotly_artifacts` env +io = IOBuffer() +# run(pipeline(`conda info --json`, stdout=io)) +run(pipeline(`conda list -n _plotly_artifacts --json`; stdout=io)) +pkgs = JSON3.read(String(take!(io))) +metadata = only(filter(x -> x.name == "plotly", pkgs)) +template_dir = "/opt/homebrew/Caskroom/miniconda/base/pkgs/$(metadata.dist_name)/lib/python3.10/site-packages/plotly/package_data/templates/" +for file in readdir(template_dir) + cp(joinpath(template_dir, file), joinpath(dir, file)) +end -#-----------------------------------------------------------------------------# Plotly.js -url = "https://cdn.plot.ly/plotly-2.14.0.min.js" +#-----------------------------------------------------------------------------# plotly.min.js +url = "https://cdn.plot.ly/plotly-2.16.1.min.js" file = basename(url) -dir = mkpath(joinpath(@__DIR__, "plotlyjs")) Downloads.download(url, joinpath(dir, file)) -run(`gzip $(Tar.create(dir, joinpath(@__DIR__, "plotly.tar")))`) +#-----------------------------------------------------------------------------# schema +schema_url = "https://api.plot.ly/v2/plot-schema?format=json&sha1=%27%27" +Downloads.download(schema_url, joinpath(dir, "schema.json")) + +#-----------------------------------------------------------------------------# tar it up +run(`gzip $(Tar.create(dir, joinpath(@__DIR__, "plotly_artifacts.tar")))`) #-----------------------------------------------------------------------------# upload try artifacts_today = "artifacts_$(today())" - run(`gh release create $artifacts_today $(joinpath(@__DIR__, "templates.tar.gz")) $(joinpath(@__DIR__, "plotly.tar.gz")) --title $artifacts_today --notes ""`) + run(`gh release create $artifacts_today $(joinpath(@__DIR__, "plotly_artifacts.tar.gz")) --title $artifacts_today --notes ""`) @info "Sleeping so artifacts are ready on GitHub..." sleep(10) add_artifact!( "Artifacts.toml", - "plotly.min.js", - "https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/plotly.tar.gz", - force=true, - ) - add_artifact!( - "Artifacts.toml", - "plotly_templates", - "https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/templates.tar.gz", + "plotlylight", + "https://github.com/joshday/PlotlyLight.jl/releases/download/$artifacts_today/plotly_artifacts.tar.gz", force=true, ) catch ex diff --git a/src/PlotlyLight.jl b/src/PlotlyLight.jl index 20d60ab..4773574 100644 --- a/src/PlotlyLight.jl +++ b/src/PlotlyLight.jl @@ -9,8 +9,9 @@ using Artifacts export Plot, Config, collectrows -const cdn_url = "https://cdn.plot.ly/plotly-2.14.0.min.js" -const plotlyjs = joinpath(artifact"plotly.min.js", basename(cdn_url)) +const cdn_url = "https://cdn.plot.ly/plotly-2.16.1.min.js" +const plotlyjs = joinpath(artifact"plotlylight", basename(cdn_url)) +const schema = open(io -> JSON3.read(io), joinpath(artifact"plotlylight", "schema.json")) const templates_dir = artifact"plotly_templates" const templates = map(x -> replace(x, ".json" => ""), readdir(templates_dir))