From 24ac1635924cb546b6ab5bf553a6a6cfe8807785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Ucar?= Date: Tue, 9 Apr 2024 12:56:56 +0200 Subject: [PATCH] Try binary installation of build-only deps for source packages (#82) * additional step to pull build-only deps for src packages * some refactoring * don't pass dots down to installed.packages * add tests for hard_deps * bump version, update NEWS --- DESCRIPTION | 2 +- NEWS.md | 4 +++- R/integration.R | 9 +++---- R/utils.R | 49 +++++++++++++++++++++++--------------- cran-comments.md | 2 +- inst/tinytest/test_utils.R | 6 ++++- 6 files changed, 45 insertions(+), 27 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7d82314..9e0f910 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: bspm Type: Package Title: Bridge to System Package Manager -Version: 0.5.5.1 +Version: 0.5.6 Authors@R: c( person("IƱaki", "Ucar", email="iucar@fedoraproject.org", role=c("aut", "cph", "cre"), comment=c(ORCID="0000-0001-6403-5550"))) diff --git a/NEWS.md b/NEWS.md index 8164be6..3aab069 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ -# bspm 0.5.5.1 +# bspm 0.5.6 - Move to cran4linux org on GitHub, update URLs. +- Try binary installation of build-only dependencies for source packages + (#82 addressing #81). # bspm 0.5.5 diff --git a/R/integration.R b/R/integration.R index a9b4626..19564c5 100644 --- a/R/integration.R +++ b/R/integration.R @@ -87,10 +87,11 @@ utils::globalVariables("contrib.url") # argument # install binaries with checks for newer versions from source install_both <- function(pkgs, contriburl, method, dependencies, ...) { db <- utils::available.packages(contriburl=contriburl, method=method, ...) - pkgs <- pkg_deps(pkgs, dependencies, db, ..., all=TRUE) + pkgs <- pkg_deps(pkgs, dependencies, db, all=TRUE) pkgs <- check_versions(pkgs, db) - later <- ask_user(pkgs$later, pkgs$bins, pkgs$binvers, pkgs$srcvers) - pkgs <- c(install_sys(pkgs$bins[!later]), pkgs$bins[later], pkgs$srcs) + mask <- ask_user(pkgs$later, pkgs$bins, pkgs$binvers, pkgs$srcvers) + hard <- hard_deps(pkgs, db, mask) + pkgs <- c(install_sys(c(pkgs$bins[!mask], hard)), pkgs$bins[mask], pkgs$srcs) pkgs } @@ -98,7 +99,7 @@ install_both <- function(pkgs, contriburl, method, dependencies, ...) { install_fast <- function(pkgs, contriburl, method, ...) { if (length(pkgs <- install_sys(pkgs))) { db <- utils::available.packages(contriburl=contriburl, method=method, ...) - install_sys(pkg_deps(pkgs, NA, db=db, ..., all=FALSE)) + install_sys(pkg_deps(pkgs, NA, db=db, all=FALSE)) } pkgs } diff --git a/R/utils.R b/R/utils.R index 7f49e02..8ae7c5a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -53,27 +53,38 @@ shadowed_packages <- function(lib.loc=NULL) { shadow } +list_inst <- function() { + libs <- unique(c(.Library.site, .Library)) + inst <- unique(row.names(utils::installed.packages(libs))) + inst +} + +list_deps <- function(packages, db, which, recursive) { + deps <- tools::package_dependencies(packages, db, which, recursive) + deps <- unique(unlist(deps, use.names=FALSE)) + deps +} + # get package dependencies -pkg_deps <- function(pkgs, dependencies, db, ..., all=TRUE) { +pkg_deps <- function(pkgs, dependencies, db, all=TRUE) { pkgs <- unique(pkgs) - libs <- unique(c(.Library.site, .Library)) - inst <- row.names(utils::installed.packages(libs, ...)) - deps <- tools::package_dependencies(pkgs, db, c("Depends", "Imports"), recursive=TRUE) - deps <- unlist(deps, use.names=FALSE) - if (!all) { - hard <- tools::package_dependencies(pkgs, db, "LinkingTo", recursive=FALSE) - deps <- c(deps, unlist(hard, use.names=FALSE)) - } - if (isTRUE(dependencies) || "Suggests" %in% dependencies) { - soft <- tools::package_dependencies(pkgs, db, "Suggests", recursive=FALSE) - deps <- c(deps, unlist(soft, use.names=FALSE)) - } - if ("Enhances" %in% dependencies) { - enha <- tools::package_dependencies(pkgs, db, "Enhances", recursive=FALSE) - deps <- c(deps, unlist(enha, use.names=FALSE)) - } - pkgs <- unique(c(setdiff(deps, inst), if (all) pkgs)) - pkgs + deps <- list_deps(pkgs, db, c("Depends", "Imports"), recursive=TRUE) + if (!all) + deps <- c(deps, list_deps(pkgs, db, "LinkingTo", recursive=FALSE)) + if (isTRUE(dependencies) || "Suggests" %in% dependencies) + deps <- c(deps, list_deps(pkgs, db, "Suggests", recursive=FALSE)) + if ("Enhances" %in% dependencies) + deps <- c(deps, list_deps(pkgs, db, "Enhances", recursive=FALSE)) + deps <- unique(c(setdiff(deps, list_inst()), if (all) pkgs)) + deps +} + +# get LinkingTo-only dependencies for src packages +hard_deps <- function(pkgs, db, mask) { + srcs <- c(pkgs$bins[mask], pkgs$srcs) + deps <- list_deps(srcs, db, "LinkingTo", recursive=FALSE) + deps <- setdiff(deps, c(list_inst(), pkgs$bins, pkgs$srcs)) + deps } # adapted from install.packages diff --git a/cran-comments.md b/cran-comments.md index dac8d86..651215a 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,5 +1,5 @@ ## Patch release -Fix test involving numeric_version per CRAN request. +Minor fixes. ## Test environments - local up-to-date R installation diff --git a/inst/tinytest/test_utils.R b/inst/tinytest/test_utils.R index 59d2771..1f69c0d 100644 --- a/inst/tinytest/test_utils.R +++ b/inst/tinytest/test_utils.R @@ -8,7 +8,7 @@ expect_equal(colnames(df), c("Package", "LibPath", "Version", "Shadow.LibPath", "Shadow.Version", "Shadow.Newer")) expect_equal(df$Version < df$Shadow.Version, df$Shadow.Newer) -# pkg_deps ---- +# pkg_deps, hard_deps ---- mock("installed.packages", pkg="utils", function(...) matrix(1:2, dimnames=list(c("codetools", "rticles"), NULL))) @@ -24,6 +24,10 @@ deps <- c(deps, "simmer.plot", "parallel", "testthat", "knitr", "rmarkdown") expect_equal(sort(bspm:::pkg_deps(pkgs, TRUE, db, all=TRUE)), sort(deps)) expect_equal(sort(bspm:::pkg_deps(pkgs, "Suggests", db, all=TRUE)), sort(deps)) +deps <- bspm:::pkg_deps(pkgs, NA, db, all=TRUE) +expect_equal(bspm:::hard_deps(list(bins=deps), db, FALSE), NULL) +expect_equal(bspm:::hard_deps(list(bins=deps), db, TRUE), "BH") + unmock_all() # check_versions ----