Skip to content

Commit

Permalink
Try binary installation of build-only deps for source packages (#82)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Enchufa2 authored Apr 9, 2024
1 parent 96a0617 commit 24ac163
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 27 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")))
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 5 additions & 4 deletions R/integration.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ 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
}

# install as many binaries as possible and fallback to source
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
}
49 changes: 30 additions & 19 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## Patch release
Fix test involving numeric_version per CRAN request.
Minor fixes.

## Test environments
- local up-to-date R installation
Expand Down
6 changes: 5 additions & 1 deletion inst/tinytest/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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 ----
Expand Down

0 comments on commit 24ac163

Please sign in to comment.