From ca99ffd3d32f7e5d256ec93c8dc283d885917130 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Tue, 21 Feb 2023 17:59:28 +0100 Subject: [PATCH] Fix #63 Also bump version because the generated Dockerfile and rang.R have changed. --- DESCRIPTION | 2 +- R/installation.R | 25 +++++++++++++------------ tests/testthat/test_dockerize.R | 10 +++++----- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5c0e967..ef76222 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rang Title: Reconstructing Reproducible R Computational Environments with Ease -Version: 0.1.0 +Version: 0.1.1 Authors@R: c(person("Chung-hong", "Chan", , "chainsawtiney@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-6232-7530")), diff --git a/R/installation.R b/R/installation.R index 92da066..5512fc6 100644 --- a/R/installation.R +++ b/R/installation.R @@ -35,7 +35,7 @@ pkgname$set(current_pkgref, current_pkgname) if ("x_uid" %in% colnames(dep_df)) { ## Not supported, but no harm to add it now uid$set(current_pkgref, unique(dep_df$x_uid)) - } + } } } ## installation simulation @@ -97,8 +97,9 @@ } .group_sysreqs <- function(rang) { + must_do_cmd <- "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config" if (length(rang$sysreqs) == 0) { - return("apt-get update -qq") + return(must_do_cmd) } if (isFALSE(.is_ppa_in_sysreqs(rang))) { cmds <- rang$sysreqs @@ -113,7 +114,7 @@ prefix <- paste0(paste0(ppa_lines, collapse = " && "), " && ") cmd <- .group_apt_cmds(cmds, fix_libgit2 = FALSE) } - paste0("apt-get update -qq && ", prefix, cmd) + paste0(must_do_cmd, " && ", prefix, cmd) } .write_rang_as_comment <- function(rang, con, path, verbose, lib, @@ -243,7 +244,7 @@ .insert_materials_dir <- function(dockerfile_content) { rang_line <- which(dockerfile_content == "COPY rang.R ./rang.R") - c(dockerfile_content[1:rang_line], + c(dockerfile_content[1:rang_line], "COPY materials/ ./materials/", dockerfile_content[(rang_line + 1):length(dockerfile_content)]) } @@ -298,7 +299,7 @@ #' is provided. The current approach does not work in R < 2.1.0. #' @export #' @references -#' Ripley, B. (2005) [Packages and their Management in R 2.1.0.](https://cran.r-project.org/doc/Rnews/Rnews_2005-1.pdf) R News, 5(1):8--11. +#' Ripley, B. (2005) [Packages and their Management in R 2.1.0.](https://cran.r-project.org/doc/Rnews/Rnews_2005-1.pdf) R News, 5(1):8--11. #' @examples #' \donttest{ #' if (interactive()) { @@ -335,11 +336,11 @@ export_rang <- function(rang, path, rang_as_comment = TRUE, verbose = TRUE, lib } else { cat(paste0("lib <- \"", as.character(lib), "\"\n"), file = con) } - cat(paste0("cran_mirror <- \"", cran_mirror, "\"\n"), file = con) + cat(paste0("cran_mirror <- \"", cran_mirror, "\"\n"), file = con) if(!is.null(rang$bioc_version)){ - cat(paste0("bioc_mirror <- \"", "https://bioconductor.org/packages/",rang$bioc_version,"/", "\"\n"), file = con) + cat(paste0("bioc_mirror <- \"", "https://bioconductor.org/packages/",rang$bioc_version,"/", "\"\n"), file = con) } - + writeLines(readLines(system.file("footer.R", package = "rang")), con = con) if (isTRUE(rang_as_comment)) { .write_rang_as_comment(rang = rang, con = con, path = path, verbose = verbose, @@ -437,15 +438,15 @@ dockerize <- function(rang, output_dir, materials_dir = NULL, image = c("r-ver", if (isFALSE(dir.exists(materials_subdir_in_output_dir))) { dir.create(materials_subdir_in_output_dir) } - file.copy(list.files(materials_dir, full.names = TRUE), - materials_subdir_in_output_dir, + file.copy(list.files(materials_dir, full.names = TRUE), + materials_subdir_in_output_dir, recursive = TRUE) dockerfile_content <- .insert_materials_dir(dockerfile_content) } writeLines(dockerfile_content, file.path(output_dir, "Dockerfile")) - + .generate_docker_readme(output_dir = output_dir,image = image) - + invisible(output_dir) } diff --git a/tests/testthat/test_dockerize.R b/tests/testthat/test_dockerize.R index f22431f..f2e047e 100644 --- a/tests/testthat/test_dockerize.R +++ b/tests/testthat/test_dockerize.R @@ -105,11 +105,11 @@ test_that("Docker R < 2.1", { test_that(".group_sysreqs and issue #21", { graph <- readRDS("../testdata/graph.RDS") - expect_equal(.group_sysreqs(graph), "apt-get update -qq && apt-get install -y default-jdk libgsl0-dev libicu-dev libpng-dev libxml2-dev make python3 zlib1g-dev liblzma-dev libpcre3-dev libbz2-dev && R CMD javareconf") + expect_equal(.group_sysreqs(graph), "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config && apt-get install -y default-jdk libgsl0-dev libicu-dev libpng-dev libxml2-dev make python3 zlib1g-dev liblzma-dev libpcre3-dev libbz2-dev && R CMD javareconf") graph <- readRDS("../testdata/rang_ok.RDS") - expect_equal(.group_sysreqs(graph), "apt-get update -qq") + expect_equal(.group_sysreqs(graph), "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config") graph <- readRDS("../testdata/issue21.RDS") - expected_output <- "apt-get update -qq && apt-get install -y software-properties-common && add-apt-repository -y ppa:cran/libgit2 && apt-get update && apt-get install -y cmake git libcurl4-openssl-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libgit2-dev libgsl0-dev libharfbuzz-dev libicu-dev libjpeg-dev libpng-dev libssh2-1-dev libssl-dev libtiff-dev libxml2-dev make pandoc pari-gp zlib1g-dev" + expected_output <- "apt-get update -qq && apt-get install -y libpcre3-dev zlib1g-dev pkg-config && apt-get install -y software-properties-common && add-apt-repository -y ppa:cran/libgit2 && apt-get update && apt-get install -y cmake git libcurl4-openssl-dev libfontconfig1-dev libfreetype6-dev libfribidi-dev libgit2-dev libgsl0-dev libharfbuzz-dev libicu-dev libjpeg-dev libpng-dev libssh2-1-dev libssl-dev libtiff-dev libxml2-dev make pandoc pari-gp zlib1g-dev" expect_warning(output <- .group_sysreqs(graph)) expect_equal(output, expected_output) graph <- readRDS("../testdata/issue21_ubuntu2004.RDS") @@ -131,7 +131,7 @@ test_that("material_dir, non-existing, #23", { ## non-existing fake_material_dir <- .generate_temp_dir() expect_false(dir.exists(fake_material_dir)) - expect_error(dockerize(rang_rio, output_dir = temp_dir, materials_dir = fake_material_dir)) + expect_error(dockerize(rang_rio, output_dir = temp_dir, materials_dir = fake_material_dir)) }) test_that("material_dir, existing, no subdir, #23", { @@ -209,4 +209,4 @@ test_that("dockerize with bioc #58", { dockerize(rang = rang_bioc, output_dir = temp_dir) ## verbose = TRUE x <- readLines(file.path(temp_dir, "rang.R")) expect_true(any(grepl("bioc_mirror",x))) -}) \ No newline at end of file +})