Skip to content

Commit

Permalink
Fix #63
Browse files Browse the repository at this point in the history
Also bump version because the generated Dockerfile and rang.R have
changed.
  • Loading branch information
chainsawriot committed Feb 21, 2023
1 parent db93baf commit ca99ffd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")),
Expand Down
25 changes: 13 additions & 12 deletions R/installation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)])
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}

Expand Down
10 changes: 5 additions & 5 deletions tests/testthat/test_dockerize.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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", {
Expand Down Expand Up @@ -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)))
})
})

0 comments on commit ca99ffd

Please sign in to comment.