Skip to content

Migrate httr to httr2 and Update Dependencies in devtools #2604

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -21,8 +21,10 @@ Imports:
desc (>= 1.4.1),
ellipsis (>= 0.3.2),
fs (>= 1.5.2),
httr2 (>= 1.1.2),
lifecycle (>= 1.0.1),
memoise (>= 2.0.1),
mime (>= 0.13),
miniUI (>= 0.1.1.1),
pkgbuild (>= 1.3.1),
pkgdown (>= 2.0.6),
11 changes: 11 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -83,8 +83,17 @@ import(fs)
importFrom(cli,cat_bullet)
importFrom(cli,cat_rule)
importFrom(ellipsis,check_dots_used)
importFrom(fs,file_delete)
importFrom(fs,file_temp)
importFrom(httr2,req_body_multipart)
importFrom(httr2,req_perform)
importFrom(httr2,request)
importFrom(httr2,resp_body_raw)
importFrom(httr2,resp_body_string)
importFrom(httr2,resp_check_status)
importFrom(lifecycle,deprecated)
importFrom(memoise,memoise)
importFrom(mime,guess_type)
importFrom(pkgbuild,clean_dll)
importFrom(pkgbuild,find_rtools)
importFrom(pkgbuild,has_devel)
@@ -107,6 +116,8 @@ importFrom(remotes,install_svn)
importFrom(remotes,install_url)
importFrom(remotes,install_version)
importFrom(remotes,update_packages)
importFrom(rlang,check_installed)
importFrom(rlang,warn)
importFrom(sessioninfo,package_info)
importFrom(sessioninfo,session_info)
importFrom(stats,update)
26 changes: 14 additions & 12 deletions R/check-mac.R
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
#' @inheritParams check_win
#' @param dep_pkgs Additional custom dependencies to install prior to checking
#' the package.
#' @importFrom httr2 request req_body_multipart req_perform resp_check_status resp_body_string
#' @family build functions
#' @return The url with the check results (invisibly)
#' @export
@@ -40,26 +41,25 @@

url <- "https://mac.r-project.org/macbuilder/v1/submit"

rlang::check_installed("httr")
body <- list(pkgfile = httr::upload_file(built_path))
rlang::check_installed("httr2")
body <- list(pkgfile = upload_file(built_path))

Check warning on line 45 in R/check-mac.R

Codecov / codecov/patch

R/check-mac.R#L44-L45

Added lines #L44 - L45 were not covered by tests

# upload_file function implemented in utils.R

if (length(dep_built_paths) > 0) {
uploads <- lapply(dep_built_paths, httr::upload_file)
uploads <- lapply(dep_built_paths, upload_file)

Check warning on line 50 in R/check-mac.R

Codecov / codecov/patch

R/check-mac.R#L50

Added line #L50 was not covered by tests
names(uploads) <- rep("depfiles", length(uploads))
body <- append(body, uploads)
}

res <- httr::POST(url,
body = body,
headers = list(
"Content-Type" = "multipart/form-data"
),
encode = "multipart"
)
req <- httr2::request(url)
req <- httr2::req_body_multipart(req, !!!body)
res <- httr2::req_perform(req)

Check warning on line 57 in R/check-mac.R

Codecov / codecov/patch

R/check-mac.R#L55-L57

Added lines #L55 - L57 were not covered by tests

httr::stop_for_status(res, task = "Uploading package")
httr2::resp_check_status(res, info = "Uploading package")

Check warning on line 59 in R/check-mac.R

Codecov / codecov/patch

R/check-mac.R#L59

Added line #L59 was not covered by tests

response_url <- httr::content(res)$url
res_body <- httr2::resp_body_string(res)
response_url <- regmatches(res_body, regexpr("https://mac\\.R-project\\.org/macbuilder/results/[0-9a-zA-Z\\-]+/", res_body))

Check warning on line 62 in R/check-mac.R

Codecov / codecov/patch

