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

pkg_system_requirements only reports direct sys reqs and ignores imports #315

Closed
assignUser opened this issue Sep 6, 2021 · 5 comments
Closed

Comments

@assignUser
Copy link

As I noticed in r-lib/actions#370 local_system_requirments and pkg_system_requirements seem to behave unxepectedly different. local recursively reports all system requirements of the package and its dependencies, while pkg only reports requirements listed directly in the DESCRIPTION of the package. I assume this is a bug?

pth <- fs::path_temp("testpackage")
usethis::create_package(pth, rstudio = FALSE, check_name = FALSE, fields = list(Imports = "gert"))
#> v Creating ...
setwd(pth)
pak::local_install()
#> i Loading metadata database
#> i Loading metadata database
pak::local_system_requirements(os = "ubuntu", os_release = "18.04")
#> [1] "apt-get install -y software-properties-common"
#> [2] "add-apt-repository -y ppa:cran/libgit2"       
#> [3] "apt-get update"                               
#> [4] "apt-get install -y libcurl4-openssl-dev"      
#> [5] "apt-get install -y libssl-dev"                
#> [6] "apt-get install -y git"                       
#> [7] "apt-get install -y libgit2-dev"
pak::pkg_system_requirements("testpackage", os = "ubuntu", os_release = "18.04")
#> character(0)

Created on 2021-09-06 by the reprex package (v2.0.1)

@assignUser
Copy link
Author

This seems to also cause pak::pkg_install to fail installation of e.g. devtools when dependencies have additional system requirements (in this case curl/openssl)

> pak::pkg_install("devtools")
                                                                           
→ Will install 38 packages.Will update 12 packages.
.
.
.Building curl 4.3.2Failed to build curl 4.3.2                      
Error: Failed to build source package 'curl'    

@riccardoporreca
Copy link
Contributor

@assignUser, as far as I can understand, the two functions have intrinsically a different behavior in the way they use the RSPM API to retrieve system requirements (via pak:::system_requirements_internal()):

pkg_system_requirements() just calls the API for the given package name, and can only return sys reqs if the package is known to RSPM:

req_url <- sprintf(
"%s/sysreqs?all=false&pkgname=%s&distribution=%s&release=%s",
rspm_repo_url,
package,
os,
os_release
)
res <- curl::curl_fetch_memory(req_url)
data <- jsonlite::fromJSON(rawToChar(res$content), simplifyVector = FALSE)
pre_install <- unique(unlist(c(data[["pre_install"]], lapply(data[["requirements"]], function(x) x[["requirements"]][["pre_install"]]))))
install_scripts <- unique(unlist(c(data[["install_scripts"]], lapply(data[["requirements"]], function(x) x[["requirements"]][["install_scripts"]]))))

The API actually returns an error (https://packagemanager.rstudio.com/__api__/repos/1/sysreqs?all=false&pkgname=testpackage&distribution=ubuntu&release=18.04), which is however not really handled by pkg_system_requirements().

local_system_requirements() calls the API passing the DESCRIPTION file instead (from which the package dependencies are extracted and corresponding sys reqs returned):

desc_file <- normalizePath(file.path(root, "DESCRIPTION"), mustWork = FALSE)
if (!file.exists(desc_file)) {
stop("`", root, "` must contain a package.", call. = FALSE)
}
req_url <- sprintf(
"%s/sysreqs?distribution=%s&release=%s&suggests=true",
rspm_repo_url,
os,
os_release
)
h <- curl::new_handle()
desc_size <- file.size(desc_file)
desc_data <- readBin(desc_file, "raw", desc_size)
curl::handle_setheaders(h,
customrequest = "POST",
"content-type" = "text/plain"
)
curl::handle_setopt(h,
postfieldsize = desc_size,
postfields = desc_data
)
res <- curl::curl_fetch_memory(req_url, h)
data <- jsonlite::fromJSON(rawToChar(res$content), simplifyVector = FALSE)
pre_install <- unique(unlist(c(data[["pre_install"]], lapply(data[["dependencies"]], `[[`, "pre_install"))))
install_scripts <- unique(unlist(c(data[["install_scripts"]], lapply(data[["dependencies"]], `[[`, "install_scripts"))))

@assignUser
Copy link
Author

assignUser commented Oct 29, 2021

@riccardoporreca thank you for your detailed answer. So my issue is kind of an edge case with a package that is not on CRAN/RSPM. I still think that the different behavior should be noted in the docs and pkg_system_requirements() should communicate API failures to the user to make troubleshooting easier.

riccardoporreca added a commit to riccardoporreca/pak that referenced this issue Oct 30, 2021
* Multiple packages for `pkg_system_requirements` (r-lib#327).
* Clear distinction between the `local_` and `pkg_` flavors, with explicit mention about `pkg_` targeting *existing* packages (r-lib#315).
riccardoporreca added a commit to riccardoporreca/pak that referenced this issue Oct 30, 2021
…ib#315)

* Relying on the API "error" key in the retrieved content.
* Tested using the additional documentation examples => Could not locate package 'iDontExist'
riccardoporreca added a commit to riccardoporreca/pak that referenced this issue Oct 30, 2021
* For consistency with what done for `pkg_system_requirements()` (r-lib#315)
* Tested via
```r
root <- tempfile("devPkg")
dir.create(root)
file.create(file.path(root, "DESCRIPTION"))
local_system_requirements("ubuntu", "20.04", root = root)
# => Could not parse DESCRIPTION: EOF
```
jimhester pushed a commit that referenced this issue Nov 1, 2021
* Multiple packages for `pkg_system_requirements` (#327).
* Clear distinction between the `local_` and `pkg_` flavors, with explicit mention about `pkg_` targeting *existing* packages (#315).
jimhester pushed a commit that referenced this issue Nov 1, 2021
* Relying on the API "error" key in the retrieved content.
* Tested using the additional documentation examples => Could not locate package 'iDontExist'
jimhester pushed a commit that referenced this issue Nov 1, 2021
* For consistency with what done for `pkg_system_requirements()` (#315)
* Tested via
```r
root <- tempfile("devPkg")
dir.create(root)
file.create(file.path(root, "DESCRIPTION"))
local_system_requirements("ubuntu", "20.04", root = root)
# => Could not parse DESCRIPTION: EOF
```
@riccardoporreca
Copy link
Contributor

I still think that the different behavior should be noted in the docs and pkg_system_requirements() should communicate API failures to the user to make troubleshooting easier.

@assignUser, see commits above, merged by PR #328

@assignUser
Copy link
Author

@riccardoporreca Great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants