From b8a29ae6a730e500ecacf42d245e0bcebcbe0d36 Mon Sep 17 00:00:00 2001 From: Chris Black Date: Mon, 11 Dec 2023 14:50:37 -0800 Subject: [PATCH] avoid reinstalling (and potentially downgrading) if req already satisfied --- docker/depends/pecan.depends.R | 45 ++++++++++++++++++++------------- scripts/generate_dependencies.R | 13 +++++++--- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/docker/depends/pecan.depends.R b/docker/depends/pecan.depends.R index abc8e9f6864..a933e1a9920 100644 --- a/docker/depends/pecan.depends.R +++ b/docker/depends/pecan.depends.R @@ -143,21 +143,30 @@ options(repos = c( getOption('repos'), sub(r'(\d{4}-\d{2}-\d{2})', 'latest', getOption('repos')) )) -remotes::install_version('abind', '>= 1.4.5', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('coda', '>= 0.18', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('geonames', '> 0.998', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('lubridate', '>= 1.7.0', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('magic', '>= 1.5.0', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('mockery', '>= 0.4.3', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('MODISTools', '>= 1.1.0', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('ncdf4', '>= 1.15', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('plyr', '>= 1.8.4', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('purrr', '>= 0.2.3', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('reshape2', '>= 1.4.2', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('rlang', '>= 0.2.0', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('rmarkdown', '>= 2.19', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('stringr', '>= 1.1.0', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('testthat', '>= 3.0.4', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('TruncatedNormal', '>= 2.2', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('vdiffr', '>= 1.0.2', dependencies = TRUE, upgrade = FALSE) -remotes::install_version('XML', '>= 3.98-1.4', dependencies = TRUE, upgrade = FALSE) +install_if_version <- function(pkg, version) { + vers <- gsub('[^[:digit:].-]+', '', version) + cmp <- get(gsub('[^<>=]+', '', version)) + ok <- requireNamespace(pkg, quietly = TRUE) && + cmp(packageVersion(pkg), vers) + if (!ok) { + remotes::install_version(pkg, version, dependencies = TRUE, upgrade = FALSE) + } +} +install_if_version('abind', '>= 1.4.5') +install_if_version('coda', '>= 0.18') +install_if_version('geonames', '> 0.998') +install_if_version('lubridate', '>= 1.7.0') +install_if_version('magic', '>= 1.5.0') +install_if_version('mockery', '>= 0.4.3') +install_if_version('MODISTools', '>= 1.1.0') +install_if_version('ncdf4', '>= 1.15') +install_if_version('plyr', '>= 1.8.4') +install_if_version('purrr', '>= 0.2.3') +install_if_version('reshape2', '>= 1.4.2') +install_if_version('rlang', '>= 0.2.0') +install_if_version('rmarkdown', '>= 2.19') +install_if_version('stringr', '>= 1.1.0') +install_if_version('testthat', '>= 3.0.4') +install_if_version('TruncatedNormal', '>= 2.2') +install_if_version('vdiffr', '>= 1.0.2') +install_if_version('XML', '>= 3.98-1.4') diff --git a/scripts/generate_dependencies.R b/scripts/generate_dependencies.R index a6b40a1a10d..06fc56846e6 100755 --- a/scripts/generate_dependencies.R +++ b/scripts/generate_dependencies.R @@ -155,9 +155,7 @@ unversioned_deps <- uniq_deps[uniq_deps$version == "*",]$package versioned_dep_install_calls <- uniq_deps[uniq_deps$version != "*",] |> dplyr::mutate( inst_call = paste0( - "remotes::install_version(", - shQuote(package), ", ", shQuote(version), - ", dependencies = TRUE, upgrade = FALSE)")) |> + "install_if_version(", shQuote(package), ", ", shQuote(version), ")")) |> dplyr::pull(inst_call) |> sort() @@ -193,5 +191,14 @@ cat("#!/usr/bin/env Rscript", " getOption('repos'),", " sub(r'(\\d{4}-\\d{2}-\\d{2})', 'latest', getOption('repos'))", "))", + "install_if_version <- function(pkg, version) {", + " vers <- gsub('[^[:digit:].-]+', '', version)", + " cmp <- get(gsub('[^<>=]+', '', version))", + " ok <- requireNamespace(pkg, quietly = TRUE) &&", + " cmp(packageVersion(pkg), vers)", + " if (!ok) {", + " remotes::install_version(pkg, version, dependencies = TRUE, upgrade = FALSE)", + " }", + "}", paste(versioned_dep_install_calls, collapse = "\n"), file = "docker/depends/pecan.depends.R", sep = "\n", append = FALSE)