Skip to content

Commit

Permalink
refactor extraction functions and fix most tests
Browse files Browse the repository at this point in the history
also expose them as part of regular functions
remove some never-going-to-do tests
expect more warnings
  • Loading branch information
nuest committed Aug 17, 2018
1 parent 406277c commit e45f1e7
Show file tree
Hide file tree
Showing 43 changed files with 8,723 additions and 416 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
^README-.*\.png$
^CONDUCT\.md$
.lintr
docs
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ tests/testthat/Rplots\.pdf
vignettes/sessionInfo\.Rdata

sessionInfo\.Rdata

tests/testthat/v.*\.yaml
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: containerit
Type: Package
Title: Package R in Docker Containers
Version: 0.5.0.9001
Version: 0.5.0.9002
Authors@R: c(person("Daniel", "Nuest", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-2392-6140")),
person("Matthias", "Hinz", role = c("aut"), email = "[email protected]", comment = c(ORCID = "0000-0001-6837-9406")))
Author: Daniel Nuest [aut, cre], Matthias Hinz [aut]
Expand Down Expand Up @@ -50,7 +50,8 @@ Suggests:
proj4,
fortunes,
remotes,
ggplot2
ggplot2,
lattice
RoxygenNote: 6.1.0
Collate:
'Class-Instruction.R'
Expand Down Expand Up @@ -82,7 +83,6 @@ Collate:
'dockerfile.R'
'package-installation-bespoke.R'
'package-installation-methods.R'
'sessionInfo-localbuild-methods.R'
'utility-functions.R'
Remotes: github::r-hub/sysreqs,
github::richfitz/stevedore
15 changes: 14 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(docker_build,Dockerfile)
S3method(docker_build,character)
export("addInstruction<-")
export(Add)
export(Arg)
Expand Down Expand Up @@ -29,10 +31,12 @@ export(clean_session)
export(containerit_write_config)
export(docker_build)
export(dockerfile)
export(empty_session)
export(extract_session_file)
export(extract_session_image)
export(getGitHubRef)
export(getImageForVersion)
export(getRVersionTag)
export(getSessionInfoFromRdata)
export(get_installed_packages)
export(parseFrom)
exportClasses(Add)
Expand Down Expand Up @@ -69,4 +73,13 @@ importFrom(methods,slot)
importFrom(semver,parse_version)
importFrom(stevedore,docker_available)
importFrom(stevedore,docker_client)
importFrom(stringr,regex)
importFrom(stringr,str_detect)
importFrom(stringr,str_extract)
importFrom(stringr,str_length)
importFrom(stringr,str_sub)
importFrom(utils,capture.output)
importFrom(utils,install.packages)
importFrom(utils,installed.packages)
importFrom(utils,read.csv)
importFrom(utils,sessionInfo)
2 changes: 1 addition & 1 deletion R/Class-Comment.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ setClass("Comment",
#' @examples
#' # A simple label that occupies one line:
#' comment <- Comment(text = "this is important to note")
#' the_dockerfile <- dockerfile(clean_session())
#' the_dockerfile <- dockerfile(empty_session())
#' addInstruction(the_dockerfile) <- comment
#' print(the_dockerfile)
#'
Expand Down
9 changes: 5 additions & 4 deletions R/Class-Label.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ setClass("Label",
#' )
#' #label with fixed namespace for all keys
#' label3 <- Label("name"="A name", "description" = "A description", label_ns = "my.label.ns.")
#' the_dockerfile <- dockerfile(clean_session())
#' the_dockerfile <- dockerfile(empty_session())
#' addInstruction(the_dockerfile) <- list(label1, label2, label3)
#' cat(format(the_dockerfile),sep = "\n")
#'
Expand All @@ -64,11 +64,12 @@ Label <-
#' @return A label with key 'R.session-info' and the deparsed session information in one line
#' @export
#' @family label
#' @importFrom utils capture.output
#'
#' @examples
#' session <- clean_session()
#' the_dockerfile <- dockerfile(session)
#' addInstruction(the_dockerfile) <- Label_SessionInfo(session)
#' the_session <- empty_session()
#' the_dockerfile <- dockerfile(the_session)
#' addInstruction(the_dockerfile) <- Label_SessionInfo(the_session)
Label_SessionInfo <-
function(session = sessionInfo(),
as_json = FALSE) {
Expand Down
2 changes: 1 addition & 1 deletion R/LabelSchemaFactory.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' @family label
#'
#' @examples
#' the_dockerfile <- dockerfile(clean_session())
#' the_dockerfile <- dockerfile(empty_session())
#' factory <- LabelSchemaFactory()
#' label <- factory(name = "ImageName",
#' description = "Description of the image",
Expand Down
1 change: 1 addition & 0 deletions R/baseimages.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @return A \code{data.frame} with installed packages and their version of the image
#' @export
#' @importFrom stevedore docker_client docker_available
#' @importFrom utils read.csv
get_installed_packages <- function(image) {
stopifnot(stevedore::docker_available())

Expand Down
36 changes: 22 additions & 14 deletions R/dockerfile.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#' @export
#'
#' @import futile.logger
#' @importFrom utils capture.output
#' @importFrom stringr str_detect regex str_extract str_length str_sub
#'
#' @examples
#' dockerfile <- dockerfile()
Expand Down Expand Up @@ -220,7 +222,7 @@ dockerfile <- function(from = utils::sessionInfo(),
if (isTRUE(save_image)) {
futile.logger::flog.debug("Saving image to file %s with %s and adding COPY instruction using environment %s",
.filename, toString(ls(envir = envir)),
capture.output(envir))
utils::capture.output(envir))
save(list = ls(envir = envir), file = .filename, envir = envir)
addInstruction(.dockerfile) <- Copy(src = .filename, dest = .filename)
} else if (is.list(save_image)) {
Expand Down Expand Up @@ -376,7 +378,7 @@ dockerfileFromSession.session_info <- function(session,
pkgs_gh <- packages_df[stringr::str_detect(string = packages_df$source, stringr::regex("GitHub", ignore_case = TRUE)),]
if (nrow(pkgs_gh) > 0) {
for (pkg in pkgs_gh$name) {
currentPkg <- subset(pkgs_gh, name == pkg)
currentPkg <- subset(pkgs_gh, pkgs_gh$name == pkg)
versionString <- stringr::str_extract(string = currentPkg$source, pattern = "(?<=\\()(.*)(?=\\))")
packages_df[packages_df$name == pkg,c("version")] <- versionString
}
Expand Down Expand Up @@ -423,18 +425,22 @@ dockerfileFromFile <- function(file,
rel_path <- .makeRelative(file, context)

# execute script / markdowns or read Rdata file to obtain sessioninfo
if (stringr::str_detect(file, ".R$")) {
if (stringr::str_detect(string = file,
pattern = stringr::regex(".R$", ignore_case = TRUE))) {
futile.logger::flog.info("Processing R script file '%s' locally.", rel_path)
sessionInfo <- containerit:::obtain_localSessionInfo(file = file,
echo = !silent,
predetect = predetect)
} else if (stringr::str_detect(file, ".Rmd$")) {
sessionInfo <- clean_session(file = file,
echo = !silent,
predetect = predetect)
} else if (stringr::str_detect(string = file,
pattern = stringr::regex(".rmd$", ignore_case = TRUE))) {
futile.logger::flog.info("Processing Rmd file '%s' locally using rmarkdown::render(...)", rel_path)
sessionInfo <- containerit:::obtain_localSessionInfo(rmd_file = file,
echo = !silent,
predetect = predetect)
} else if (stringr::str_detect(file, ".Rdata$")) {
sessionInfo <- getSessionInfoFromRdata(file)
sessionInfo <- clean_session(rmd_file = file,
echo = !silent,
predetect = predetect)
} else if (stringr::str_detect(string = file,
pattern = stringr::regex(".rdata$", ignore_case = TRUE))) {
futile.logger::flog.info("Extracting session object from RData file %s", rel_path)
sessionInfo <- extract_session_file(file)
} else{
futile.logger::flog.info("The supplied file %s has no known extension. containerit will handle it as an R script for packaging.", rel_path)
}
Expand Down Expand Up @@ -519,13 +525,15 @@ dockerfileFromWorkspace <- function(path,
pattern = "\\.R$",
full.names = TRUE,
include.dirs = FALSE,
recursive = TRUE)
recursive = TRUE,
ignore.case = TRUE)

.md_Files <- dir(path = path,
pattern = "\\.Rmd$", #|\\.Rnw$",
full.names = TRUE,
include.dirs = FALSE,
recursive = TRUE)
recursive = TRUE,
ignore.case = TRUE)
futile.logger::flog.debug("Found %s scripts and %s documents", length(.rFiles), length(.md_Files))

if (length(.rFiles) > 0 && length(.md_Files) > 0) {
Expand Down
5 changes: 0 additions & 5 deletions R/package-installation-bespoke.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
lib,
version,
.package_config))
no_apt <<- append(add_apt,
.get_lib_pkgs_names(
lib = lib,
platform = .debian_platform,
config = .package_config))
add_inst <<- append(add_inst,
.get_lib_install_instructions(
lib = lib,
Expand Down
114 changes: 0 additions & 114 deletions R/sessionInfo-localbuild-methods.R

This file was deleted.

Loading

0 comments on commit e45f1e7

Please sign in to comment.