R/check-mac.R#L61-L62

Added lines #L61 - L62 were not covered by tests

if (!quiet) {
time <- strftime(Sys.time() + 10 * 60, "%I:%M %p")
@@ -72,3 +72,5 @@

invisible(response_url)
}


2 changes: 1 addition & 1 deletion R/check.R
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
#' CRAN, and hence can take a reasonable amount of time.
#'
#' * Debugging flags for the compiler, set by
#' [`compiler_flags(FALSE)`][compiler_flags()].
#' [`compiler_flags(FALSE)`][pkgbuild::compiler_flags()].
#'
#' * If `aspell` is found, `_R_CHECK_CRAN_INCOMING_USE_ASPELL_`
#' is set to `TRUE`. If no spell checker is installed, a warning is issued.
33 changes: 21 additions & 12 deletions R/release.R
Original file line number Diff line number Diff line change
@@ -277,23 +277,27 @@

# Initial upload ---------
cli::cli_inform(c(i = "Uploading package & comments"))
rlang::check_installed("httr")
rlang::check_installed("httr2")

Check warning on line 280 in R/release.R

Codecov / codecov/patch

R/release.R#L280

Added line #L280 was not covered by tests
body <- list(
pkg_id = "",
name = maint$name,
email = maint$email,
uploaded_file = httr::upload_file(built_path, "application/x-gzip"),
uploaded_file = upload_file(built_path, "application/x-gzip"),

Check warning on line 285 in R/release.R

Codecov / codecov/patch

R/release.R#L285

Added line #L285 was not covered by tests
comment = comments,
upload = "Upload package"
)
r <- httr::POST(cran_submission_url, body = body)

req <- httr2::request(cran_submission_url)
req <- httr2::req_body_multipart(req, !!!body)
r <- httr2::req_perform(req)

Check warning on line 292 in R/release.R

Codecov / codecov/patch

R/release.R#L290-L292

Added lines #L290 - L292 were not covered by tests

