Skip to content

Commit

Permalink
Update embedded pkgcache
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborcsardi committed Aug 8, 2024
1 parent 6931513 commit ff7510e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 489 deletions.
4 changes: 2 additions & 2 deletions src/library/pkgcache/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE, r6 = FALSE)
RoxygenNote: 7.3.1.9000
RoxygenNote: 7.3.2
NeedsCompilation: yes
Packaged: 2024-06-25 08:37:02 UTC; gaborcsardi
Packaged: 2024-08-08 09:38:56 UTC; gaborcsardi
Author: Gábor Csárdi [aut, cre],
Posit Software, PBC [cph, fnd]
Maintainer: Gábor Csárdi <[email protected]>
6 changes: 6 additions & 0 deletions src/library/pkgcache/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
anyway, because PPM is in a consistent state w.r.t. metadata and
package files (https://github.com/r-lib/pak/issues/623).

* `parse_packages()` now does not throw a warning for empty `PACKAGES*`
files (#107).

* `repo_set()` and the `ppm_*()` functions, e.g. `ppm_snapshots()`, now
work again after the PPM API changes (#110, #115).

# pkgcache 2.2.2

* pkgcache now treats R 4.5.x (current R-devel) macOS binaries
Expand Down
1 change: 1 addition & 0 deletions src/library/pkgcache/R/aaa-async.R
Original file line number Diff line number Diff line change
Expand Up @@ -2886,6 +2886,7 @@ http_post <- mark_as_async(http_post)
http_delete <- function(url, headers = character(), file = NULL,
options = list()) {
url; headers; options;
options <- get_default_curl_options(options)

make_deferred_http(
function() {
Expand Down
2 changes: 1 addition & 1 deletion src/library/pkgcache/R/installed.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ parse_packages <- function(path, type = NULL) {
}
}

tbl <- as_data_frame(tab)
tbl <- as_data_frame(tab %||% list())

tbl
}
Expand Down
438 changes: 0 additions & 438 deletions src/library/pkgcache/R/onload.R

Large diffs are not rendered by default.

39 changes: 4 additions & 35 deletions src/library/pkgcache/R/ppm.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,45 +107,14 @@ get_ppm_base_url <- function() {
#' ppm_snapshots()

ppm_snapshots <- function() {
snp <- synchronise(async_get_ppm_versions(forget = TRUE))
last <- as.Date(format_iso_8601(Sys.time())) - 1
dts <- seq(as.Date("2017-10-10"), last, by = 1)
data_frame(
date = parse_iso_8601(names(snp)),
id = as.integer(unname(snp))
date = dts,
id = as.character(dts)
)
}

async_get_ppm_versions <- function(forget = FALSE, date = NULL) {
tmp1 <- tempfile()
def <- if (forget ||
(!is.null(date) && date < names(pkgenv$ppm_versions[1])) ||
(!is.null(date) && date > last(names(pkgenv$ppm_versions)))) {
url <- Sys.getenv(
"PKGCACHE_PPM_TRANSACTIONS_URL",
paste0(get_ppm_base_url(), "/__api__/sources/1/transactions?_limit=10000")
)
tmp <- tempfile()
download_file(url, tmp1)$
then(function(res) {
resp <- jsonlite::fromJSON(tmp1, simplifyVector = FALSE)
vrs <- structure(
vcapply(resp, function(x) as.character(x$id)),
names = vcapply(resp, function(x) as.character(x$published_to))
)
pkgenv$ppm_versions <- vrs[order(as.Date(names(vrs)))]
})$
catch(error = function(err) {
warning("Failed to download PPM versions")
})

} else {
async_constant()
}

def$
finally(function() unlink(tmp1))$
then(function() pkgenv$ppm_versions)
}

#' List all platforms supported by Posit Package Manager (PPM)
#'
#' @return Data frame with columns:
Expand Down
16 changes: 5 additions & 11 deletions src/library/pkgcache/R/repo-set.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ repo_get <- function(r_version = getRversion(), bioc = TRUE,
#'
#' @export
#' @examplesIf pkgcache:::run_examples()
#' repo_resolve("PPM@2020-01-21")
#' repo_resolve("PPM@2021-01-21")
#' #' repo_resolve("[email protected]")
#' #' repo_resolve("[email protected]")

Expand Down Expand Up @@ -211,7 +211,7 @@ repo_sugar_ppm <- function(x, nm) {

# if we may have binaries, then get the distro data as well
synchronise(when_all(
async_get_ppm_versions(date = if (as.character(date) == "latest") NULL else date),
ppm_snapshots(),
if (binaries) {
async_get_ppm_status(
distribution = current$distribution,
Expand Down Expand Up @@ -239,16 +239,10 @@ repo_sugar_ppm <- function(x, nm) {
if (as.character(date) == "latest") {
ver <- "latest"
} else {
vers <- pkgenv$ppm_versions
ppm_dates <- names(vers)
if (date < ppm_dates[1]) {
stop("PPM snapshots go back to ", as.Date(ppm_dates[1]), " only")
if (date < "2017-10-10") {
stop("PPM snapshots go back to 2017-10-10 only")
}
sel <- which(date <= ppm_dates)[1]
if (is.na(sel)) {
stop("Cannot find matching PPM snapshot for ", date)
}
ver <- vers[[sel]]
ver <- as.character(date)
}

# create repo URL
Expand Down
4 changes: 2 additions & 2 deletions src/library/pkgcache/src/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static R_INLINE int hash_string(char *str, int strlen) {

struct hash_table {
SEXP nms;
SEXP *nmsptr;
const SEXP *nmsptr;
SEXP cols;
int *tab;
int tablen;
Expand All @@ -45,7 +45,7 @@ struct hash_table {
static void hash_create(struct hash_table *table, SEXP nms, SEXP cols,
SEXP tab, int max_cols, int npkgs) {
table->nms = nms;
table->nmsptr = STRING_PTR(nms);
table->nmsptr = STRING_PTR_RO(nms);
table->cols = cols;
table->tab = INTEGER(tab);
table->tablen = LENGTH(tab);
Expand Down

0 comments on commit ff7510e

Please sign in to comment.