r-lib / pak

A fresh approach to package installation
https://pak.r-lib.org
642 stars 56 forks source link

{pak} cannot resolve dependencies with public PM as single repo #574

Open pat-s opened 6 months ago

pat-s commented 6 months ago

(Applies to any package, brew is just an example)

getOption("repos")
                                                             CRAN 
"https://packagemanager.posit.co/cran/__linux__/rhel9/2023-10-31" 

pak::pkg_install("brew")
Error: 
! error in pak subprocess
Caused by error: 
! Could not solve package dependencies:
* brew: Can't find package called brew.

---
Backtrace:
1. pak::pkg_install("brew")
2. pak:::remote(function(...) get("pkg_install_make_plan", asNamespace("pak"))(...), …
3. err$throw(res$error)
---
Subprocess backtrace:
1. base::withCallingHandlers(cli_message = function(msg) { …
2. get("pkg_install_make_plan", asNamespace("pak"))(...)
3. prop$stop_for_solution_error()
4. private$plan$stop_for_solve_error()
5. pkgdepends:::pkgplan_stop_for_solve_error(self, private)
6. base::throw(new_error("Could not solve package dependencies:\n", msg, …
7. | base::signalCondition(cond)
8. global (function (e) …

install.packages() works just fine:

getOption("repos")
                                                             CRAN 
"https://packagemanager.posit.co/cran/__linux__/rhel9/2023-10-31" 

install.packages("brew")
Installing package into ‘/home/x60039989/R/x86_64-pc-linux-gnu-library/4.3’
(as ‘lib’ is unspecified)
trying URL 'https://packagemanager.posit.co/cran/__linux__/rhel9/2023-10-31/src/contrib/brew_1.0-8.tar.gz'
Content type 'binary/octet-stream' length 80367 bytes (78 KB)
==================================================
downloaded 78 KB

* installing *binary* package ‘brew’ ...
* DONE (brew)

pak 0.7.1

gaborcsardi commented 6 months ago

What is the output of pak::system_r_platform()?

pat-s commented 6 months ago
> pak::system_r_platform()
[1] "x86_64-pc-linux-gnu-rhel-9.3"
gaborcsardi commented 6 months ago

Hmmm, I cannot reproduce that:

> options(repos = c(CRAN = "https://packagemanager.posit.co/cran/__linux__/rhel9/2023-10-31"))
> pak::pkg_install("brew?reinstall&nocache")
✔ Updated metadata database: 4.64 MB in 8 files.
✔ Updating metadata database ... done

→ Will install 1 package.
→ Will download 1 package with unknown size.
+ brew   1.0-8 [dl]
ℹ Getting 1 pkg with unknown size
✔ Got brew 1.0-8 (x86_64-pc-linux-gnu-rhel-9.2) (80.37 kB)
✔ Downloaded 1 package (80.37 kB) in 1.1s
✔ Installed brew 1.0-8  (1.1s)
✔ 1 pkg: added 1, dld 1 (80.37 kB) [9s]
> pak::system_r_platform()
[1] "x86_64-pc-linux-gnu-rhel-9.2"
> pak::pak_sitrep()
* pak version:
- 0.7.1
* Version information:
- pak platform: x86_64-pc-linux-musl (current: x86_64-pc-linux-gnu, compatible)
...
pat-s commented 1 month ago

I've tracked it down and it seems to be caused by

https://github.com/r-lib/pkgcache/blob/48c1017bbe75534a514ce226febb97687aaeee78/R/metadata-cache.R#L416C17-L416C31

which does not work in a secured environment which only has whitelistings for packagemanager.posit.co, cran.r-project.org and rspm-sync.rstudio.com.

gaborcsardi commented 1 month ago

So what happens if you do this?

curl::curl_fetch_memory("https://cran.r-pkg.org/metadata/src/contrib/METADATA2.gz")
pat-s commented 1 month ago
curl::curl_fetch_memory("https://cran.r-pkg.org/metadata/src/contrib/METADATA2.gz")
$url
[1] "https://cran.r-pkg.org/metadata/src/contrib/METADATA2.gz"

$status_code
[1] 403

$type
[1] "text/html"