# If a 404 likely CRAN is closed for maintenance, try to get the message
if (httr::status_code(r) == 404) {
if (httr2::resp_status(r) == 404) {

Check warning on line 295 in R/release.R

Codecov / codecov/patch

R/release.R#L295

Added line #L295 was not covered by tests
msg <- ""
try({
r2 <- httr::GET(sub("index2", "index", cran_submission_url))
msg <- extract_cran_msg(httr::content(r2, "text"))
try({
req2 <- httr2::request(sub("index2", "index", cran_submission_url))
r2 <- httr2::req_perform(req2)
msg <- extract_cran_msg(httr2::resp_body_string(r2))

Check warning on line 300 in R/release.R

Codecov / codecov/patch

R/release.R#L297-L300

Added lines #L297 - L300 were not covered by tests
})
cli::cli_abort(
c(
@@ -304,8 +308,8 @@
)
}

httr::stop_for_status(r)
new_url <- httr::parse_url(r$url)
httr2::resp_check_status(r)
new_url <- httr2::url_parse(r$url)

Check warning on line 312 in R/release.R

Codecov / codecov/patch

R/release.R#L311-L312

Added lines #L311 - L312 were not covered by tests

# Confirmation -----------
cli::cli_inform(c(i = "Confirming submission"))
@@ -316,9 +320,14 @@
policy_check = "1/",
submit = "Submit package"
)
r <- httr::POST(cran_submission_url, body = body)
httr::stop_for_status(r)
new_url <- httr::parse_url(r$url)

req <- httr2::request(cran_submission_url)
req <- httr2::req_body_multipart(req, !!!body)
r <- httr2::req_perform(req)

Check warning on line 326 in R/release.R

Codecov / codecov/patch

R/release.R#L324-L326

Added lines #L324 - L326 were not covered by tests

httr2::resp_check_status(r)

Check warning on line 328 in R/release.R

Codecov / codecov/patch

R/release.R#L328

Added line #L328 was not covered by tests

new_url <- httr2::url_parse(r$url)

Check warning on line 330 in R/release.R

Codecov / codecov/patch

R/release.R#L330

Added line #L330 was not covered by tests
if (new_url$query$submit == "1") {
cli::cli_inform(c(
"v" = "Package submission successful",
2 changes: 1 addition & 1 deletion R/remotes.R
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ with_pkgbuild_build_tools <- function(fun) {
#'

#' These functions are re-exported from the remotes package. They differ only
#' that the ones in devtools use the [ellipsis] package to ensure all dotted
#' that the ones in devtools use the [ellipsis::check_dots_used] feature to ensure all dotted
#' arguments are used.
#'
#' Follow the links below to see the documentation.
20 changes: 13 additions & 7 deletions R/run-source.R
Original file line number Diff line number Diff line change
@@ -13,6 +13,10 @@
#' @param url url
#' @param ... other options passed to [source()]
#' @param sha1 The (prefix of the) SHA-1 hash of the file at the remote URL.
#' @importFrom fs file_temp file_delete
#' @importFrom rlang check_installed warn
#' @importFrom httr2 request req_perform resp_check_status resp_body_raw
#' @importFrom ellipsis check_dots_used
#' @export
#' @seealso [source_gist()]
#' @examples
@@ -31,18 +35,20 @@
source_url <- function(url, ..., sha1 = NULL) {
stopifnot(is.character(url), length(url) == 1)
rlang::check_installed("digest")
rlang::check_installed("httr")
rlang::check_installed("httr2")

Check warning on line 38 in R/run-source.R

Codecov / codecov/patch

R/run-source.R#L38

Added line #L38 was not covered by tests

temp_file <- file_temp()
on.exit(file_delete(temp_file), add = TRUE)
temp_file <- fs::file_temp()
on.exit(fs::file_delete(temp_file), add = TRUE)

Check warning on line 41 in R/run-source.R

Codecov / codecov/patch

R/run-source.R#L40-L41

Added lines #L40 - L41 were not covered by tests

request <- httr::GET(url)
httr::stop_for_status(request)
writeBin(httr::content(request, type = "raw"), temp_file)
resp <- httr2::req_perform(httr2::request(url))

Check warning on line 43 in R/run-source.R

Codecov / codecov/patch

R/run-source.R#L43

Added line #L43 was not covered by tests

httr2::resp_check_status(resp)

Check warning on line 45 in R/run-source.R

Codecov / codecov/patch

R/run-source.R#L45

Added line #L45 was not covered by tests

writeBin(httr2::resp_body_raw(resp), temp_file)

Check warning on line 47 in R/run-source.R

Codecov / codecov/patch

R/run-source.R#L47

Added line #L47 was not covered by tests

check_sha1(temp_file, sha1)

check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
ellipsis::check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))

Check warning on line 51 in R/run-source.R

Codecov / codecov/patch

R/run-source.R#L51

Added line #L51 was not covered by tests
source(temp_file, ...)
}

9 changes: 9 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -45,3 +45,12 @@
is_rstudio_running <- function() {
!is_testing() && rstudioapi::isAvailable()
}

#' @importFrom mime guess_type
upload_file <- function(path, type = NULL) {
stopifnot(is.character(path), length(path) == 1, file.exists(path))
if (is.null(type)) {
type <- mime::guess_type(path)

Check warning on line 53 in R/utils.R

Codecov / codecov/patch

R/utils.R#L51-L53

Added lines #L51 - L53 were not covered by tests
}
curl::form_file(path, type)

Check warning on line 55 in R/utils.R

Codecov / codecov/patch

R/utils.R#L55

Added line #L55 was not covered by tests
}
2 changes: 1 addition & 1 deletion man/check.Rd

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

13 changes: 5 additions & 8 deletions man/load_all.Rd

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

7 changes: 5 additions & 2 deletions man/reexports.Rd

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

2 changes: 1 addition & 1 deletion man/remote-reexports.Rd

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