Skip to content
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

Fix for new chromedriver location #35

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ 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
RoxygenNote: 7.2.1
RoxygenNote: 7.2.3
VignetteBuilder: knitr
Config/testthat/edition: 3
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ export(chrome)
export(gecko)
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)
importFrom(binman,list_versions)
importFrom(binman,process_yaml)
importFrom(binman,rm_platform)
Expand Down
4 changes: 2 additions & 2 deletions R/chrome.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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]], "\\.")
}

Expand Down
71 changes: 71 additions & 0 deletions R/predl_chrome_for_testing.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#' 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)
}

#' Unzip/untar downloaded files
#'
#' Unzip or untar downloaded files. Copies files into the
#' expected position.
#'
#' @param ... Passed into [binman::unziptar_dlfiles].
#'
#' @return The same as [binman::unziptar_dlfiles]: a list of character
#' vectors indicating files processed.
#'
#' @export
#' @md
unziptar_dlfiles <- function(...) {
dmurdoch marked this conversation as resolved.
Show resolved Hide resolved
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))
}
x
}
6 changes: 3 additions & 3 deletions inst/yaml/chromedriver.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,5 +13,5 @@ predlfunction:
dlfunction:
"binman::download_files": []
postdlfunction:
"binman::unziptar_dlfiles":
"wdman::unziptar_dlfiles":
chmod: TRUE
33 changes: 33 additions & 0 deletions man/predl_chrome_for_testing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/unziptar_dlfiles.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading