From bc8eb6af5934d235e8d8caec853a8ae4d2882382 Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Thu, 24 Aug 2023 19:08:44 -0400 Subject: [PATCH 01/16] Partial work towards Google Chrome for Testing update. Does renames. Still doesn't move the driver to the right place... --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ R/chrome.R | 4 +-- R/predl_chrome_for_testing.R | 50 +++++++++++++++++++++++++++++++++ inst/yaml/chromedriver.yml | 4 +-- man/predl_chrome_for_testing.Rd | 33 ++++++++++++++++++++++ 6 files changed, 90 insertions(+), 5 deletions(-) create mode 100644 R/predl_chrome_for_testing.R create mode 100644 man/predl_chrome_for_testing.Rd diff --git a/DESCRIPTION b/DESCRIPTION index ea86a0b..d82f91c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,5 +29,5 @@ Imports: URL: https://docs.ropensci.org/wdman/, https://github.com/ropensci/wdman URLNote: https://github.com/ropensci/wdman BugReports: https://github.com/ropensci/wdman/issues -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 14c5ad2..f60ecc2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,9 +4,11 @@ export(chrome) export(gecko) export(iedriver) export(phantomjs) +export(predl_chrome_for_testing) export(selenium) importFrom(assertthat,assert_that) importFrom(binman,app_dir) +importFrom(binman,assign_directory) importFrom(binman,list_versions) importFrom(binman,process_yaml) importFrom(binman,rm_platform) diff --git a/R/chrome.R b/R/chrome.R index af6e160..e0cb828 100644 --- a/R/chrome.R +++ b/R/chrome.R @@ -100,7 +100,7 @@ chrome <- function(port = 4567L, version = "latest", path = "wd/hub", chrome_check <- function(verbose, check = TRUE) { chromeyml <- system.file("yaml", "chromedriver.yml", package = "wdman") cyml <- yaml::yaml.load_file(chromeyml) - platvec <- c("predlfunction", "binman::predl_google_storage", "platform") + platvec <- c("predlfunction", "wdman::predl_chrome_for_testing", "platform") cyml[[platvec]] <- switch(Sys.info()["sysname"], Linux = grep(os_arch("linux"), cyml[[platvec]], value = TRUE), @@ -111,7 +111,7 @@ chrome_check <- function(verbose, check = TRUE) { # Need regex that can tell mac64 and mac64_m1 apart if (cyml[[platvec]] %in% c("mac64", "mac64_m1")) { - platregexvec <- c("predlfunction", "binman::predl_google_storage", "platformregex") + platregexvec <- c("predlfunction", "wdman::predl_chrome_for_testing", "platformregex") cyml[[platregexvec]] <- paste0(cyml[[platvec]], "\\.") } diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R new file mode 100644 index 0000000..1e376c9 --- /dev/null +++ b/R/predl_chrome_for_testing.R @@ -0,0 +1,50 @@ +#' Pre-download function for Chrome-for-testing site +#' +#' @param url URL of the JSON to use for files +#' @param platform One of `c("linux64", "mac-arm64", "mac-x64", +#' "win32", "win64") +#' @param history Integer number of recent entries +#' @param appname Name of the app, typically `"chromedriver"` +#' @param platformregex A filter for platforms. Defaults to the platform names. +#' +#' @return A named list of dataframes. The name indicates the platform. The dataframe should contain the version, url, and file to +#' be processed. Used as input for `binman::download_files()` or an equivalent. +#' @importFrom binman assign_directory +#' @export +predl_chrome_for_testing <- function(url, platform, history, + appname, + platformregex = platform) { + assert_that(is_URL_file(url)) + assert_that(is_character(platform)) + platform <- c(mac64_m1 = "mac-arm64", + mac64 = "mac-x64", + linux32 = "linux32", + linux64 = "linux64", + win32 = "win64")[platform] + assert_that(is_integer(history)) + assert_that(is_string(appname)) + assert_that(is_character(platformregex)) + ver_data <- jsonlite::fromJSON(url)[[2]] + ver_data <- Filter(function(x) !is.null(x$downloads[[appname]]), + ver_data) + ver_data <- ver_data[order(as.numeric(names(ver_data)))] + unwrap <- function(entry) { + version <- entry$version + downloads <- entry$downloads[[appname]] + if (!is.null(downloads)) { + platform <- downloads$platform + url <- downloads$url + file <- basename(url) + data.frame(version, platform, url, file) + } + } + extracted <- do.call(rbind, lapply(ver_data, unwrap)) + app_links <- tapply(extracted, extracted$platform, identity) + app_links <- app_links[platform] + names(app_links) <- c("mac-arm64" = "mac64_m1", + "mac-x64" = "mac64", + linux32 = "linux32", + linux64 = "linux64", + win64 = "win32")[names(app_links)] + assign_directory(app_links, appname) +} diff --git a/inst/yaml/chromedriver.yml b/inst/yaml/chromedriver.yml index c6ee99c..7f962bf 100644 --- a/inst/yaml/chromedriver.yml +++ b/inst/yaml/chromedriver.yml @@ -1,7 +1,7 @@ name: chromedriver predlfunction: - "binman::predl_google_storage": - url: https://www.googleapis.com/storage/v1/b/chromedriver/o + "wdman::predl_chrome_for_testing": + url: https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone-with-downloads.json platform: - mac64_m1 - mac64 diff --git a/man/predl_chrome_for_testing.Rd b/man/predl_chrome_for_testing.Rd new file mode 100644 index 0000000..e8b89e0 --- /dev/null +++ b/man/predl_chrome_for_testing.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/predl_chrome_for_testing.R +\name{predl_chrome_for_testing} +\alias{predl_chrome_for_testing} +\title{Pre-download function for Chrome-for-testing site} +\usage{ +predl_chrome_for_testing( + url, + platform, + history, + appname, + platformregex = platform +) +} +\arguments{ +\item{url}{URL of the JSON to use for files} + +\item{platform}{One of `c("linux64", "mac-arm64", "mac-x64", +"win32", "win64")} + +\item{history}{Integer number of recent entries} + +\item{appname}{Name of the app, typically `"chromedriver"`} + +\item{platformregex}{A filter for platforms. Defaults to the platform names.} +} +\value{ +A named list of dataframes. The name indicates the platform. The dataframe should contain the version, url, and file to +be processed. Used as input for `binman::download_files()` or an equivalent. +} +\description{ +Pre-download function for Chrome-for-testing site +} From 51f576bf69bf661deb12cb03ae7644318bf90eab Mon Sep 17 00:00:00 2001 From: Duncan Murdoch Date: Sat, 23 Sep 2023 13:35:28 -0400 Subject: [PATCH 02/16] First pass at fix for new chromedriver location --- NAMESPACE | 1 + R/predl_chrome_for_testing.R | 10 ++++++++++ inst/yaml/chromedriver.yml | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index f60ecc2..c0c0e77 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(iedriver) export(phantomjs) export(predl_chrome_for_testing) export(selenium) +export(unziptar_dlfiles) importFrom(assertthat,assert_that) importFrom(binman,app_dir) importFrom(binman,assign_directory) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index 1e376c9..cc4967e 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -48,3 +48,13 @@ predl_chrome_for_testing <- function(url, platform, history, win64 = "win32")[names(app_links)] assign_directory(app_links, appname) } + +#' @export +unziptar_dlfiles <- function(...) { + x <- binman::unziptar_dlfiles(...) + for (f in x) { + dir <- tools::file_path_sans_ext(f) + file.copy(list.files(dir, full.names = TRUE), dirname(dir)) + } + x +} diff --git a/inst/yaml/chromedriver.yml b/inst/yaml/chromedriver.yml index 7f962bf..593d4e4 100644 --- a/inst/yaml/chromedriver.yml +++ b/inst/yaml/chromedriver.yml @@ -13,5 +13,5 @@ predlfunction: dlfunction: "binman::download_files": [] postdlfunction: - "binman::unziptar_dlfiles": + "wdman::unziptar_dlfiles": chmod: TRUE From 3d6fed8cd481e80be12795b87b0bd358e86c2525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20V=C3=B6lkle?= Date: Mon, 23 Oct 2023 11:57:46 +0200 Subject: [PATCH 03/16] fix dependencies --- DESCRIPTION | 5 +++-- NAMESPACE | 1 - R/predl_chrome_for_testing.R | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b35835a..f92f2c1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,8 +27,9 @@ Imports: assertthat, processx, yaml, - semver(>= 0.2.0), - utils + semver (>= 0.2.0), + utils, + jsonlite URL: https://docs.ropensci.org/wdman/, https://github.com/ropensci/wdman URLNote: https://github.com/ropensci/wdman BugReports: https://github.com/ropensci/wdman/issues diff --git a/NAMESPACE b/NAMESPACE index c0c0e77..f60ecc2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,7 +6,6 @@ export(iedriver) export(phantomjs) export(predl_chrome_for_testing) export(selenium) -export(unziptar_dlfiles) importFrom(assertthat,assert_that) importFrom(binman,app_dir) importFrom(binman,assign_directory) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index cc4967e..9111dad 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -49,7 +49,6 @@ predl_chrome_for_testing <- function(url, platform, history, assign_directory(app_links, appname) } -#' @export unziptar_dlfiles <- function(...) { x <- binman::unziptar_dlfiles(...) for (f in x) { From 2852533f30d52801a98bba2fcfed1b60cd1c43d1 Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 05:13:20 +0100 Subject: [PATCH 04/16] Fix Chrome errors --- R/predl_chrome_for_testing.R | 41 ++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index 9111dad..aa374de 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -16,17 +16,21 @@ predl_chrome_for_testing <- function(url, platform, history, platformregex = platform) { assert_that(is_URL_file(url)) assert_that(is_character(platform)) - platform <- c(mac64_m1 = "mac-arm64", - mac64 = "mac-x64", - linux32 = "linux32", - linux64 = "linux64", - win32 = "win64")[platform] + platform <- c( + mac64_m1 = "mac-arm64", + mac64 = "mac-x64", + linux32 = "linux32", + linux64 = "linux64", + win32 = "win64" + )[platform] assert_that(is_integer(history)) assert_that(is_string(appname)) assert_that(is_character(platformregex)) ver_data <- jsonlite::fromJSON(url)[[2]] - ver_data <- Filter(function(x) !is.null(x$downloads[[appname]]), - ver_data) + ver_data <- Filter( + function(x) !is.null(x$downloads[[appname]]), + ver_data + ) ver_data <- ver_data[order(as.numeric(names(ver_data)))] unwrap <- function(entry) { version <- entry$version @@ -41,17 +45,28 @@ predl_chrome_for_testing <- function(url, platform, history, extracted <- do.call(rbind, lapply(ver_data, unwrap)) app_links <- tapply(extracted, extracted$platform, identity) app_links <- app_links[platform] - names(app_links) <- c("mac-arm64" = "mac64_m1", - "mac-x64" = "mac64", - linux32 = "linux32", - linux64 = "linux64", - win64 = "win32")[names(app_links)] + names(app_links) <- c( + "mac-arm64" = "mac64_m1", + "mac-x64" = "mac64", + linux32 = "linux32", + linux64 = "linux64", + win64 = "win32" + )[names(app_links)] assign_directory(app_links, appname) } +#' Unzip/untar files +#' +#' Unzip or untar downloaded files +#' +#' @param ... Passed into [binman::unziptar_dlfiles]. +#' +#' @return The same as [binman::unziptar_dlfiles]. +#' +#' @export unziptar_dlfiles <- function(...) { x <- binman::unziptar_dlfiles(...) - for (f in x) { + for (f in x$processed) { dir <- tools::file_path_sans_ext(f) file.copy(list.files(dir, full.names = TRUE), dirname(dir)) } From e8014d89d4cedc12c78d2a2d0ed2f964cc7b8721 Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 05:22:45 +0100 Subject: [PATCH 05/16] Document --- NAMESPACE | 1 + man/unziptar_dlfiles.Rd | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 man/unziptar_dlfiles.Rd diff --git a/NAMESPACE b/NAMESPACE index f60ecc2..c0c0e77 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(iedriver) export(phantomjs) export(predl_chrome_for_testing) export(selenium) +export(unziptar_dlfiles) importFrom(assertthat,assert_that) importFrom(binman,app_dir) importFrom(binman,assign_directory) diff --git a/man/unziptar_dlfiles.Rd b/man/unziptar_dlfiles.Rd new file mode 100644 index 0000000..f2a5ff2 --- /dev/null +++ b/man/unziptar_dlfiles.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/predl_chrome_for_testing.R +\name{unziptar_dlfiles} +\alias{unziptar_dlfiles} +\title{Unzip/untar files} +\usage{ +unziptar_dlfiles(...) +} +\arguments{ +\item{...}{Passed into [binman::unziptar_dlfiles].} +} +\value{ +The same as [binman::unziptar_dlfiles]. +} +\description{ +Unzip or untar downloaded files +} From 564c932627584ce4126749746e2134b960ee1674 Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 05:31:57 +0100 Subject: [PATCH 06/16] Use rlang::try_fetch() to display errors --- inst/etc/checks.R | 98 +++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 34 deletions(-) diff --git a/inst/etc/checks.R b/inst/etc/checks.R index ba83622..4ab3d76 100644 --- a/inst/etc/checks.R +++ b/inst/etc/checks.R @@ -2,47 +2,77 @@ library(wdman) tries <- list() -tries$chrome <- tryCatch({ - print("chrome") - tmp <- chrome(verbose = TRUE) - print(tmp$log()) - tmp$stop() - tmp -}, error = function(e) {print(e$message); e}) - -tries$gecko <- tryCatch({ - print("gecko") - tmp <- gecko(verbose = TRUE) - print(tmp$log()) - tmp$stop() - tmp -}, error = function(e) {print(e$message); e}) +tries$chrome <- rlang::try_fetch( + { + print("chrome") + tmp <- chrome(verbose = TRUE) + print(tmp$log()) + tmp$stop() + tmp + }, + error = function(e) { + print(e) + e + } +) -tries$phantomjs <- tryCatch({ - print("phantomjs") - tmp <- phantomjs(verbose = TRUE) - print(tmp$log()) - tmp$stop() - tmp -}, error = function(e) {print(e$message); e}) +tries$gecko <- tryCatch( + { + print("gecko") + tmp <- gecko(verbose = TRUE) + print(tmp$log()) + tmp$stop() + tmp + }, + error = function(e) { + print(e$message) + e + } +) -if (Sys.info()[["sysname"]] == "Windows") { - tries$iedriver <- tryCatch({ - print("iedriver") - tmp <- iedriver(verbose = TRUE) +tries$phantomjs <- tryCatch( + { + print("phantomjs") + tmp <- phantomjs(verbose = TRUE) print(tmp$log()) tmp$stop() tmp - }, error = function(e) {print(e$message); e}) + }, + error = function(e) { + print(e$message) + e + } +) + +if (Sys.info()[["sysname"]] == "Windows") { + tries$iedriver <- tryCatch( + { + print("iedriver") + tmp <- iedriver(verbose = TRUE) + print(tmp$log()) + tmp$stop() + tmp + }, + error = function(e) { + print(e$message) + e + } + ) } -tries$selenium <- tryCatch({ - print("selenium") - tmp <- selenium(verbose = TRUE) - print(tmp$log()) - tmp$stop() - tmp -}, error = function(e) {print(e$message); e}) +tries$selenium <- tryCatch( + { + print("selenium") + tmp <- selenium(verbose = TRUE) + print(tmp$log()) + tmp$stop() + tmp + }, + error = function(e) { + print(e$message) + e + } +) errors <- sapply(tries, function(x) is(x, "simpleError")) if (any(errors)) { From e184b6db0aac1017a3d563688e678f66937332f9 Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 07:31:28 +0100 Subject: [PATCH 07/16] Fix platform pattern matching --- R/predl_chrome_for_testing.R | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index aa374de..a21f814 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -16,13 +16,6 @@ predl_chrome_for_testing <- function(url, platform, history, platformregex = platform) { assert_that(is_URL_file(url)) assert_that(is_character(platform)) - platform <- c( - mac64_m1 = "mac-arm64", - mac64 = "mac-x64", - linux32 = "linux32", - linux64 = "linux64", - win32 = "win64" - )[platform] assert_that(is_integer(history)) assert_that(is_string(appname)) assert_that(is_character(platformregex)) @@ -44,14 +37,12 @@ predl_chrome_for_testing <- function(url, platform, history, } extracted <- do.call(rbind, lapply(ver_data, unwrap)) app_links <- tapply(extracted, extracted$platform, identity) - app_links <- app_links[platform] - names(app_links) <- c( - "mac-arm64" = "mac64_m1", - "mac-x64" = "mac64", - linux32 = "linux32", - linux64 = "linux64", - win64 = "win32" - )[names(app_links)] + has_platform <- vapply( + names(app_links), + function(x) any(grepl(platformregex, x, perl = TRUE)), + FUN.VALUE = logical(1) + ) + app_links <- app_links[has_platform] assign_directory(app_links, appname) } From 45b0c5cd0189569a7de46cf5c1aab7ef10ea40dc Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 07:39:35 +0100 Subject: [PATCH 08/16] Revert "Fix platform pattern matching" This reverts commit e184b6db0aac1017a3d563688e678f66937332f9. --- R/predl_chrome_for_testing.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index a21f814..4814ef0 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -36,6 +36,7 @@ predl_chrome_for_testing <- function(url, platform, history, } } extracted <- do.call(rbind, lapply(ver_data, unwrap)) + print(extracted) app_links <- tapply(extracted, extracted$platform, identity) has_platform <- vapply( names(app_links), From 4fdb9e78afe549d2b397f1c359d7c6b1cbe20855 Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 10:38:31 +0100 Subject: [PATCH 09/16] Fix chromedriver.yml --- NAMESPACE | 2 +- R/predl_chrome_for_testing.R | 25 +++++++++++-------- inst/yaml/chromedriver.yml | 8 +++--- ...ar_dlfiles.Rd => unziptar_chromedriver.Rd} | 11 ++++---- 4 files changed, 25 insertions(+), 21 deletions(-) rename man/{unziptar_dlfiles.Rd => unziptar_chromedriver.Rd} (54%) diff --git a/NAMESPACE b/NAMESPACE index c0c0e77..f09185e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,7 +6,7 @@ export(iedriver) export(phantomjs) export(predl_chrome_for_testing) export(selenium) -export(unziptar_dlfiles) +export(unziptar_chromedriver) importFrom(assertthat,assert_that) importFrom(binman,app_dir) importFrom(binman,assign_directory) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index 4814ef0..f088d4a 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -36,31 +36,34 @@ predl_chrome_for_testing <- function(url, platform, history, } } extracted <- do.call(rbind, lapply(ver_data, unwrap)) - print(extracted) app_links <- tapply(extracted, extracted$platform, identity) - has_platform <- vapply( - names(app_links), - function(x) any(grepl(platformregex, x, perl = TRUE)), - FUN.VALUE = logical(1) - ) - app_links <- app_links[has_platform] + print(names(app_links)) + print(platform) + app_links <- app_links[platform] + print(app_links) assign_directory(app_links, appname) } -#' Unzip/untar files +#' Unzip/untar the chromedriver file #' -#' Unzip or untar downloaded files +#' Unzip or untar a downloaded chromedriver file, then extract it from +#' its folder. #' #' @param ... Passed into [binman::unziptar_dlfiles]. #' #' @return The same as [binman::unziptar_dlfiles]. #' #' @export -unziptar_dlfiles <- function(...) { +unziptar_chromedriver <- function(...) { + chmod <- list(...)$chmod x <- binman::unziptar_dlfiles(...) for (f in x$processed) { dir <- tools::file_path_sans_ext(f) - file.copy(list.files(dir, full.names = TRUE), dirname(dir)) + file.copy(list.files(dir, full.names = TRUE), dirname(dir), copy.mode = TRUE) + + if (chmod && .Platform$OS.type != "windows") { + Sys.chmod(list.files(dirname(dir), pattern = "^chromedriver$", full.names = TRUE), "0755") + } } x } diff --git a/inst/yaml/chromedriver.yml b/inst/yaml/chromedriver.yml index 593d4e4..e212729 100644 --- a/inst/yaml/chromedriver.yml +++ b/inst/yaml/chromedriver.yml @@ -3,15 +3,15 @@ predlfunction: "wdman::predl_chrome_for_testing": url: https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone-with-downloads.json platform: - - mac64_m1 - - mac64 - - linux32 + - mac-arm64 + - mac-x64 - linux64 - win32 + - win64 history: 3 appname: "chromedriver" dlfunction: "binman::download_files": [] postdlfunction: - "wdman::unziptar_dlfiles": + "wdman::unziptar_chromedriver": chmod: TRUE diff --git a/man/unziptar_dlfiles.Rd b/man/unziptar_chromedriver.Rd similarity index 54% rename from man/unziptar_dlfiles.Rd rename to man/unziptar_chromedriver.Rd index f2a5ff2..0c8ef5c 100644 --- a/man/unziptar_dlfiles.Rd +++ b/man/unziptar_chromedriver.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/predl_chrome_for_testing.R -\name{unziptar_dlfiles} -\alias{unziptar_dlfiles} -\title{Unzip/untar files} +\name{unziptar_chromedriver} +\alias{unziptar_chromedriver} +\title{Unzip/untar the chromedriver file} \usage{ -unziptar_dlfiles(...) +unziptar_chromedriver(...) } \arguments{ \item{...}{Passed into [binman::unziptar_dlfiles].} @@ -13,5 +13,6 @@ unziptar_dlfiles(...) The same as [binman::unziptar_dlfiles]. } \description{ -Unzip or untar downloaded files +Unzip or untar a downloaded chromedriver file, then extract it from +its folder. } From bc68bd93d8a9cd73c73f3925c590153c750b73bd Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 14:19:21 +0100 Subject: [PATCH 10/16] Update mac_machine() to include new Mac platforms --- R/utils.R | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/R/utils.R b/R/utils.R index df5ed51..820aa54 100644 --- a/R/utils.R +++ b/R/utils.R @@ -75,12 +75,13 @@ read_pipes <- function(env, outfile, errfile, pipe = "both", unix_spawn_tofile <- function(command, args, outfile, errfile, ...) { tfile <- tempfile(fileext = ".sh") write("#!/bin/sh", tfile) - write(paste(c( - shQuote(command), args, ">", - shQuote(outfile), "2>", shQuote(errfile) - ), collapse = " "), - tfile, - append = TRUE + write( + paste(c( + shQuote(command), args, ">", + shQuote(outfile), "2>", shQuote(errfile) + ), collapse = " "), + tfile, + append = TRUE ) Sys.chmod(tfile) processx::process$new(tfile, cleanup_tree = TRUE) @@ -124,5 +125,5 @@ kill_process <- function(p) { # Figure out if installing on an Intel or M1 mac mac_machine <- function() { - ifelse(Sys.info()[["machine"]] == "arm64", "mac(64_|os-)", "mac(64|os)$") + ifelse(Sys.info()[["machine"]] == "arm64", "mac(-arm64|64_|os-)", "mac(64|os|-x64)$") } From 460669f90bee63aae100ee0744b7e700a2827efb Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 14:22:51 +0100 Subject: [PATCH 11/16] Pattern match Windows correctly --- R/chrome.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/chrome.R b/R/chrome.R index c7a89b8..ed8ae53 100644 --- a/R/chrome.R +++ b/R/chrome.R @@ -104,7 +104,7 @@ chrome_check <- function(verbose, check = TRUE) { cyml[[platvec]] <- switch(Sys.info()["sysname"], Linux = grep(os_arch("linux"), cyml[[platvec]], value = TRUE), - Windows = grep("win", cyml[[platvec]], value = TRUE), + Windows = grep(os_arch("win"), cyml[[platvec]], value = TRUE), Darwin = grep(mac_machine(), cyml[[platvec]], value = TRUE), stop("Unknown OS") ) From d81ae6e496aa016b2009beef76ac0df01d7b244f Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 14:50:33 +0100 Subject: [PATCH 12/16] Use workaround for tapply() on older versions or R --- R/chrome.R | 14 ++++++++++++++ R/predl_chrome_for_testing.R | 3 --- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/R/chrome.R b/R/chrome.R index ed8ae53..35dffc5 100644 --- a/R/chrome.R +++ b/R/chrome.R @@ -125,6 +125,20 @@ chrome_check <- function(verbose, check = TRUE) { list(yaml = cyml, platform = chromeplat) } +# The same as tapply(x, y, identity), but works on older versions of R. +tapply_identity <- function(x, y) { + args <- c( + list( + function(x, ...) setNames(list(data.frame(...)), x), + y + ), + x, + USE.NAMES = FALSE + ) + + as.array(do.call(mapply, args)) +} + chrome_ver <- function(platform, version) { chromever <- list_versions("chromedriver")[[platform]] chromever <- if (identical(version, "latest")) { diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index f088d4a..15e3d64 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -37,10 +37,7 @@ predl_chrome_for_testing <- function(url, platform, history, } extracted <- do.call(rbind, lapply(ver_data, unwrap)) app_links <- tapply(extracted, extracted$platform, identity) - print(names(app_links)) - print(platform) app_links <- app_links[platform] - print(app_links) assign_directory(app_links, appname) } From 0476486ba7c5b1418ff2748a2d531d1111715ded Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 14:59:23 +0100 Subject: [PATCH 13/16] Actually use tapply_identity() --- R/chrome.R | 14 -------------- R/predl_chrome_for_testing.R | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/R/chrome.R b/R/chrome.R index 35dffc5..ed8ae53 100644 --- a/R/chrome.R +++ b/R/chrome.R @@ -125,20 +125,6 @@ chrome_check <- function(verbose, check = TRUE) { list(yaml = cyml, platform = chromeplat) } -# The same as tapply(x, y, identity), but works on older versions of R. -tapply_identity <- function(x, y) { - args <- c( - list( - function(x, ...) setNames(list(data.frame(...)), x), - y - ), - x, - USE.NAMES = FALSE - ) - - as.array(do.call(mapply, args)) -} - chrome_ver <- function(platform, version) { chromever <- list_versions("chromedriver")[[platform]] chromever <- if (identical(version, "latest")) { diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index 15e3d64..8e598a2 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -36,11 +36,26 @@ predl_chrome_for_testing <- function(url, platform, history, } } extracted <- do.call(rbind, lapply(ver_data, unwrap)) - app_links <- tapply(extracted, extracted$platform, identity) + app_links <- tapply_identity(extracted, extracted$platform) app_links <- app_links[platform] assign_directory(app_links, appname) } +# The same as tapply(x, y, identity), but works on older versions of R. +tapply_identity <- function(x, y) { + args <- c( + list( + function(x, ...) setNames(list(data.frame(...)), x), + y + ), + x, + USE.NAMES = FALSE + ) + + as.array(do.call(mapply, args)) +} + + #' Unzip/untar the chromedriver file #' #' Unzip or untar a downloaded chromedriver file, then extract it from From 26115d1591e2cd9ac85f70204c51bd8d6c3dc7de Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 15:33:14 +0100 Subject: [PATCH 14/16] Make sure chrome() works for old version --- R/chrome.R | 24 +++++++++++++++++++----- R/predl_chrome_for_testing.R | 14 ++++---------- inst/etc/checks.R | 18 ++++++++++++++++-- inst/yaml/chromedriver.yml | 12 ++++++------ inst/yaml/chromedriver_testing.yml | 17 +++++++++++++++++ 5 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 inst/yaml/chromedriver_testing.yml diff --git a/R/chrome.R b/R/chrome.R index ed8ae53..0d15388 100644 --- a/R/chrome.R +++ b/R/chrome.R @@ -36,7 +36,14 @@ chrome <- function(port = 4567L, version = "latest", path = "wd/hub", assert_that(is_string(version)) assert_that(is_string(path)) assert_that(is_logical(verbose)) - chromecheck <- chrome_check(verbose, check = check) + + if (version != "latest" && numeric_version(version) < "115.0.5790.170") { + chrome_old <- TRUE + } else { + chrome_old <- FALSE + } + + chromecheck <- chrome_check(verbose, check = check, chrome_old = chrome_old) chromeplat <- chromecheck[["platform"]] chromeversion <- chrome_ver(chromeplat, version) eopts <- list(...) @@ -97,10 +104,17 @@ chrome <- function(port = 4567L, version = "latest", path = "wd/hub", ) } -chrome_check <- function(verbose, check = TRUE) { - chromeyml <- system.file("yaml", "chromedriver.yml", package = "wdman") +chrome_check <- function(verbose, check = TRUE, chrome_old = FALSE) { + if (chrome_old) { + chromeyml <- system.file("yaml", "chromedriver.yml", package = "wdman") + predl_function <- "binman::predl_google_storage" + } else { + chromeyml <- system.file("yaml", "chromedriver_testing.yml", package = "wdman") + predl_function <- "wdman::predl_chrome_for_testing" + } + cyml <- yaml::yaml.load_file(chromeyml) - platvec <- c("predlfunction", "wdman::predl_chrome_for_testing", "platform") + platvec <- c("predlfunction", predl_function, "platform") cyml[[platvec]] <- switch(Sys.info()["sysname"], Linux = grep(os_arch("linux"), cyml[[platvec]], value = TRUE), @@ -111,7 +125,7 @@ chrome_check <- function(verbose, check = TRUE) { # Need regex that can tell mac64 and mac64_m1 apart if (cyml[[platvec]] %in% c("mac64", "mac64_m1")) { - platregexvec <- c("predlfunction", "wdman::predl_chrome_for_testing", "platformregex") + platregexvec <- c("predlfunction", predl_function, "platformregex") cyml[[platregexvec]] <- paste0(cyml[[platvec]], "\\.") } diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index 8e598a2..c82dbb1 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -43,18 +43,12 @@ predl_chrome_for_testing <- function(url, platform, history, # The same as tapply(x, y, identity), but works on older versions of R. tapply_identity <- function(x, y) { - args <- c( - list( - function(x, ...) setNames(list(data.frame(...)), x), - y - ), - x, - USE.NAMES = FALSE - ) + res <- lapply(unique(y), function(z) x[y == z, ]) - as.array(do.call(mapply, args)) -} + names(res) <- unique(y) + as.array(res) +} #' Unzip/untar the chromedriver file #' diff --git a/inst/etc/checks.R b/inst/etc/checks.R index 4ab3d76..519e77e 100644 --- a/inst/etc/checks.R +++ b/inst/etc/checks.R @@ -2,7 +2,7 @@ library(wdman) tries <- list() -tries$chrome <- rlang::try_fetch( +tries$chrome <- tryCatch( { print("chrome") tmp <- chrome(verbose = TRUE) @@ -11,7 +11,21 @@ tries$chrome <- rlang::try_fetch( tmp }, error = function(e) { - print(e) + print(e$message) + e + } +) + +tries$chrome_old <- tryCatch( + { + print("chrome (old)") + tmp <- chrome(verbose = TRUE, version = "114.0.5735.90") + print(tmp$log()) + tmp$stop() + tmp + }, + error = function(e) { + print(e$message) e } ) diff --git a/inst/yaml/chromedriver.yml b/inst/yaml/chromedriver.yml index e212729..c6ee99c 100644 --- a/inst/yaml/chromedriver.yml +++ b/inst/yaml/chromedriver.yml @@ -1,17 +1,17 @@ name: chromedriver predlfunction: - "wdman::predl_chrome_for_testing": - url: https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone-with-downloads.json + "binman::predl_google_storage": + url: https://www.googleapis.com/storage/v1/b/chromedriver/o platform: - - mac-arm64 - - mac-x64 + - mac64_m1 + - mac64 + - linux32 - linux64 - win32 - - win64 history: 3 appname: "chromedriver" dlfunction: "binman::download_files": [] postdlfunction: - "wdman::unziptar_chromedriver": + "binman::unziptar_dlfiles": chmod: TRUE diff --git a/inst/yaml/chromedriver_testing.yml b/inst/yaml/chromedriver_testing.yml new file mode 100644 index 0000000..e212729 --- /dev/null +++ b/inst/yaml/chromedriver_testing.yml @@ -0,0 +1,17 @@ +name: chromedriver +predlfunction: + "wdman::predl_chrome_for_testing": + url: https://googlechromelabs.github.io/chrome-for-testing/latest-versions-per-milestone-with-downloads.json + platform: + - mac-arm64 + - mac-x64 + - linux64 + - win32 + - win64 + history: 3 + appname: "chromedriver" +dlfunction: + "binman::download_files": [] +postdlfunction: + "wdman::unziptar_chromedriver": + chmod: TRUE From 2407d5df15b69cbacd3561a1d7efa368d0b5f889 Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 15:43:16 +0100 Subject: [PATCH 15/16] Make sure Windows pattern matches correctly with old Chrome --- R/chrome.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/chrome.R b/R/chrome.R index 0d15388..7eca804 100644 --- a/R/chrome.R +++ b/R/chrome.R @@ -115,7 +115,7 @@ chrome_check <- function(verbose, check = TRUE, chrome_old = FALSE) { cyml <- yaml::yaml.load_file(chromeyml) platvec <- c("predlfunction", predl_function, "platform") - cyml[[platvec]] <- + cyml_platvec <- switch(Sys.info()["sysname"], Linux = grep(os_arch("linux"), cyml[[platvec]], value = TRUE), Windows = grep(os_arch("win"), cyml[[platvec]], value = TRUE), @@ -123,6 +123,12 @@ chrome_check <- function(verbose, check = TRUE, chrome_old = FALSE) { stop("Unknown OS") ) + if (length(cyml_platvec) == 0) { + cyml_platvec <- grep("win", cyml[[platvec]], value = TRUE) + } + + cyml[[platvec]] <- cyml_platvec + # Need regex that can tell mac64 and mac64_m1 apart if (cyml[[platvec]] %in% c("mac64", "mac64_m1")) { platregexvec <- c("predlfunction", predl_function, "platformregex") From c1c874fe7a1e7dbde86df8affac095d1cfa8014a Mon Sep 17 00:00:00 2001 From: Ashby Thorpe Date: Wed, 25 Oct 2023 16:07:24 +0100 Subject: [PATCH 16/16] Document and clean up functions --- R/predl_chrome_for_testing.R | 59 +++++++++++++++++++----------- inst/etc/checks.R | 1 + inst/yaml/chromedriver_testing.yml | 2 - man/predl_chrome_for_testing.Rd | 35 ++++++++---------- man/unziptar_chromedriver.Rd | 18 +++++++-- 5 files changed, 69 insertions(+), 46 deletions(-) diff --git a/R/predl_chrome_for_testing.R b/R/predl_chrome_for_testing.R index c82dbb1..40c235b 100644 --- a/R/predl_chrome_for_testing.R +++ b/R/predl_chrome_for_testing.R @@ -1,33 +1,38 @@ -#' Pre-download function for Chrome-for-testing site +#' Pre-download function for Chrome for Testing site #' -#' @param url URL of the JSON to use for files +#' Prepare to download Chromedriver from the Chrome for Testing site. +#' +#' @param url URL containing the JSON used to locate files. #' @param platform One of `c("linux64", "mac-arm64", "mac-x64", -#' "win32", "win64") -#' @param history Integer number of recent entries -#' @param appname Name of the app, typically `"chromedriver"` -#' @param platformregex A filter for platforms. Defaults to the platform names. +#' "win32", "win64")`. +#' +#' @return +#' A named list of dataframes. The name indicates the platform. The +#' dataframe should contain the version, url, and file to be processed. +#' Used as input for [binman::download_files()] or equivalent. +#' +#' @examples +#' \dontrun{ +#' # predl_chrome_for_testing() is used by chrome() +#' chrome <- chrome() +#' chrome$stop() +#' } #' -#' @return A named list of dataframes. The name indicates the platform. The dataframe should contain the version, url, and file to -#' be processed. Used as input for `binman::download_files()` or an equivalent. #' @importFrom binman assign_directory +#' #' @export -predl_chrome_for_testing <- function(url, platform, history, - appname, - platformregex = platform) { +predl_chrome_for_testing <- function(url, platform) { assert_that(is_URL_file(url)) assert_that(is_character(platform)) - assert_that(is_integer(history)) - assert_that(is_string(appname)) - assert_that(is_character(platformregex)) ver_data <- jsonlite::fromJSON(url)[[2]] ver_data <- Filter( - function(x) !is.null(x$downloads[[appname]]), + function(x) !is.null(x$downloads[["chromedriver"]]), ver_data ) ver_data <- ver_data[order(as.numeric(names(ver_data)))] unwrap <- function(entry) { version <- entry$version - downloads <- entry$downloads[[appname]] + downloads <- entry$downloads[["chromedriver"]] if (!is.null(downloads)) { platform <- downloads$platform url <- downloads$url @@ -38,7 +43,7 @@ predl_chrome_for_testing <- function(url, platform, history, extracted <- do.call(rbind, lapply(ver_data, unwrap)) app_links <- tapply_identity(extracted, extracted$platform) app_links <- app_links[platform] - assign_directory(app_links, appname) + assign_directory(app_links, "chromedriver") } # The same as tapply(x, y, identity), but works on older versions of R. @@ -55,14 +60,24 @@ tapply_identity <- function(x, y) { #' Unzip or untar a downloaded chromedriver file, then extract it from #' its folder. #' -#' @param ... Passed into [binman::unziptar_dlfiles]. +#' @param dlfiles Passed into [binman::unziptar_dlfiles]: A data frame of +#' files. +#' @param chmod If `TRUE`, the files are made executable. +#' +#' @returns The same as [binman::unziptar_dlfiles()]: a list of character +#' vectors representing the processed files. #' -#' @return The same as [binman::unziptar_dlfiles]. +#' @examples +#' \dontrun{ +#' # unziptar_chromedriver() is used by chrome() +#' chrome <- chrome() +#' chrome$stop() +#' } #' #' @export -unziptar_chromedriver <- function(...) { - chmod <- list(...)$chmod - x <- binman::unziptar_dlfiles(...) +unziptar_chromedriver <- function(dlfiles, chmod = TRUE) { + x <- binman::unziptar_dlfiles(dlfiles, chmod = chmod) + for (f in x$processed) { dir <- tools::file_path_sans_ext(f) file.copy(list.files(dir, full.names = TRUE), dirname(dir), copy.mode = TRUE) diff --git a/inst/etc/checks.R b/inst/etc/checks.R index 519e77e..f0e8928 100644 --- a/inst/etc/checks.R +++ b/inst/etc/checks.R @@ -18,6 +18,7 @@ tries$chrome <- tryCatch( tries$chrome_old <- tryCatch( { + # Version of chrome that is not on the Chrome for Testing site print("chrome (old)") tmp <- chrome(verbose = TRUE, version = "114.0.5735.90") print(tmp$log()) diff --git a/inst/yaml/chromedriver_testing.yml b/inst/yaml/chromedriver_testing.yml index e212729..55b2b4d 100644 --- a/inst/yaml/chromedriver_testing.yml +++ b/inst/yaml/chromedriver_testing.yml @@ -8,8 +8,6 @@ predlfunction: - linux64 - win32 - win64 - history: 3 - appname: "chromedriver" dlfunction: "binman::download_files": [] postdlfunction: diff --git a/man/predl_chrome_for_testing.Rd b/man/predl_chrome_for_testing.Rd index e8b89e0..a57266b 100644 --- a/man/predl_chrome_for_testing.Rd +++ b/man/predl_chrome_for_testing.Rd @@ -2,32 +2,29 @@ % Please edit documentation in R/predl_chrome_for_testing.R \name{predl_chrome_for_testing} \alias{predl_chrome_for_testing} -\title{Pre-download function for Chrome-for-testing site} +\title{Pre-download function for Chrome for Testing site} \usage{ -predl_chrome_for_testing( - url, - platform, - history, - appname, - platformregex = platform -) +predl_chrome_for_testing(url, platform) } \arguments{ -\item{url}{URL of the JSON to use for files} +\item{url}{URL containing the JSON used to locate files.} \item{platform}{One of `c("linux64", "mac-arm64", "mac-x64", -"win32", "win64")} - -\item{history}{Integer number of recent entries} - -\item{appname}{Name of the app, typically `"chromedriver"`} - -\item{platformregex}{A filter for platforms. Defaults to the platform names.} +"win32", "win64")`.} } \value{ -A named list of dataframes. The name indicates the platform. The dataframe should contain the version, url, and file to -be processed. Used as input for `binman::download_files()` or an equivalent. +A named list of dataframes. The name indicates the platform. The +dataframe should contain the version, url, and file to be processed. +Used as input for [binman::download_files()] or equivalent. } \description{ -Pre-download function for Chrome-for-testing site +Prepare to download Chromedriver from the Chrome for Testing site. +} +\examples{ +\dontrun{ +# predl_chrome_for_testing() is used by chrome() +chrome <- chrome() +chrome$stop() +} + } diff --git a/man/unziptar_chromedriver.Rd b/man/unziptar_chromedriver.Rd index 0c8ef5c..dcb7a22 100644 --- a/man/unziptar_chromedriver.Rd +++ b/man/unziptar_chromedriver.Rd @@ -4,15 +4,27 @@ \alias{unziptar_chromedriver} \title{Unzip/untar the chromedriver file} \usage{ -unziptar_chromedriver(...) +unziptar_chromedriver(dlfiles, chmod = TRUE) } \arguments{ -\item{...}{Passed into [binman::unziptar_dlfiles].} +\item{dlfiles}{Passed into [binman::unziptar_dlfiles]: A data frame of +files.} + +\item{chmod}{If `TRUE`, the files are made executable.} } \value{ -The same as [binman::unziptar_dlfiles]. +The same as [binman::unziptar_dlfiles()]: a list of character + vectors representing the processed files. } \description{ Unzip or untar a downloaded chromedriver file, then extract it from its folder. } +\examples{ +\dontrun{ +# unziptar_chromedriver() is used by chrome() +chrome <- chrome() +chrome$stop() +} + +}