From bfdbd01bc51a245c764f09c66d620c61e004b518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Cs=C3=A1rdi?= Date: Fri, 5 Apr 2024 10:54:44 +0200 Subject: [PATCH] Ignore soft deps with bad OS_type, for installation --- NEWS.md | 4 + R/resolution-df.R | 6 +- R/resolution.R | 2 +- R/solve.R | 21 +++++ R/utils.R | 6 +- .../testthat/_snaps/pillar-1.9.0/type-bioc.md | 3 + .../testthat/_snaps/pillar-1.9.0/type-git.md | 3 + tests/testthat/_snaps/type-cran.md | 84 +++++++++---------- 8 files changed, 83 insertions(+), 46 deletions(-) diff --git a/NEWS.md b/NEWS.md index 75be7c22..e041072b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,10 @@ the `git-submodules` configuration option is set to `TRUE`. See `?"pkgdepends-config"` (#354). +* pkgdepends now automatically ignores soft dependencies that have an + incompatible OS type (`OS_type` entry in `DESCRIPTION`) when installing + packages. + # pkgdepends 0.7.2 * pkgdepends now supports the `*` wildcard for parameter specifications, diff --git a/R/resolution-df.R b/R/resolution-df.R index 212e8485..33cffabf 100644 --- a/R/resolution-df.R +++ b/R/resolution-df.R @@ -33,7 +33,8 @@ res_make_empty_df <- local({ extra = list(), # any extra data (e.g. GitHub sha) dep_types= list(), params = list(), - sysreqs = character() + sysreqs = character(), + os_type = character() ) } data @@ -70,7 +71,8 @@ res_df_defaults <- local({ extra = list(list()), dep_types= list("default"), params = list(character()), - sysreqs = NA_character_ + sysreqs = NA_character_, + os_type = NA_character_ ) } data diff --git a/R/resolution.R b/R/resolution.R index f18d86ba..18b099fd 100644 --- a/R/resolution.R +++ b/R/resolution.R @@ -667,7 +667,7 @@ resolve_from_metadata <- function(remotes, direct, config, cache, "ref", "type", "status", "package", "version", "license", "needscompilation", "priority", "md5sum", "platform", "rversion", "repodir", "target", "deps", "sources", "mirror", - "filesize", "sha256", "sysreqs") + "filesize", "sha256", "sysreqs", "os_type") cols <- intersect(names(data), cols) diff --git a/R/solve.R b/R/solve.R index 72b74f9f..869cbea4 100644 --- a/R/solve.R +++ b/R/solve.R @@ -211,6 +211,7 @@ pkgplan_i_create_lp_problem <- function(pkgs, config, policy) { lp <- pkgplan_i_lp_init(pkgs, config, policy) lp <- pkgplan_i_lp_objectives(lp) + lp <- pkgplan_i_lp_os_type(config, lp) lp <- pkgplan_i_lp_force_source(lp) lp <- pkgplan_i_lp_failures(lp) lp <- pkgplan_i_lp_ignore(lp) @@ -301,6 +302,20 @@ pkgplan_i_lp_objectives <- function(lp) { lp } +pkgplan_i_lp_os_type <- function(config, lp) { + if (config$get("goal") != "install") return(lp) + if (! "os_type" %in% names(lp$pkgs)) return(lp) + os <- os_type() + bad <- which(!is.na(lp$pkgs$os_type) & lp$pkgs$os_type != os) + for (wh in bad) { + lp <- pkgplan_i_lp_add_cond(lp, wh, op = "==", rhs = 0, + type = "matching-platform") + } + lp$ruled_out <- c(lp$ruled_out, bad) + + lp +} + pkgplan_i_lp_force_source <- function(lp) { # if source package is forced, then rule out binaries src_req <- vlapply(lp$pkgs$params, is_true_param, "source") @@ -614,6 +629,12 @@ pkgplan_i_lp_dependencies <- function(lp, config) { ignored2 <- package_version(ignore_rver) > current ignored <- ignored | ignored2 } + # ignore packages with the wrong OS type + if (config$get("goal") == "install") { + os <- os_type() + bad <- which(!is.na(pkgs$os_type) & pkgs$os_type != os) + if (length(bad) > 0) ignored[bad] <- TRUE + } soft_deps <- tolower(pkg_dep_types_soft()) ## 4. Package dependencies must be satisfied diff --git a/R/utils.R b/R/utils.R index c29c6e51..7b57cd78 100644 --- a/R/utils.R +++ b/R/utils.R @@ -494,4 +494,8 @@ backtick <- function(x) { collapse <- function(x, ...) { cli::ansi_collapse(x, ...) -} \ No newline at end of file +} + +na_omit <- function(x) { + x[!is.na(x)] +} diff --git a/tests/testthat/_snaps/pillar-1.9.0/type-bioc.md b/tests/testthat/_snaps/pillar-1.9.0/type-bioc.md index 245d1323..8a626b8b 100644 --- a/tests/testthat/_snaps/pillar-1.9.0/type-bioc.md +++ b/tests/testthat/_snaps/pillar-1.9.0/type-bioc.md @@ -121,4 +121,7 @@ $sysreqs [1] NA + $os_type + [1] NA + diff --git a/tests/testthat/_snaps/pillar-1.9.0/type-git.md b/tests/testthat/_snaps/pillar-1.9.0/type-git.md index d8db24e0..84137c79 100644 --- a/tests/testthat/_snaps/pillar-1.9.0/type-git.md +++ b/tests/testthat/_snaps/pillar-1.9.0/type-git.md @@ -166,6 +166,9 @@ $sysreqs [1] "" + $os_type + [1] NA + $cache_status [1] "miss" diff --git a/tests/testthat/_snaps/type-cran.md b/tests/testthat/_snaps/type-cran.md index cda95a0b..0b79f65e 100644 --- a/tests/testthat/_snaps/type-cran.md +++ b/tests/testthat/_snaps/type-cran.md @@ -3,7 +3,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 1 x 30 + # A data frame: 1 x 31 ref type direct directpkg status package version license 1 pkg1 standard TRUE TRUE OK pkg1 1.0.0 @@ -16,9 +16,9 @@ mirror sources remote error metadata 1 http://127.0.0.1:/ - extra dep_types params sysreqs cache_status - - 1 miss + extra dep_types params sysreqs os_type cache_status + + 1 miss + sources: http://127.0.0.1://src/contrib/pkg1_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg1/pkg1_1.0.0.tar.gz + remote: @@ -35,7 +35,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 3 x 30 + # A data frame: 3 x 31 ref type direct directpkg status package version license 1 pkg2 standard FALSE FALSE OK pkg2 1.0.0 @@ -56,11 +56,11 @@ 1 http://127.0.0.1:/ 2 http://127.0.0.1:/ 3 http://127.0.0.1:/ - extra dep_types params sysreqs cache_status - - 1 miss - 2 miss - 3 miss + extra dep_types params sysreqs os_type cache_status + + 1 miss + 2 miss + 3 miss + sources: http://127.0.0.1://src/contrib/pkg2_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg2/pkg2_1.0.0.tar.gz http://127.0.0.1://src/contrib/pkg3_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg3/pkg3_1.0.0.tar.gz @@ -87,7 +87,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 3 x 30 + # A data frame: 3 x 31 ref type direct directpkg status package version license 1 pkg1 standard FALSE FALSE OK pkg1 1.0.0 @@ -108,11 +108,11 @@ 1 http://127.0.0.1:/ 2 http://127.0.0.1:/ 3 http://127.0.0.1:/ - extra dep_types params sysreqs cache_status - - 1 miss - 2 miss - 3 miss + extra dep_types params sysreqs os_type cache_status + + 1 miss + 2 miss + 3 miss + sources: http://127.0.0.1://src/contrib/pkg1_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg1/pkg1_1.0.0.tar.gz http://127.0.0.1://src/contrib/pkg2_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg2/pkg2_1.0.0.tar.gz @@ -139,7 +139,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 1 x 30 + # A data frame: 1 x 31 ref type direct directpkg status package 1 cran::xxyyzzqwertyqwerty cran TRUE TRUE FAILED xxyyzzqwertyqwerty @@ -155,9 +155,9 @@ remote error metadata extra dep_types params sysreqs 1 - cache_status - - 1 miss + os_type cache_status + + 1 miss + sources: NA + remote: @@ -174,7 +174,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 2 x 30 + # A data frame: 2 x 31 ref type direct directpkg status package 1 cran::pkg1 cran TRUE TRUE OK pkg1 @@ -195,10 +195,10 @@ 1 2 - sysreqs cache_status - - 1 miss - 2 miss + sysreqs os_type cache_status + + 1 miss + 2 miss + sources: http://127.0.0.1://src/contrib/pkg1_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg1/pkg1_1.0.0.tar.gz NA @@ -220,7 +220,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 1 x 30 + # A data frame: 1 x 31 ref type direct directpkg status package version license 1 cran::pkg1@current cran TRUE TRUE OK pkg1 1.0.0 @@ -233,9 +233,9 @@ mirror sources remote error metadata 1 http://127.0.0.1:/ - extra dep_types params sysreqs cache_status - - 1 miss + extra dep_types params sysreqs os_type cache_status + + 1 miss + sources: http://127.0.0.1://src/contrib/pkg1_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg1/pkg1_1.0.0.tar.gz + remote: @@ -252,7 +252,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 2 x 30 + # A data frame: 2 x 31 ref type direct directpkg status package version license 1 pkg1@0.9.0 standard TRUE TRUE OK pkg1 0.9.0 @@ -269,10 +269,10 @@ 1 2 http://127.0.0.1:/ - extra dep_types params sysreqs cache_status - - 1 "" miss - 2 miss + extra dep_types params sysreqs os_type cache_status + + 1 "" miss + 2 miss + sources: http://127.0.0.1://src/contrib/Archive/pkg1/pkg1_0.9.0.tar.gz http://127.0.0.1://src/contrib/pkg1_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg1/pkg1_1.0.0.tar.gz @@ -294,7 +294,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 1 x 30 + # A data frame: 1 x 31 ref type direct directpkg status package version license 1 pkg1@1.0.0 standard TRUE TRUE OK pkg1 1.0.0 @@ -307,9 +307,9 @@ mirror sources remote error metadata 1 http://127.0.0.1:/ - extra dep_types params sysreqs cache_status - - 1 miss + extra dep_types params sysreqs os_type cache_status + + 1 miss + sources: http://127.0.0.1://src/contrib/pkg1_1.0.0.tar.gz, http://127.0.0.1://src/contrib/Archive/pkg1/pkg1_1.0.0.tar.gz + remote: @@ -326,7 +326,7 @@ Code snapshot(res, extra = "all") Output - # A data frame: 1 x 30 + # A data frame: 1 x 31 ref type direct directpkg status package version license 1 pkg1@>=0.9.0 standard TRUE TRUE FAILED pkg1 @@ -339,9 +339,9 @@ remote error metadata extra dep_types params sysreqs 1 - cache_status - - 1 miss + os_type cache_status + + 1 miss + sources: NA + remote: