-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create plotly.js bundle map programmatically #2336
Open
salim-b
wants to merge
10
commits into
plotly:master
Choose a base branch
from
salim-b:gen-plotly-bundles
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−75
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
81ed807
Create plotly.js bundle map programmatically
salim-b eaf3aea
Avoid package 'yay'
salim-b 21c2f0e
Use explicit pkg namespaces
salim-b 09f1459
refactor: avoid unnecessary download
salim-b b96d782
refactor: avoid unnecessary glob expansion
salim-b 74a4f4f
refactor: throw error if plotly.js bundle extraction fails
salim-b 8362bd1
refactor: clean up tmp dir
salim-b 93ef777
refactor: revert dependency on R >= 3.5
salim-b 666075b
Merge branch 'master' into gen-plotly-bundles
salim-b 64d5ed8
docs: add NEWS bullet
salim-b File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
library(httr) | ||
library(rprojroot) | ||
|
||
# get zip URL to latest plotly.js release | ||
x <- RETRY( | ||
x <- httr::RETRY( | ||
verb = "GET", | ||
url = 'https://api.github.com/repos/plotly/plotly.js/releases/latest', | ||
times = 5, | ||
terminate_on = c(400, 401, 403, 404), | ||
terminate_on_success = TRUE | ||
) | ||
zip <- content(x)$zipball_url | ||
zip <- httr::content(x)$zipball_url | ||
|
||
# remember where to copy over assets | ||
pkg_dir <- find_package_root_file() | ||
lib_dir <- find_package_root_file("inst/htmlwidgets/lib/plotlyjs") | ||
pkg_dir <- rprojroot::find_package_root_file() | ||
lib_dir <- rprojroot::find_package_root_file("inst/htmlwidgets/lib/plotlyjs") | ||
patches <- list.files( | ||
find_package_root_file("tools/patches"), | ||
rprojroot::find_package_root_file("tools/patches"), | ||
full.names = TRUE | ||
) | ||
|
||
|
@@ -25,8 +22,8 @@ dir.create(tmpdir) | |
|
||
withr::with_dir(tmpdir, { | ||
# download source | ||
download.file(zip, "plotly-js.zip") | ||
unzip("plotly-js.zip", exdir = "plotly-js") | ||
utils::download.file(zip, "plotly-js.zip") | ||
utils::unzip("plotly-js.zip", exdir = "plotly-js") | ||
|
||
withr::with_dir( | ||
dir("plotly-js", full.names = TRUE), { | ||
|
@@ -65,10 +62,29 @@ withr::with_dir(tmpdir, { | |
file.path(lib_dir, "locales", sub("^plotly-locale-", "", basename(locales))), | ||
overwrite = TRUE | ||
) | ||
# update plot schema | ||
# update plot schema and (partial) bundles | ||
Schema <- jsonlite::fromJSON(Sys.glob("dist/plot-schema.json")) | ||
tmp_file <- tempfile(pattern = "plotly_constants_", fileext = ".js") | ||
utils::download.file( | ||
url = paste0("https://raw.githubusercontent.com/plotly/plotly.js/", basename(zip), "/tasks/util/constants.js"), | ||
destfile = tmp_file, | ||
quiet = TRUE, | ||
mode = "wb" | ||
) | ||
bundleTraceMap <- | ||
salim-b marked this conversation as resolved.
Show resolved
Hide resolved
|
||
paste0(readLines(tmp_file), collapse = "\n") |> | ||
stringr::str_extract(pattern = "(?<=var partialBundleTraces = )\\{[^}]+\\}") |> | ||
yaml::read_yaml(text = _) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be nice if this could also handle There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 74a4f4f. |
||
withr::with_dir( | ||
pkg_dir, usethis::use_data(Schema, overwrite = TRUE, internal = TRUE) | ||
pkg_dir, usethis::use_data( | ||
Schema, | ||
bundleTraceMap, | ||
internal = TRUE, | ||
overwrite = TRUE, | ||
compress = "xz", | ||
version = 3L | ||
) | ||
) | ||
|
||
# plotly.js used to bundle a typedarray polyfill to support older browsers, | ||
|
@@ -81,7 +97,5 @@ withr::with_dir(tmpdir, { | |
#) | ||
|
||
message("Update plotlyMainBundle()'s version with ", basename(zip)) | ||
|
||
}) | ||
|
||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a requirement for R's latest serialization format (v3), cf. this line. We could stay on the v2 format if it's really important to support R < 3.5.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line you're referring to is a build time, not run time dependency, so the version bump requirement isn't necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but it also becomes a runtime dependency once we ship pkg-internal data in v3 format (which we do with this PR). To cite the relevant doc:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, right, thanks for pointing that out. Could we just keep the current behavior? It doesn't seem worth it to me to break compatibility for relatively small R objects that only get loaded once
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping the current behaviour is fine with me. But OTOH, R 3.5.0 was released more than 6 years ago, so I don't think we ought to care about supporting even more ancient versions.
I'll have a look at your other comments tomorrow. I'll revert to v2 serialization format then if you still think it's worth it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reverted to the v2 serialization format, see 93ef777.