From 7ad9b430217bb9b0009c8309792715fd430fd00e Mon Sep 17 00:00:00 2001 From: vincent guyader Date: Fri, 28 Jun 2024 08:56:30 +0200 Subject: [PATCH] Dev tmp (#71) * Use 'pkg_sysreqs' instead of 'pkg_system_requirements' (#69) * proof of concept code * switch statement * function name * extract install script * inflate * update imports * parse packages * inflate and docs * remove preinstall scripts Update script added later --------- Co-authored-by: Boyd Tarlinton * update NEWS bump version --------- Co-authored-by: Boyd Tarlinton --- DESCRIPTION | 11 +++++++---- NAMESPACE | 4 +++- NEWS.md | 1 + R/compact_sysreqs.R | 2 +- R/dock_from_renv.R | 39 ++++++++++++++++++------------------- dev/flat_dock_from_renv.Rmd | 39 ++++++++++++++++++------------------- man/compact_sysreqs.Rd | 2 +- 7 files changed, 51 insertions(+), 47 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f8d6825..9ba7bd6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: dockerfiler Title: Easy Dockerfile Creation from R -Version: 0.2.2.9001 +Version: 0.2.2.9002 Authors@R: c( person("Colin", "Fay", , "contact@colinfay.me", role = c("cre", "aut"), comment = c(ORCID = "0000-0001-7343-1846")), @@ -27,8 +27,10 @@ Imports: memoise, pak (>= 0.2.0), pkgbuild (>= 1.2.0), + purrr, R6 (>= 2.5.0), remotes (>= 2.2.0), + renv, usethis (>= 2.0.1), utils Suggests: @@ -36,10 +38,11 @@ Suggests: rmarkdown (>= 2.6), testthat (>= 3.0.0), withr -VignetteBuilder: knitr -Config/fusen/version: 0.5.1 +VignetteBuilder: + knitr +Config/fusen/version: 0.5.2 Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true -RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) +RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index 93bec8b..82ce290 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -21,8 +21,10 @@ importFrom(fs,path) importFrom(glue,glue) importFrom(jsonlite,fromJSON) importFrom(memoise,memoise) -importFrom(pak,pkg_system_requirements) +importFrom(pak,pkg_sysreqs) importFrom(pkgbuild,build) +importFrom(purrr,keep_at) +importFrom(purrr,pluck) importFrom(remotes,dev_package_deps) importFrom(remotes,package_deps) importFrom(usethis,use_build_ignore) diff --git a/NEWS.md b/NEWS.md index e58862b..e35afa1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # 0.2.2.xxxx - remove sysreqs.r-hub.io to use {pak} instead for system requirement detection +- move from `pak::pkg_system_requirements` to `pak::pkg_sysreqs()` thanks to @B0ydT # dockerfile 0.2.2 diff --git a/R/compact_sysreqs.R b/R/compact_sysreqs.R index 41f374b..943f2db 100644 --- a/R/compact_sysreqs.R +++ b/R/compact_sysreqs.R @@ -1,6 +1,6 @@ #' Compact Sysreqs #' -#' @param pkg_installs pkg_sysreqs as vector, `pak::pkg_system_requirements` output +#' @param pkg_installs pkg_sysreqs as vector, `pak::pkg_sysreqs` output #' @param update_cmd command used to update packages, "apt-get update -y" by default #' @param install_cmd command used to install packages, "apt-get install -y" by default #' @param clean_cmd command used to clean package folder, "rm -rf /var/lib/apt/lists/*" by default diff --git a/R/dock_from_renv.R b/R/dock_from_renv.R index 82d35e5..dd74421 100644 --- a/R/dock_from_renv.R +++ b/R/dock_from_renv.R @@ -10,8 +10,8 @@ available_distros <- c( ) #' @importFrom memoise memoise -pkg_system_requirements_mem <- memoise::memoise( - pak::pkg_system_requirements +pkg_sysreqs_mem <- memoise::memoise( + pak::pkg_sysreqs ) @@ -47,7 +47,8 @@ pkg_system_requirements_mem <- memoise::memoise( #' #' @importFrom attempt map_try_catch #' @importFrom glue glue -#' @importFrom pak pkg_system_requirements +#' @importFrom pak pkg_sysreqs +#' @importFrom purrr keep_at pluck #' @export #' @examples @@ -100,28 +101,22 @@ dock_from_renv <- function( distro_args <- switch( distro, centos7 = list( - os = "centos", - os_release = "7" + sysreqs_platform = "centos-7" ), centos8 = list( - os = "centos", - os_release = "8" + sysreqs_platform = "centos-8" ), xenial = list( - os = "ubuntu", - os_release = "16.04" + sysreqs_platform = "ubuntu-16.04" ), bionic = list( - os = "ubuntu", - os_release = "18.04" + sysreqs_platform = "ubuntu-18.04" ), focal = list( - os = "ubuntu", - os_release = "20.04" + sysreqs_platform = "ubuntu-20.04" ), jammy = list( - os = "ubuntu", - os_release = "22.04" + sysreqs_platform = "ubuntu-2.04" ) ) @@ -177,7 +172,7 @@ dock_from_renv <- function( pkgs, FUN = function(x) { c( - list(package = x), + list(pkg = x), distro_args ) } @@ -188,18 +183,22 @@ dock_from_renv <- function( pkg_os, function(x) { do.call( - pkg_system_requirements_mem, + pkg_sysreqs_mem, x - ) + ) |> + pluck("packages") |> + keep_at("system_packages") }, .e = ~ character(0) - ) + ) |> + unlist() - pkg_installs <- unique(pkg_sysreqs) + pkg_installs <- unique(pkg_sysreqs) |> + lapply( function(.x) {paste0(install_cmd, " ", .x)}) if (length(unlist(pkg_installs)) == 0) { cat_bullet( diff --git a/dev/flat_dock_from_renv.Rmd b/dev/flat_dock_from_renv.Rmd index 3a44b37..b9673b6 100644 --- a/dev/flat_dock_from_renv.Rmd +++ b/dev/flat_dock_from_renv.Rmd @@ -53,8 +53,8 @@ available_distros <- c( ) #' @importFrom memoise memoise -pkg_system_requirements_mem <- memoise::memoise( - pak::pkg_system_requirements +pkg_sysreqs_mem <- memoise::memoise( + pak::pkg_sysreqs ) @@ -90,7 +90,8 @@ pkg_system_requirements_mem <- memoise::memoise( #' #' @importFrom attempt map_try_catch #' @importFrom glue glue -#' @importFrom pak pkg_system_requirements +#' @importFrom pak pkg_sysreqs +#' @importFrom purrr keep_at pluck #' @export dock_from_renv <- function( @@ -138,28 +139,22 @@ dock_from_renv <- function( distro_args <- switch( distro, centos7 = list( - os = "centos", - os_release = "7" + sysreqs_platform = "centos-7" ), centos8 = list( - os = "centos", - os_release = "8" + sysreqs_platform = "centos-8" ), xenial = list( - os = "ubuntu", - os_release = "16.04" + sysreqs_platform = "ubuntu-16.04" ), bionic = list( - os = "ubuntu", - os_release = "18.04" + sysreqs_platform = "ubuntu-18.04" ), focal = list( - os = "ubuntu", - os_release = "20.04" + sysreqs_platform = "ubuntu-20.04" ), jammy = list( - os = "ubuntu", - os_release = "22.04" + sysreqs_platform = "ubuntu-2.04" ) ) @@ -215,7 +210,7 @@ dock_from_renv <- function( pkgs, FUN = function(x) { c( - list(package = x), + list(pkg = x), distro_args ) } @@ -226,18 +221,22 @@ dock_from_renv <- function( pkg_os, function(x) { do.call( - pkg_system_requirements_mem, + pkg_sysreqs_mem, x - ) + ) |> + pluck("packages") |> + keep_at("system_packages") }, .e = ~ character(0) - ) + ) |> + unlist() - pkg_installs <- unique(pkg_sysreqs) + pkg_installs <- unique(pkg_sysreqs) |> + lapply( function(.x) {paste0(install_cmd, " ", .x)}) if (length(unlist(pkg_installs)) == 0) { cat_bullet( diff --git a/man/compact_sysreqs.Rd b/man/compact_sysreqs.Rd index affe893..97fdbe0 100644 --- a/man/compact_sysreqs.Rd +++ b/man/compact_sysreqs.Rd @@ -12,7 +12,7 @@ compact_sysreqs( ) } \arguments{ -\item{pkg_installs}{pkg_sysreqs as vector, \code{pak::pkg_system_requirements} output} +\item{pkg_installs}{pkg_sysreqs as vector, \code{pak::pkg_sysreqs} output} \item{update_cmd}{command used to update packages, "apt-get update -y" by default}